1. 程式人生 > >CodeForces Round #549 Div.2

CodeForces Round #549 Div.2

col queen closed pac lan for eve root std

A. The Doors

代碼:

技術分享圖片
#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10;
int N;
int Zero = 0, One = 0;
int a[maxn], b[maxn], suma[maxn], sumb[maxn];
int num1, num2, ans;

int main() {
    scanf("%d", &N);
    for(int i = 0; i < N; i ++) {
        scanf("%d
", &a[i]); if(a[i] == 1) { b[i] = 0; One ++; } if(a[i] == 0) { b[i] = 1; Zero ++; } if(i == 0) suma[i] = a[i], sumb[i] = b[i]; else suma[i] = suma[i - 1] + a[i], sumb[i] = sumb[i - 1] + b[i]; }
for(int i = 0; i < N; i ++) { if(suma[i] == One) { num1 = i; break; } } for(int i = 0; i < N; i ++) { if(sumb[i] == Zero) { num2 = i; break; } } ans = min(num1, num2); printf("%d\n"
, ans + 1); return 0; }
View Code

B. Nirvana

代碼:

技術分享圖片
#include <bits/stdc++.h>
using namespace std;

int N;

int Ans(int x) {
    if(x < 10) return max(1, x);
    return max((x % 10) * Ans(x / 10), 9 * Ans(x / 10 - 1));
}

int main() {
    scanf("%d", &N);
    printf("%d\n", Ans(N));
    return 0;
}
View Code

C. Queen

代碼:

技術分享圖片
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
int N;
int root;
int vis[maxn];
vector<int> ans;

int main() {
    scanf("%d", &N);
    for(int i = 1; i <= N; i ++) {
        int st, col;
        scanf("%d%d", &st, &col);
        if(col == 0) {
            if(st != -1)
                vis[st] = 1;
            vis[i] = 1;
        }
    }

    for(int i = 1; i <= N; i ++) {
        if(vis[i] != 1)
            ans.push_back(i);
    }

    if(ans.size() == 0) printf("-1\n");
    else {
        sort(ans.begin(), ans.end());
        for(int i = 0; i < ans.size(); i ++)
            printf("%d%s", ans[i], i != ans.size() - 1 ? " " : "\n");
    }

    return 0;
}
View Code

最近是理解能力下降???讀題讀不清楚???菜是原罪!!!

CodeForces Round #549 Div.2