“楼下一个男人病得要死,那间隔壁的一家唱着留声机,对面是弄孩子。楼上有两人狂笑;还有打牌声。河中的船上有女人哭着她死去的母亲。人类的悲欢并不相通,我只以为他们吵闹。”ios
A - XORwice
把a和b当作二进制数处理,不难发现只要a,b某位都是1咱们就有办法把它消掉,不然答案该位必定是a+b(0,1)该位的值url
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #pragma GCC optimize(2) #include<set> #include<map> #include<cmath> #include<queue> #include<string> #include<vector> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<unordered_map> using namespace std; typedef long long ll; typedef pair<int,int> pii; int main() { IO; int T=1; cin>>T; while(T--) { int a,b; cin>>a>>b; int res=0; for(int i=30;i>=0;i--) if(!(a>>i&1)&&(b>>i&1)||(a>>i&1)&&!(b>>i&1)) res+=1<<i; cout<<res<<'\n'; } return 0; }
B - Putting Bricks in the Wall
咱们只要让g[1][2]
和g[2][1]
的值相等而且不等于g[n][n-1]
和g[n-1][n]
的值便可,最多操做3步。spa
懒得想了,直接枚举( 2 4 = 16 2^4=16 24=16),应该有更好写的写法。.net
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #pragma GCC optimize(2) #include<set> #include<map> #include<cmath> #include<queue> #include<string> #include<vector> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<unordered_map> using namespace std; typedef long long ll; typedef pair<int,int> pii; const int N=210; char g[N][N]; int main() { IO; int T=1; cin>>T; while(T--) { int n; cin>>n; for(int i=1;i<=n;i++) cin>>g[i]+1; if(g[1][2]=='0'&&g[2][1]=='0'&&g[n][n-1]=='0'&&g[n-1][n]=='0') cout<<2<<'\n'<<1<<' '<<2<<'\n'<<2<<' '<<1<<'\n'; else if(g[1][2]=='1'&&g[2][1]=='0'&&g[n][n-1]=='0'&&g[n-1][n]=='0') cout<<1<<'\n'<<2<<' '<<1<<'\n'; else if(g[1][2]=='0'&&g[2][1]=='1'&&g[n][n-1]=='0'&&g[n-1][n]=='0') cout<<1<<'\n'<<1<<' '<<2<<'\n'; else if(g[1][2]=='1'&&g[2][1]=='1'&&g[n][n-1]=='0'&&g[n-1][n]=='0') cout<<0<<'\n'; else if(g[1][2]=='0'&&g[2][1]=='0'&&g[n][n-1]=='1'&&g[n-1][n]=='0') cout<<1<<'\n'<<n-1<<' '<<n<<'\n'; else if(g[1][2]=='1'&&g[2][1]=='0'&&g[n][n-1]=='1'&&g[n-1][n]=='0') cout<<2<<'\n'<<2<<' '<<1<<'\n'<<n<<' '<<n-1<<'\n'; else if(g[1][2]=='0'&&g[2][1]=='1'&&g[n][n-1]=='1'&&g[n-1][n]=='0') cout<<2<<'\n'<<2<<' '<<1<<'\n'<<n<<' '<<n-1<<'\n'; else if(g[1][2]=='1'&&g[2][1]=='1'&&g[n][n-1]=='1'&&g[n-1][n]=='0') cout<<1<<'\n'<<n<<' '<<n-1<<'\n'; else if(g[1][2]=='0'&&g[2][1]=='0'&&g[n][n-1]=='0'&&g[n-1][n]=='1') cout<<1<<'\n'<<n<<' '<<n-1<<'\n'; else if(g[1][2]=='1'&&g[2][1]=='0'&&g[n][n-1]=='0'&&g[n-1][n]=='1') cout<<2<<'\n'<<1<<' '<<2<<'\n'<<n<<' '<<n-1<<'\n'; else if(g[1][2]=='0'&&g[2][1]=='1'&&g[n][n-1]=='0'&&g[n-1][n]=='1') cout<<2<<'\n'<<1<<' '<<2<<'\n'<<n-1<<' '<<n<<'\n'; else if(g[1][2]=='1'&&g[2][1]=='1'&&g[n][n-1]=='0'&&g[n-1][n]=='1') cout<<1<<'\n'<<n-1<<' '<<n<<'\n'; else if(g[1][2]=='0'&&g[2][1]=='0'&&g[n][n-1]=='1'&&g[n-1][n]=='1') cout<<0<<'\n'; else if(g[1][2]=='1'&&g[2][1]=='0'&&g[n][n-1]=='1'&&g[n-1][n]=='1') cout<<1<<'\n'<<1<<' '<<2<<'\n'; else if(g[1][2]=='0'&&g[2][1]=='1'&&g[n][n-1]=='1'&&g[n-1][n]=='1') cout<<1<<'\n'<<2<<' '<<1<<'\n'; else cout<<2<<'\n'<<1<<' '<<2<<'\n'<<2<<' '<<1<<'\n'; } return 0;
C - Palindromifier
a b c d e f → ( e d c b ) a b c d e f → e d c b a b c d e f ( e d c b a ) → e d c b a b c d e f e d c b a ( b c d e ) abcdef \to (edcb)abcdef\to edcbabcdef(edcba)\to edcbabcdefedcba(bcde) abcdef→(edcb)abcdef→edcbabcdef(edcba)→edcbabcdefedcba(bcde)
只要三步直接搞出来,能够配合代码和上述例子食用
debug
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #pragma GCC optimize(2) #include<set> #include<map> #include<cmath> #include<queue> #include<string> #include<vector> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<unordered_map> using namespace std; typedef long long ll; typedef pair<int,int> pii; int main() { IO; int T=1; //cin>>T; while(T--) { string s; cin>>s; int n=s.size(); cout<<3<<'\n'; cout<<"L "<<n-1<<'\n'; cout<<"R "<<n-1<<'\n'; cout<<"R "<<2*n-1<<'\n'; } return 0; }
D - Hexagons
六个方向分别让坐标的变化:
c 1 : ( x + 1 , y + 1 ) c_1:(x+1,y+1) c1:(x+1,y+1)
c 2 : ( x , y + 1 ) c_2:(x,y+1) c2:(x,y+1)
c 3 : ( x − 1 , y ) c_3:(x-1,y) c3:(x−1,y)
c 4 : ( x − 1 , y − 1 ) c_4:(x-1,y-1) c4:(x−1,y−1)
c 5 : ( x , y − 1 ) c_5:(x,y-1) c5:(x,y−1)
c 6 : ( x + 1 , y ) c_6:(x+1,y) c6:(x+1,y)
code
不难发现操做 c 2 + c 6 = c 1 c_2+c_6=c_1 c2+c6=c1、 c 3 + c 5 = c 4 c_3+c_5=c_4 c3+c5=c4
所以从两方面考虑是否使用 c 1 c_1 c1和 c 4 c_4 c4操做
若是不使用那么只经过单独进行横坐标±1和纵坐标±1到达目的地直接算便可。
若是使用那么首先使得最终向x坐标和向y坐标移动的步数(dx=dy)相等,因而考虑先经过横坐标±1或者纵坐标±1操做使最终dx=dy,而后再经过 c 1 c_1 c1或者 c 4 c_4 c4操做使之到达目的地。
不过注意等效操做 c 2 + c 6 = c 1 c_2+c_6=c_1 c2+c6=c1、 c 3 + c 5 = c 4 c_3+c_5=c_4 c3+c5=c4取代价更小的。
ci
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #pragma GCC optimize(2) #include<set> #include<map> #include<cmath> #include<queue> #include<string> #include<vector> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<unordered_map> using namespace std; typedef long long ll; typedef pair<int,int> pii; ll c[10]; int main() { IO; int T=1; cin>>T; while(T--) { ll x,y; cin>>x>>y; for(int i=1;i<=6;i++) cin>>c[i]; ll res=8e18;ll now=0; // +x 6 // -x 3 // +y 2 // -y 5 // 不用c1和c4 if(x>=0&&y>=0) now=c[6]*x+c[2]*y; else if(x>=0&&y<0) now=c[6]*x+c[5]*(-y); else if(x<0&&y>=0) now=c[3]*(-x)+c[2]*y; else now=c[3]*(-x)+c[5]*(-y); res=min(res,now); // 使用c1和c4 if(x>y) { now=0; now+=c[5]*(x-y); if(x>=0) now+=min(c[1],c[2]+c[6])*x; else now+=min(c[4],c[3]+c[5])*(-x); res=min(res,now); now=0; now+=c[6]*(x-y); if(y>=0) now+=min(c[1],c[2]+c[6])*y; else now+=min(c[4],c[3]+c[5])*(-y); res=min(res,now); } else { now=0; now+=c[3]*(y-x); if(y>=0) now+=min(c[1],c[2]+c[6])*y; else now+=min(c[4],c[3]+c[5])*(-y); res=min(res,now); now=0; now+=c[2]*(y-x); if(x>=0) now+=min(c[1],c[2]+c[6])*x; else now+=min(c[4],c[3]+c[5])*(-x); res=min(res,now); } cout<<res<<'\n'; } return 0; }
吐槽一波,这题debug了半天居然是上限搞小了,本身通常开 1 0 18 10^{18} 1018结果有数据的答案比该值还大,最终把最大值开到 8 × 1 0 18 8×10^{18} 8×1018才过的。。。get
刚刚看了一波别人的题解,发现D题只须要把全部等效操做的代价取个最小值便可,不必这样讨论,嗨本身仍是太菜了string
E - Swedish Heroes
这题好像是dp,之后回补的!it
最近学业压力有点重,并且快期中考试了。。。这周六还有校赛,但愿能打出好成绩。