【Codeforces Round #443 (Div. 2) C】Short Program
【链接】 我是链接,点我呀:)
【题意】
给你一个n行的只和位运算有关的程序。
让你写一个不超过5行的等价程序。
使得对于每个输入,它们的输出都是一样的。
【题解】
先假设x=1023,y=0;
即每位都是1和每位都是0;
然后做一下这n个操作。
得出,每一位如果是0的话输出应该是几,以及每一位是1的话输出应该是几.
会发现,用or和xor和and就能完成.
【代码】
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,a,b;
int main(){
#ifdef LOCAL_DEFINE
freopen("rush.txt", "rt", stdin);
#endif
scanf("%d",&n);
char s[5];int d1;
a = 1023,b = 0;
for (int i = 1;i <= n;i++){
scanf("%s%d",s,&d1);
if (s[0]=='|') {
a|=d1,b|=d1;
}
if (s[0]=='^') a^=d1,b^=d1;
if (s[0]=='&') a&=d1,b&=d1;
}
int numor = 0,numand = 0,numxor = 0;
for (int i = 0;i < 10;i++){
int x = (1<<i);
if ((a&x) && (b&x)){
numor += x;
}
if (!(a&x) && (b&x)){
numxor+=x;
}
if (!(a&x) && !(b&x)){
numor += x,numxor += x;
}
}
int ans = (numor>0) + (numand>0)+(numxor>0);
printf("%d\n",ans);
if (numor){
printf("| %d\n",numor);
}
if (numand){
printf("& %d\n",numand);
}
if (numxor){
printf("^ %d\n",numxor);
}
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
【Codeforces Round #443 (Div. 2) C】Short Program的更多相关文章
- 【Codeforces Round #443 (Div. 2) A】Borya's Diagnosis
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟 [代码] #include <bits/stdc++.h> using namespace std; const ...
- 【Codeforces Round #443 (Div. 2) B】Table Tennis
[链接] 我是链接,点我呀:) [题意] n个人站在一排. 每次第一个人和第二个人打架. 输的人跑到队列的尾巴去. 然后赢的人继续在队首.和第三个人打. 谁会先赢K次. [题解] 会发现,一轮之后就一 ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- 【Codeforces Round #423 (Div. 2) B】Black Square
[Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...
- 【Codeforces Round #423 (Div. 2) A】Restaurant Tables
[Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
随机推荐
- leetCode 27.Remove Element (删除元素) 解题思路和方法
Remove Element Given an array and a value, remove all instances of that value in place and return th ...
- OpenCASCADE 3 Planes Intersection
OpenCASCADE 3 Planes Intersection eryar@163.com Abstract. OpenCASCADE provides the algorithm to sear ...
- Image与byte[]数组的相互转换
近期项目有个需求是关于图片操作的,须要将图片保存到数据库中.经过尝试才知道Image类型文件是不能直接存储到数据库中的.保存之前须要我们做一步转换:将Image转换成字节数组类型Byte ...
- js02---字符串
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.
https://stackoverflow.com/questions/30045871/sorting-the-view-based-on-frequency-in-sql-server Just ...
- 关于自定义一个上传的file按钮
在input中html给我们一个 type file用来做文件上传的功能,比如 但是这样的样式,实在难看,在开发的时候看了layui和bootstrap的点击上传,都很不错. 前者的调用方式和js的 ...
- Ansible学习记录六:Tower安装
0.特别说明 1. 本文档没有特殊说明,均已root用户安装 2. 本文档中ftp传输文件的工具采用filezilla. 3. 本文档中的执行命令必须严格按照顺序而来. 4. 本文档中所用浏览器为Go ...
- 【Django】MEDIA的配置及用法
如果需要在数据库中存储图片或视频类的数据,我们可以配置MEDIA. 下面的示例将以上传一张图片的形式来说明MEDIA的配置及用法. 第一步 settings.py # media配置 MEDIA_UR ...
- 03003_MySQL
1.之前已经进行过MySQL的安装,参考03002_MySql数据库的安装和配置 : 2.登录MySQL数据库 (1)启动mysql服务:net start mysql : (2)MySQL是一个 ...
- Prism 框架基础架构
概要 Prism提供指导,帮助您更轻松地设计和构建,灵活且易于维护的客户端业务应用程序,这些应用程序可在Windows运行时,Windows Presentation Foundation(WPF)桌 ...