Codeforces Round 922 (Div. 2) A~C

A. Brick Wall

#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n,m;
    cin>>n>>m;
    int ans=n*(m/2);
    cout<<ans<<"\n";
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 

B. Minimize Inversions 观察数据

image
image

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N],b[N];
void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    vector<pair<int,int>>p(n+1);
    for(int i=1;i<=n;i++){
        p[i].first=a[i];
        p[i].second=b[i];
    }
	sort(p.begin()+1,p.end());
    for(int i=1;i<=n;i++){
        cout<<p[i].first<<" ";
    }
    cout<<"\n";
	for(int i=1;i<=n;i++){
        cout<<p[i].second<<" ";
    }
    cout<<"\n";
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 

C. XOR-distance

image
image
image

范围给的很大 要么打表找,要么是二进制

#include<bits/stdc++.h>
#define int long long 
using namespace std;
void solve() {
    int a, b, r;
    cin >> a >> b >> r;
    if (a < b) {
        swap(a, b);
    }
    bool ok = 0;
    int x = 0;
    for (int i = 63; i >= 0; i--) {
        if ((a >> i & 1) && !(b >> i & 1)) {
            if (ok) {
                if (x + (1LL << i) <= r) {
                    x += (1LL << i);
                }
            } else {
                ok = 1;
            }
        }
    }
    cout << abs((a ^ x) - (b ^ x)) << '\n';
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 
posted @ 2024-02-13 12:01  yufan1102  阅读(9)  评论(0编辑  收藏  举报