Codeforces Round #676 (Div. 2)

1421A - XORwice:
#include <iostream>

using namespace std;
int n, m;

int main()
{
    
    
    int T;
    cin >> T;
    while(T -- )
    {
    
    
        cin >> n >> m;
        int a = n & m;
        int c = a ^ n;
        int d = a ^ m;
        printf("%d\n", c + d);
    }
    
    return 0;
}

B. Putting Bricks in the Wall

我们只需要知道Pink一开始走出起点的限制有两个格子( 1 , 2 ) (1,2)(1,2)和(2,1),走到终点也有两个格子限制( n − 1 , n ) (n-1,n)(n−1,n)和( n , n − 1 ) (n,n-1)(n,n−1)。那么只要使得这起点格子和终点格子起冲突即可。让这两组的格子元素值相反即可。

#include<bits/stdc++.h>
using namespace std;
int main(){
    
    
	int t;
    cin>>t;
    while(t--){
    
    
        int n;
        cin>>n;
        string s[n+5];
        for(int i=0;i<n;i++){
    
    
            cin>>s[i];
        }
        vector<pair<int,int>>ans;
        for(int i=0;i<=1;i++){
    
    
            ans.resize(0);
            if(s[0][1]==i+'0'){
    
    
                ans.push_back({
    
    1,2});
            }
            if(s[1][0]==i+'0'){
    
    
                ans.push_back({
    
    2,1});
            }
            if(s[n-1][n-2]==(i^1)+'0'){
    
    
                ans.push_back({
    
    n,n-1});
            }
            if(s[n-2][n-1]==(i^1)+'0'){
    
    
                ans.push_back({
    
    n-1,n});
            }
            //当小于等于2时,说明已是最优情况
            if(ans.size()<=2){
    
    
                break;
            }
        }
        cout<<ans.size()<<endl;
        for(auto it:ans){
    
    
            cout<<it.first<<' '<<it.second<<endl;
        }
    }
}

第三题:
C. Palindromifier

解析: 先复制L 2, 然后复制2 之后的,然后复制2之前的size() * 2 - 1

#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
    
    
cin>>s;
printf("3\nL 2\nR 2\nR %d",2*s.size()-1);
}

第四题:
D. Hexagons

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
int main(){
    
    
    int t;
    cin>>t;
    while(t--){
    
    
        ll x,y,c1,c2,c3,c4,c5,c6;
        cin>>x>>y;
        cin>>c1>>c2>>c3>>c4>>c5>>c6;
        ll ans=(x>=0?c6:c3)*abs(x)+(y>=0?c2:c5)*abs(y);
        ans=min(ans,(x>=0?c1:c4)*abs(x)+(y-x>=0?c2:c5)*abs(y-x));
        ans=min(ans,(y>=0?c1:c4)*abs(y)+(y-x>=0?c3:c6)*abs(y-x));
        cout<<ans<<endl;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_45772236/article/details/109207430
今日推荐