April Fools Contest 2017 题解&源码(A,数学 B,数学 C,数学 D,字符串 E,数字逻辑 F,排序,卡时间,G,数学)
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 ;
}
April Fools Contest 2017 题解&源码(A,数学 B,数学 C,数学 D,字符串 E,数字逻辑 F,排序,卡时间,G,数学)的更多相关文章
- April Fools Contest 2017 题解
趁着上课无聊,来补一补-- A. Numbers Joke 直接oeis就好了:http://oeis.org/search?q=numbers+joke&language=english&a ...
- Codeforces April Fools Contest 2017
都是神题,我一题都不会,全程听学长题解打代码,我代码巨丑就不贴了 题解见巨神博客 假装自己没有做过这套
- April Fools Contest 2017 F
Description You are developing a new feature for the website which sells airline tickets: being able ...
- April Fools Contest 2017 E
Description Input The input consists of four lines, each line containing a single digit 0 or 1. Outp ...
- April Fools Contest 2017 D
Description Input The only line of the input contains a string of digits. The length of the string i ...
- April Fools Contest 2017 C
Description DO YOU EXPECT ME TO FIND THIS OUT? WHAT BASE AND/XOR LANGUAGE INCLUDES string? DON'T BYT ...
- April Fools Contest 2017 B
Description Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it? Input The i ...
- April Fools Contest 2017 A
Description Input The input contains a single integer a (1 ≤ a ≤ 30). Output Output a single integer ...
- ECJTUACM16 Winter vacation training #4 题解&源码
A......................................................................................... 题目链接→Code ...
随机推荐
- (转)iOS-Runtime知识点整理
runtime简介 因为Objc是一门动态语言,所以它总是想办法把一些决定工作从编译连接推迟到运行时.也就是说只有编译器是不够的,还需要一个运行时系统 (runtime system) 来执行编译后的 ...
- Python模块之pickle(列表,字典等复杂数据类型与二进制文件的转化)
1.pickle模块简介 The pickle module implements binary protocols for serializing and de-serializing a Pyth ...
- 浅析c++和c语言的enum类型
1.先看c语言枚举类型 1.c语言定义枚举类型,每一个枚举元素都是一个整数2.注重数据类型,没有数据类型限定3.相邻枚举元素相差整数4.可以通过整数访问,不够安全 2.上代码: 1 #include& ...
- splay小结—植树结
我要把高级数据结构当爸爸了... ...弱到跪烂了. splay,二叉搜索树的一种,具有稳定变形功能. 二叉搜索树:对于一个节点,都只有不超过2个孩子.其左子树内的点的权值都比这个点小,右子树的点的权 ...
- bzoj 4289: PA2012 Tax
Description 给出一个N个点M条边的无向图,经过一个点的代价是进入和离开这个点的两条边的边权的较大值,求从起点1到点N的最小代价.起点的代价是离开起点的边的边权,终点的代价是进入终点的边的边 ...
- CJOJ 免费航班
Description 小Z在MOI比赛中获得了大奖,奖品是一张特殊的机 票.使用这张机票,可以在任意一个国家内的任意城市之间的免费飞行,只有跨国飞行时才会有额外的费用.小Z获得了一张地图,地图上有城 ...
- 关于a标签颜色的探索
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Rstudio( bioconductor)下载太慢,用国内镜像
在Rstudio中,下载软件install.packages()和 bioconductor软件下载命令 source("http://bioconductor.org/biocLite.R ...
- git环境搭建以及第一个PHP程序
使用mac下的sublime等编辑器帮助代码编写,然后到linux下运行网页代码.可以通过/vagrant共享目录完成,但是默认apache默认目录为/var/www/html,不想改变该目录,同时为 ...
- Hibernate学习笔记(6)---Criteria接口
Criteria接口 Criteria查询通过面相对向的设计,将数据查询条件封装为一个对象.在hibernate执行时会把criteria指定的查询恢复相应的sql语句. 条件查询 Criteria ...