• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

AtCoder Beginner Contest 190

互联网 diligentman 4周前 (01-31) 16次浏览

AtCoder Beginner Contest 190

A – Very Very Primitive Game

#include <bits/stdc++.h>

#pragma GCC optimize(2)
#define int long long
using namespace std;
//const int mod = 998244353;
const int inf=1e18;
const int mod = 1e9 + 7;
const int maxn = 3e5 + 10;

int a[maxn];

void solve() {
    int a,b,c;
    cin>>a>>b>>c;
    if (a==b){
        cout<<(c==1?"Takahashi":"Aoki");
    } else{
        cout<<(a>b?"Takahashi":"Aoki");
    }
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

B – Magic 3

#include <bits/stdc++.h>

#pragma GCC optimize(2)
#define int long long
using namespace std;
//const int mod = 998244353;
const int inf=1e18;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;

int a[maxn];
int b[maxn];

void solve() {
    int n,s,d;
    cin>>n>>s>>d;
    for (int i = 0; i < n; ++i) {
        cin>>a[i]>>b[i];
    }
    int f=0;
    for (int i = 0; i < n; ++i) {
        if (a[i]<s&&b[i]>d) {
            f=1;
        }
    }
    cout<<(f==1?"Yesn":"Non");
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

C – Bowls and Dishes

二进制硬暴力每种情况

#include <bits/stdc++.h>

#pragma GCC optimize(2)
#define int long long
using namespace std;
//const int mod = 998244353;
const int inf=1e18;
const int mod = 1e9 + 7;
const int maxn = 1e2 + 10;

int a[maxn];
int b[maxn];
int c[maxn];
int d[maxn];
int e[maxn];

void solve() {
    int n,m;
    cin>>n>>m;
    for (int i = 0; i < m; ++i) {
        cin>>a[i]>>b[i];
    }
    int k;
    cin>>k;
    for (int i = 0; i < k; ++i) {
        cin>>c[i]>>d[i];
    }
    int ans=0;
    for (int i = 0; i < (1 << k); ++i) {
        memset(e,0,sizeof(e));
        for (int j = 0; j <k; ++j) {
            //cout<<((i>>j)&1)<<"n";
            if ((i>>j)&1){
                e[c[j]]=1;
            } else e[d[j]]=1;
        }
        /*for (int l = 1; l <=m; ++l) {
            cout<<e[l]<<" ";
        }cout<<"n";*/
        int sum=0;
        for (int j = 0; j < m; ++j) {
            //cout<<e[a[j]]<<" "<<e[b[j]]<<"n";
            if (e[a[j]]==1&&e[b[j]]==1){
                sum++;
            }
        }//cout<<"nn";
        ans=max(ans,sum);
    }
    cout<<ans;
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

D – Staircase Sequences

求其奇数因子个数,因为可以配合负数所以每种都可以变成俩种,所以ans=2*奇数因子个数

#include <bits/stdc++.h>

#pragma GCC optimize(2)
#define int long long
using namespace std;
//const int mod = 998244353;
const int inf = 1e18;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;

int dp[maxn];

void solve() {
    int a ;
    cin >> a;
    int ans = 0;     //ans是求a所有因子数的总个数
    for (int i = 1; i * i <= a; i++) {
        if (a % i == 0) {
            if (i%2==1) ans++;
            if (i != a / i&&(a/i)%2==1) {     //两个因子数不相等
                ans++;
            }
        }
    }
    printf("%dn", 2*ans);
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

F – Shift and Inversions

先求出原数组逆序对,然后每把开头移到结尾,ans+=(n-b[i]-1)-b[i];
因为把b[i]放到结尾前面有n-b[i]-1比他大,又原本有b[i]个逆序因为他的移到而没有了

#include <bits/stdc++.h>

#pragma GCC optimize(2)
#define int long long
using namespace std;
//const int mod = 998244353;
const int inf = 1e18;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;

int a[maxn];
int t[maxn];
int b[maxn];
int res;

void merge_sort(int l,int r){
    if(l>=r)return ;
    int mid=l+r>>1;
    merge_sort(l,mid),merge_sort(mid+1,r);//递归分治
    int i=l,j=mid+1,n=0;
    while(i<=mid&&j<=r)
        if(a[i]<=a[j])t[n++]=a[i++];
        else res+=mid-i+1,t[n++]=a[j++];//计算答案的情况
    while(i<=mid)t[n++]=a[i++];
    while(j<=r)t[n++]=a[j++];
    for(int i=l,j=0;i<=r;i++,j++)a[i]=t[j];
}

void solve() {
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i) {
        cin>>a[i],b[i]=a[i];
    }
    merge_sort(0,n-1);
    for (int i = 0; i < n; ++i) {
        cout<<res<<"n";//cout<<(n-b[i]-1)<<"n";
        res+=(n-b[i]-1)-b[i];
    }
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

//0 3 1 5 4 2 9 6 8 7    9
//3 1 5 4 2 9 6 8 7 0    9+(10-0-1)=18
//1 5 4 2 9 6 8 7 0 3    18+(10-3-1)=24
//5 4 2 9 6 8 7 0 3 1
//4 2 9 6 8 7 0 3 1 5


程序员灯塔
转载请注明原文链接:AtCoder Beginner Contest 190
喜欢 (0)