Mail.Ru Cup 2018 Round 1 ----C. Candies Distribution

地址:http://codeforces.com/contest/1054/problem/C

这道题是简单题就是我没有逆向思维,思维不会变通,当时想到,如果给的L,R数组是正确的话,那么答案就是n - L[i] - R[i],然后就一直在想如何判断给的数组一定输出YES,其实可以先减得出结果数组,然后再判断是否可以得出L,R数组,如果不能,输出NO,否则输出YES和结果数组。。。。。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const int N = 1005;

int L[N];
int R[N];
int res[N];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 1;i <= n;++i) scanf("%d",&L[i]);
    for(int i = 1;i <= n;++i) scanf("%d",&R[i]);
    for(int i = 1;i <= n;++i) res[i] = n - L[i] - R[i];
    for(int i = 1;i <= n;++i){
        for(int j = i + 1;j <= n;++j){
            if(res[j] > res[i]){
                R[i]--;
            }
            if(res[j] < res[i]){
                L[j]--;
            }
        }
    }
    for(int i = 1;i <= n;++i){
        if(L[i] != 0 || R[i] != 0){
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    for(int i = 1;i <= n;++i){
        printf("%d ",res[i]);
    }
    printf("\n");
    return 0;
}


猜你喜欢

转载自blog.csdn.net/qq_36386435/article/details/83239171