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 ...
随机推荐
- 【java设计模式】【创建模式Creational Pattern】简单工厂模式Simple Factory Pattern(静态工厂方法模式Static Factory Method Pattern)
public class Test { public static void main(String[] args){ try{ Factory.factory("A").doSt ...
- HTTP之URL分解
HTTP使用统一资源标识符(Uniform Resource Identifiers, URI)来传输数据和建立连接.URL是一种特殊类型的URI,包含了用于查找某个资源的足够的信息 URL,全称是U ...
- ASP.NET Cookie 概述
什么是 Cookie? Cookie 是一小段文本信息,伴随着用户请求和页面在 Web 服务器和浏览器之间传递.Cookie 包含每次用户访问站点时 Web 应用程序都可以读取的信息. 例如,如果在用 ...
- lua中易混淆函数
lua中易混淆的函数 ipairs和pairs: ipairs只能顺序遍历table,遇到key不是数字就会退出 pairs可以遍历table中所有元素 ----------------------- ...
- 第五节 suid/ sgid /sbit /which /locate / find /stat / ln / uname -a
复习上节课内容(重点记录)1.chown -R 递归修改目录下包含子目录和子目录下的文件的属组2.chmod -R 递归修改目录下包含子目录和子目录下的文件的权限 ================== ...
- > library('ggplot2') Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 不存在叫‘colorspace’这个名字的程辑包
> library('ggplot2')Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : ...
- Webpack 2 视频教程 009 - 配置 ESLint 实现代码规范自动测试 (上)
原文发表于我的技术博客 这是我免费发布的高质量超清「Webpack 2 视频教程」. Webpack 作为目前前端开发必备的框架,Webpack 发布了 2.0 版本,此视频就是基于 2.0 的版本讲 ...
- 摄像头脸部识别 (1)opencv 抓取视频数据并保存
摄像头脸部识别 (1)opencv 抓取视频数据并保存 基于python 和 opencv 3.4.0 (兼容 opencv 2.X 参考注释),详细如代码 import numpy as np im ...
- day 10 字符编码和文件处理 细节整理
pycharm是文本编辑器. 大概理解为: 输出到屏幕上的时候,是解码过的字符串,用 decode 处理的时候要编码成相应的流, encode 成你要用的格式就可以了 1 .字符编码: 字符==== ...
- 纯css提示效果 提示层
<!DOCTYPE HTML PUBLIC "-//W3C//DTD xHTML 1.0 Transitional//EN"><HTML> <HEAD ...