CodeForces Round #569 Div.2

A. Alex and a Rhombus

#include <bits/stdc++.h>
using namespace std;
 
int num[110];
int N;
 
int main() {
    memset(num, 0, sizeof(num));
    num[0] = 0, num[1] = 1;
    for(int i = 2; i <= 100; i ++)
        num[i] = num[i - 1] + 4 * (i - 1);
 
    scanf("%d", &N);
    printf("%d\n", num[N]);
 
    return 0;
}
View Code

B. Nick and Array

#include <bits/stdc++.h>
using namespace std;
 
const int maxn = 1e5 + 10;
int N;
int a[maxn];
 
int main() {
    scanf("%d", &N);
    for(int i = 0; i < N; i ++) {
        scanf("%d", &a[i]);
        if(a[i] >= 0) a[i] = -1 * a[i] - 1;
    }
    if(N % 2) {
        int minn = -1, temp = 0;
        for(int i = 0; i < N; i ++) {
            if(a[i] < minn) {
                minn = a[i];
                temp = i;
            }
        }
        if(minn == -1) a[0] = 0;
        else a[temp] = -1 * a[temp] - 1;
    }
 
    for(int i = 0; i < N; i ++)
        printf("%d%s", a[i], i == N - 1 ? "\n" : " ");
    return 0;
}
View Code

C. Valeriy and Deque

By Golden_miner, contest: Codeforces Round #569 (Div. 2), problem: (C) Valeriy and Deque, Accepted, #, Copy
#include <bits/stdc++.h>
using namespace std;
 
const int maxn = 1e5 + 10;
int N, Q;
deque<int> q;
vector<pair<int, int> >v;
 
int main() {
    scanf("%d%d", &N, &Q);
    int maxx = -1, temp = 0;
    for(int i = 1; i <= N; i ++) {
        int x;
        scanf("%d", &x);
        maxx = max(maxx, x);
        q.push_back(x);
    }
 
    int top = q.front();
    while(top != maxx) {
        pair<int, int> p;
        p.first = q.front(); q.pop_front();
        p.second = q.front(); q.pop_front();
        v.push_back(p);
        q.push_front(max(p.first, p.second));
        q.push_back(min(p.first, p.second));
        top = q.front();
    }
 
    q.pop_front();
    int sz = v.size();
 
    deque<int>::iterator it = q.begin();
    for(it = q.begin(); it != q.end(); it ++) {
        pair<int, int> p;
        p.first = top, p.second = *it;
        v.push_back(p);
    }
 
    while(Q --) {
        long long tim;
        scanf("%lld", &tim);
        if(tim <= sz) printf("%d %d\n", v[tim - 1].first, v[tim - 1].second);
        else {
            tim -= sz;
            tim %= (v.size() - sz);
            tim = (tim % (v.size() - sz) == 0) ? v.size() - sz : tim % (v.size() - sz);
            printf("%d %d\n", v[tim + sz - 1].first, v[tim + sz - 1].second);
        }
    }
 
    return 0;
}
View Code

D. Tolik and His Uncle

#include <bits/stdc++.h>
using namespace std;

int N, M;

int main() {
    scanf("%d%d", &N, &M);
    int x = 1, y = 1;
    int dx = N, dy = M;
    int cnt = 0;
    
    while(cnt != N * M) {
        if(cnt == N * M - 1) {
            printf("%d %d\n", x, y);
            break;
        }

        printf("%d %d\n%d %d\n", x, y, dx, dy);

        if(y < M) y ++;
        else {
            x ++;
            y = 1;
        }

        if(dy > 1) dy --;
        else {
            dx --;
            dy = M;
        }

        cnt += 2;
    }
    return 0;
}
View Code

APP 开发算是中场休息辣!我终于终于更题目了 呜呜呜

猜你喜欢

转载自www.cnblogs.com/zlrrrr/p/12802287.html