H. Photoshoot

H. Photoshoot

https://codeforces.com/group/5yyKg9gx7m/contest/270203/problem/H

分析:

开始没读懂题。。因为他编号是1~n,不能多不能少。所以从小到暴力即可,只要符合b i=a i+a i+1的要求和编号恰好含1~n。

#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int b[n+6];
    int a[n+6];
    bool used[n+6]; 
    for(int i=1;i<=n-1;i++)
    {
        cin>>b[i];
    }
    bool over=1;
    for(int i=1;i<=b[1];i++)
    {
        memset(used,0,sizeof used);
        a[1]=i;
        used[i]=true;
        over=1;
        for(int j=1;j<=n-1;j++)
        {
            int p=b[j]-a[j];
            if(used[p]||p<=0||p>n)
            {
                over=0;
                break;
            }
            used[p]=1;
            a[j+1]=p;   
        }
        if(over) break;
    }
    for(int i=1;i<=n;i++)
    {
        printf("%d ",a[i]);
    }
    return 0;
}

 

 

posted on 2020-03-03 22:02  Aminers  阅读(132)  评论(0编辑  收藏  举报

导航