CodeForces
来源:互联网 发布:适合程序员看的电影 编辑:程序博客网 时间:2024/06/04 01:31
总共10位,考虑每个运算对每一位的影响
或0:无影响, 或1:一定为 1, 且0:一定为0,且1:无影响。异或0:无影响,异或1:反转
#include <bits//stdc++.h>using namespace std;char c;int n, a, ans[15], temp[15], a1[15], a2[15], a3[15], x, y, z;int main() { memset(ans, -1, sizeof(ans)); scanf("%d", &n); for (int k = 1; k <= n; k++) { getchar(); scanf("%c", &c); scanf("%d", &a); int cnt = 10; memset(temp, 0, sizeof(temp)); while (a) { temp[cnt--] = a&1; a >>= 1; }// for (int i = 1; i <= 10; i++) cout << temp[i];// cout << endl; for (int i = 1; i <= 10; i++) { if (c == '|') { if (temp[i] == 0) { continue; } else { ans[i] = 1; } } else if (c == '&') { if (temp[i] == 0) { ans[i] = 0; } else { continue; } } else { if (temp[i] == 0) { continue; } else { if (ans[i] == -1) ans[i] = 2; else if (ans[i] == 2) ans[i] = -1; else if (ans[i] == 0) ans[i] = 1; else if (ans[i] == 1) ans[i] = 0; } } }// for (int i = 1; i <= 10; i++) cout << ans[i];// cout << endl; } for (int i = 1; i <= 10; i++) { if (ans[i] == 0) { a1[i] = 0; a2[i] = 0; a3[i] = 0; } else if (ans[i] == 1) { a1[i] = 1; a2[i] = 1; a3[i] = 0; } else if (ans[i] == -1) { a1[i] = 0; a2[i] = 1; a3[i] = 0; } else if (ans[i] == 2) { a1[i] = 0; a2[i] = 1; a3[i] = 1; } } for (int i = 1; i <= 10; i++) { x = x * 2 + a1[i]; y = y * 2 + a2[i]; z = z * 2 + a3[i]; } printf("3\n| %d\n& %d\n^ %d\n", x, y, z);}
阅读全文
1 0
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- js自执行函数
- python conda
- 稀疏表示step by step
- 【蓝桥杯】【手机尾号评分】
- 后台数据结合百度echarts生成各类图表
- CodeForces
- 微信端中的企业号、订阅号、服务号之前的区别
- Ubuntu14.04配置CUDA8.0
- 什么样的macbook清理软件才更加适合你
- 机器学习的学习之路
- 日活占比开发文档编写
- 中国数据科学家年薪有多少?
- python爬虫实战(2)——爬取腾讯新闻
- HDU4429