【链接】 我是链接,点我呀:)

【题意】

给你一个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的更多相关文章

  1. 【Codeforces Round #443 (Div. 2) A】Borya's Diagnosis

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟 [代码] #include <bits/stdc++.h> using namespace std; const ...

  2. 【Codeforces Round #443 (Div. 2) B】Table Tennis

    [链接] 我是链接,点我呀:) [题意] n个人站在一排. 每次第一个人和第二个人打架. 输的人跑到队列的尾巴去. 然后赢的人继续在队首.和第三个人打. 谁会先赢K次. [题解] 会发现,一轮之后就一 ...

  3. 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers

    [链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...

  4. 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes

    [题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...

  5. 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees

    [题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...

  6. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

  7. 【Codeforces Round #423 (Div. 2) C】String Reconstruction

    [Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...

  8. 【Codeforces Round #423 (Div. 2) B】Black Square

    [Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...

  9. 【Codeforces Round #423 (Div. 2) A】Restaurant Tables

    [Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...

随机推荐

  1. 【java】itoo项目实战之大数据查询之使用 new map 优化hibernate之级联查询

    在我的上一篇博客<[java]itoo项目实战之hibernate 懒载入优化性能>中,我曾提到过学生数据有2万条,查询数据十分的慢,这是让人非常受不了的事情.看着页面进度条一直转着圈圈, ...

  2. Tools-->SQL Server Profiler监视数据库

    http://www.cnblogs.com/lorking/p/4062787.html https://docs.microsoft.com/en-us/sql/tools/sql-server- ...

  3. 56.lambda表达式与绑定以及伪函数和绑定

    #include <iostream> #include <functional> using namespace std; using namespace std::plac ...

  4. Impala数据处理(加载和存储)

    不多说,直接上干货! Hive与Impala都是构建在Hadoop之上的数据查询工具,那么在实际的应用中,它们是如何加载和存储数据的呢? Hive和Impala存储和加载表,和所有的关系型数据库一样, ...

  5. Atcoder ABC 070 B、C、D

    B - Two Switches Time limit : 2sec / Memory limit : 256MB Score : 200 points Problem Statement Alice ...

  6. Gym 100952 B. New Job

    B. New Job time limit per test 1 second memory limit per test 64 megabytes input standard input outp ...

  7. LuoguP1251 餐巾计划问题(费用流)

    题目描述 一个餐厅在相继的 NN 天里,每天需用的餐巾数不尽相同.假设第 ii 天需要 r_iri​块餐巾( i=1,2,...,N).餐厅可以购买新的餐巾,每块餐巾的费用为 pp 分;或者把旧餐巾送 ...

  8. [AngularFire] Resolve snapshotChanges doesn't emit value when data is empty

    Updated to AngularFire2 v5.0. One important change is that you need to call .snapshotChanges() or .v ...

  9. PHP glob() 函数详解

    PHP glob() 函数详解 一.总结 glob()作用:glob() 函数返回匹配指定模式的文件名或目录. glob()返回值:该函数返回一个包含有匹配文件 / 目录的数组.如果出错返回 fals ...

  10. 洛谷 P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib

    P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib 题目描述 农民约翰的母牛总是产生最好的肋骨.你能通过农民约翰和美国农业部标记在每根肋骨上的数字认出它们.农民约翰确定他卖给 ...