ZJNU 2135 - 小智的宝可梦

因为成环

所以可以枚举第1只与第n只喂的次数

然后第1只和第2只的次数就固定了,以此类推,则所有宝可梦喂的次数都固定了

最后处理完检查是否全为0,不是则进行下一次枚举,是则直接输出Yes

如果所有枚举均不成立,输出No

 1 /*
 2 Written By. StelaYuri
 3 On 2020/01/15
 4 */
 5 #include<bits/stdc++.h>
 6 using namespace std;
 7 int main(){
 8     ios::sync_with_stdio(0);
 9     cin.tie(0);cout.tie(0);
10     int n,i,j,a[1005],d[1005];
11     bool pass;
12     cin>>n;
13     if(n<2){
14         cout<<"Yes\n";
15         return 0;
16     }
17     else if(n==2){
18         cin>>a[1]>>a[2];
19         if(a[1]!=a[2])
20             cout<<"No\n";
21         else
22             cout<<"Yes\n";
23         return 0;
24     }
25     for(i=1;i<=n;i++)
26         cin>>a[i];
27     for(j=0;j<=a[1];j++){//枚举第1只与第n只喂的次数
28         for(i=1;i<=n;i++)
29             d[i]=a[i];
30         d[1]-=j;
31         d[n]-=j;
32         for(i=1;i<n;i++){
33             d[i+1]-=d[i];
34             d[i]=0;
35         }
36         pass=true;
37         for(i=1;i<=n;i++)
38             if(d[i]){
39                 pass=false;
40                 break;
41             }
42         if(pass){
43             cout<<"Yes\n";
44             return 0;
45         }
46     }
47     cout<<"No\n";
48     
49     return 0;
50 }

猜你喜欢

转载自www.cnblogs.com/stelayuri/p/12236303.html