A. Numbers Joke
The input contains a single integer a (1 ≤ a ≤ 30).
Output a single integer.
3
27
题目链接:http://codeforces.com/contest/784/problem/A
分析:百度史蒂芬数,直接打表求解!
下面给出AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
else if(n==)
cout<<<<endl;
}
return ;
}
B. Kids' Riddle
Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it?
The input contains a single integer n (0 ≤ n ≤ 2000000000).
Output a single integer.
11
2
14
0
61441
2
571576
10
2128506
3
题目链接:http://codeforces.com/contest/784/problem/B
#include<bits/stdc++.h>
using namespace std;
#define ll long long
string s;
int a,b,c,d;
int main()
{
int ans;
cin>>ans;
if(ans==)
{
a++;
}
while(ans)
{
if(ans%==)
{
a++;
}
else if(ans%==)
{
a+=;
}
else if(ans%==)
{
a++;
}
else if(ans%==)
{
a++;
}
else if(ans%==)
{
a+=;
}
else if(ans%==)
{
a++;
}
else if(ans%==)
{
a++;
}
else if(ans%==)
{
a++;
}
ans/=;
}
cout<<a<<endl;
return ;
}
C. INTERCALC
DO YOU EXPECT ME TO FIND THIS OUT?
WHAT BASE AND/XOR LANGUAGE INCLUDES string?
DON'T BYTE OF MORE THAN YOU CAN CHEW
YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR
SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD
THE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT!
I HAVE NO ARRAY AND I MUST SCREAM
ELEMENTS MAY NOT BE STORED IN WEST HYPERSPACE
The first line of input data contains a single integer n (1 ≤ n ≤ 10).
The second line of input data contains n space-separated integers ai (1 ≤ ai ≤ 11).
Output a single integer.
4
2 5 3 1
4
题目链接:http://codeforces.com/contest/784/problem/C
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,x,mx=;
int main()
{
cin>>n;
for(int i=;i<=n;i++)
cin>>x,mx=max(mx,x);
cout<<(x^mx);
return ;
}
D. Touchy-Feely Palindromes
The only line of the input contains a string of digits. The length of the string is between 1 and 10, inclusive.
Output "Yes" or "No".
373
Yes
121
No
436
Yes
题目链接:http://codeforces.com/contest/784/problem/D
分析:看是不是回文(436中4,6盲文对称,所以s[4]=6)
下面给出AC代码:
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std; int s[]={,-,-,-,,,,-,,};
char st[]; int main()
{
scanf("%s",st+);int n=strlen(st+);
for(int i=,j=n;i<j;i++,j--)
if(st[i]!=st[j]&&s[st[i]-'']!=st[j]-'') return *puts("No");
if(n&){if(st[n/+]!=''&&st[n/+]!='')return *puts("No");}
puts("YES");
return ;
}
E. Twisted Circuit
The input consists of four lines, each line containing a single digit 0 or 1.
Output a single digit, 0 or 1.
0
1
1
0
0
题目链接:http://codeforces.com/contest/784/problem/E
分析:一个数字电路,不过或门和异或门是反的,所以。。注意下
下面给出AC代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
string s;
int a,b,c,d;
int main()
{
cin>>a>>b>>c>>d;
printf("%d\n",((a^b)&(c|d))^((b&c)|(a^d)));
return ;
}
F. Crunching Numbers Just for You
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order.
The input consists of a single line of space-separated integers. The first number is n (1 ≤ n ≤ 10) — the size of the array. The following n numbers are the elements of the array (1 ≤ ai ≤ 100).
Output space-separated elements of the sorted array.
3
3 1 2
1 2 3
Remember, this is a very important feature, and you have to make sure the customers appreciate it!
题目链接:http://codeforces.com/contest/784/problem/F
分析:
排序。不过必须运行时间超过1s,不会怎么控制时间?有个好办法,随便找个代码,反正要运行1s以上的,加进去,然后输出结果就好了,这里我用了网络赛的代码
下面给出AC代码:
#include<bits/stdc++.h>
using namespace std; #define MAXN 100
#define MAXM 10001
#define MAXP 266666
#define MAX 3200001
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)
#define dbg(x) cout << #x << " = " << x << endl
#define chkbit(ar, i) (((ar[(i) >> 6]) & (1 << (((i) >> 1) & 31))))
#define setbit(ar, i) (((ar[(i) >> 6]) |= (1 << (((i) >> 1) & 31))))
#define isprime(x) (( (x) && ((x)&1) && (!chkbit(ar, (x)))) || ((x) == 2)) namespace pcf
{
long long dp[MAXN][MAXM];
unsigned int ar[(MAX >> ) + ] = {};
int len = , primes[MAXP], counter[MAX]; void Sieve()
{
setbit(ar, ), setbit(ar, );
for (int i = ; (i * i) < MAX; i++, i++)
{
if (!chkbit(ar, i))
{
int k = i << ;
for (int j = (i * i); j < MAX; j += k) setbit(ar, j);
}
} for (int i = ; i < MAX; i++)
{
counter[i] = counter[i - ];
if (isprime(i)) primes[len++] = i, counter[i]++;
}
} void init()
{
Sieve();
for (int n = ; n < MAXN; n++)
{
for (int m = ; m < MAXM; m++)
{
if (!n) dp[n][m] = m;
else dp[n][m] = dp[n - ][m] - dp[n - ][m / primes[n - ]];
}
}
} long long phi(long long m, int n)
{
if (n == ) return m;
if (primes[n - ] >= m) return ;
if (m < MAXM && n < MAXN) return dp[n][m];
return phi(m, n - ) - phi(m / primes[n - ], n - );
} long long Lehmer(long long m)
{
if (m < MAX) return counter[m]; long long w, res = ;
int i, a, s, c, x, y;
s = sqrt(0.9 + m), y = c = cbrt(0.9 + m);
a = counter[y], res = phi(m, a) + a - ;
for (i = a; primes[i] <= s; i++) res = res - Lehmer(m / primes[i]) + Lehmer(primes[i]) - ;
return res;
}
} long long solve(long long n)
{
int i, j, k, l;
long long x, y, res = ; /*for (i = 0; i < pcf::len; i++){
printf("%I64d\n",pcf::Lehmer(n));
x = pcf::primes[i], y = n / x;
if ((x * x) > n) break;
res += (pcf::Lehmer(y) - pcf::Lehmer(x));
} for (i = 0; i < pcf::len; i++){
x = pcf::primes[i];
if ((x * x * x) > n) break;
res++;
}*/
res=pcf::Lehmer(n);
return res;
}
int xx[];
int main()
{
pcf::init();
long long n, res;
while(cin>>n)
{
int x=solve();
for(int i=; i<=n; i++)
{
cin>>xx[i];
}
sort(xx+,xx+n+);
for(int i=; i<=n; i++)
{
cout<<xx[i]<<" ";
}
}
return ;
}
G. BF Calculator
In this problem you will write a simple generator of Brainfuck (https://en.wikipedia.org/wiki/Brainfuck) calculators.
You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brainfuck program which, when executed, will print the result of evaluating this expression.
We use a fairly standard Brainfuck interpreter for checking the programs:
- 30000 memory cells.
- memory cells store integers from 0 to 255 with unsigned 8-bit wraparound.
- console input (, command) is not supported, but it's not needed for this problem.
The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive. The calculations result is guaranteed to be an integer between 0 and 255, inclusive (results of intermediary calculations might be outside of these boundaries).
Output a Brainfuck program which, when executed, will print the result of evaluating this expression. The program must be at most 5000000 characters long (including the non-command characters), and its execution must be complete in at most 50000000 steps.
2+3
++>
+++>
<[<+>-]<
++++++++++++++++++++++++++++++++++++++++++++++++.
9-7
+++++++++>
+++++++>
<[<->-]<
++++++++++++++++++++++++++++++++++++++++++++++++.
You can download the source code of the Brainfuck interpreter by the link http://assets.codeforces.com/rounds/784/bf.cpp. We use this code to interpret outputs.
题目链接:http://codeforces.com/contest/784/problem/G
给定一个表达式求值,输出一份BrainFuck语言写的可以算出答案的代码。
先算出答案,然后按照BrainFuck语言的一套理论,+表示计数器+1,-表示计数器-1,.(点)表示输出计数器的asc码对应的字符。所以+48之后随便输出呗!
下面给出AC代码:
#include <bits/stdc++.h>
using namespace std; char st[];
int op[],num[],cnt=; int calc(int l,int r)
{
int x=;
for(int i=l;i<=r;i++)
x=x*+st[i]-'';
return x;
} void work(int&th,int x)
{
int to=x+;
while(th>to)th--,printf("-");
while(th<to)th++,printf("+");
printf(".\n");
} int main()
{
scanf("%s",st+);int pre=;
for(int i=;st[i];i++)
{
if(st[i]=='+'||st[i]=='-')
{
op[++cnt]=(st[i]=='+')?:;
num[cnt]=calc(pre+,i-);
pre=i;
}
}
num[++cnt]=calc(pre+,strlen(st+));
int x=num[];
for(int i=;i<cnt;i++)
{
if(op[i]==)x=x+num[i+];
else x=x-num[i+];
}
int th=;cnt=;
if(!x) {work(th,);return ;}
while(x)
{
num[++cnt]=x%;x/=;
}
for(int i=cnt;i;i--)
work(th,num[i]);
return ;
}