【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个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
随机推荐
- 怎样更好的设计android图标,拉伸不变形等等系列长处,并且减小apk大小
android mvp框架:dileber(https://github.com/dileber/dileber.git) 继续为大家介绍android mvp开源框架 dileber 今天主要是字 ...
- myeclipse中断点调试
在代码最左端,也就是行号位置处双击.会出现一个实心小圆点.即增加的断点.debug启动程序,就会运行到断点处: 按F5是进去方法里面. 按F6是一步一步走, 按F7是跳出方法里面(按F5后再按F7就跳 ...
- 空间矢量数据(.shp文件)之JAVA操作
Shape文件由ESRI开发.一个ESRI(Environmental Systems Research Institute)的shape文件包含一个主文件,一个索引文件,和一个dBASE表. 当中主 ...
- OpenCASCADE 参数曲面面积
OpenCASCADE 参数曲面面积 eryar@163.com Abstract. 本文介绍了参数曲面的第一基本公式,并应用曲面的第一基本公式,结合OpenCASCADE中计算多重积分的类,对任意参 ...
- jquery20--animate() : 运动的方法
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- 配置Lotus Domino集群视频详解
IBM Lotus Domino Server 有个最重要的高可用特新就是集群,它对于任何使用 Domino 服务器的组织,让用户能够持续访问它们的数据库,保证业务不间断运行.下面通过两个视频来学习如 ...
- 2017国家集训队作业[arc076d/f][Exhausted?]
2017国家集训队作业[arc076d/f][Exhausted?] 题意: 有\(N\)个人,\(M\)把椅子,给出\(...L_i.R_i\)表示第\(i\)个人可以选择编号为\(1\sim ...
- PHP GD 生成图片验证码+session获取储存验证码
以下分享一个PHP制作的图片验证码案例:案比例如以下图: 运用PHP GD具体请看:http://www.php.net/manual/zh/book.image.php 后台图片代码例如以下: &l ...
- linux host主机名配置
1.查看主机名 #hostname 2.查看ip #ifconfig 2.添加主机名配置 #vi /etc/hosts 新增一行 172.23.26.195 vhost145.idmp.safe
- JS 图片大小自动调整 (img)
<script> function dlutChangeImg(){ var maxwidth = 598; var obj = document.getElementById('bbs_ ...