【Codeforces Round #443 (Div. 2) C】Short Program
Codeforces div round program 443 short
2023-09-14 09:03:45 时间
【链接】 我是链接,点我呀:)
【题意】
【题解】
先假设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;
}
相关文章
- 【Educational Codeforces Round 101 (Rated for Div. 2) C】Building a Fence
- 【Codeforces Round #693 (Div. 3) G】Moving to the Capital
- 【Codeforces Round #451 (Div. 2) B】Proper Nutrition
- 【Codeforces Round #450 (Div. 2) B】Position in Fraction
- 【Codeforces Round #439 (Div. 2) A】The Artful Expedient
- 【Codeforces Round #435 (Div. 2) C】Mahmoud and Ehab and the xor
- 【Codeforces Round #433 (Div. 2) A】Fraction
- 【Codeforces Round #432 (Div. 1) A】 Five Dimensional Points
- 【Codeforces Round #429 (Div. 2) B】 Godsend
- 【Codeforces Round #429 (Div. 2) A】Generous Kefa
- 【Codeforces Round #424 (Div. 2) B】Keyboard Layouts
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
- 【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(hash写法)
- Codeforces Round #254 (Div. 2)D(预计)
- Codeforces Round #296 (Div. 1) E. Triangles 3000
- Codeforces Round #265 (Div. 2) C. No to Palindromes! 构建无回文串子
- Codeforces Round #311 (Div. 2) E - Ann and Half-Palindrome(字典树+dp)
- Educational Codeforces Round 40 (Rated for Div. 2)
- Codeforces Round #442 (Div. 2)
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2)
- Codeforces Round #439 (Div. 2)
- Codeforces Round #436 (Div. 2)
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)
- Codeforces Round #408 (Div. 2)