Diary_2.26

Codeforces Round 1006 (Div. 3)

1. New World, New Me, New Array

int n, k, p;
void solve(){
    cin >> n >> k >> p;
    if((k>0 && n*p < k )|| (k<0 && -n*p > k)){
        cout << -1 << endl;
    }else{
        if(k<0){
            k = -k;
        }
        cout << k/p+(k%p ? 1: 0) << endl;
    }
}

2. Having Been a Treasurer in the Past, I Help Goblins Deceive

#define int long long
int n;
void solve(){
    cin >> n;
    string s;   cin >> s;
    int cntl = 0, cntr = 0;
    for(int i=0; i<n; i++){
        if(s[i] == '-') cntl++;
        else    cntr++;
    }
    int l = cntl/2;
    int r = cntl-l;
    int ans = l*r*cntr;
    cout << ans << endl;
}

3. Creating Keys for StORages Has Become My Main Skill

#define int long long
void solve(){
    int n, x;   cin >> n >> x;
    int cx = x;
    int a[n], cnt = 0;
    memset(a, 0, sizeof(a));
    vector<int> q;
    int p = 0, cnt1 = 0;
    while(x){
        if((x&1) == 0){
            q.push_back(p);
        }else{
            cnt1++;
        }
        x >>= 1;
        p++;
    }
    // 符合就放,不符合就跳过,直到所有的位都访问过了
    bool vis[p];
    memset(vis, 0, sizeof(vis));
    int len = q.size();
    for(int i=0; i<n; i++){
        for(int k=0; k<len; k++){
            if((i >> q[k]) == 1)    goto lable;
        }
        a[cnt++] = i;
        if(i>=((1<<(p))-1))   break;
    }
    lable: ;
    int t = 0;
    for(int i=0; i<n; i++){
        t |= a[i];
    }
    if(t != cx){
        a[n-1] = cx;
    }
    int tt = 0;
    for(int i=0; i<n; i++){
        cout << a[i] << ' ';
        tt |= a[i];
    }
    cout << endl;
    // cout << tt << endl;
}

4. For Wizards, the Exam Is Easy, but I Couldn't Handle It

#define int long long
void solve(){
    int n;  cin >> n;
    int a[n];
    for(int i=0; i<n; i++)  cin >> a[i];
    int ans = 0, ansl = 0, ansr = 0;
    for(int i=0; i<n; i++){
        int cnt = 0;
        for(int k=i+1; k<n; k++){
            if(a[i] > a[k]) cnt++;
            if(a[i] < a[k]) cnt--;
            if(ans < cnt){
                ans = cnt;
                ansl = i, ansr = k;
            }
        }
    }
    cout << ansl+1 << ' ' << ansr+1 << endl;
}
posted @   Devpp  阅读(10)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示