标签:div problem c++ \n name else 注意 fine span
题目链接:http://codeforces.com/gym/101775/problem/J
思路:序列差分一下,然后用得到的查分序列乱搞就可以了
注意差分序列第一项等于a[i],之后n-1项为cha[i]=a[i]-a[i-1],第n+1项为0-a[n]
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 typedef long long ll; 5 const int mod=1e9+7; 6 const int maxn=2e5+10; 7 const int inf=0x3f3f3f3f; 8 const double eps=1e-14; 9 const double pi=acos(-1.0); 10 #define mem(s,v) memset(s,v,sizeof(s)) 11 #define pdd pair<double,double> 12 #define pii pair<int,int> 13 14 int t,n; 15 int a[maxn],cha[maxn]; 16 17 int main(){ 18 scanf("%d",&t); 19 for(int k=1;k<=t;++k){ 20 scanf("%d",&n); 21 for(int i=1;i<=n;++i){ 22 scanf("%d",&a[i]); 23 if(i==1) cha[i]=a[i]; 24 else cha[i]=a[i]-a[i-1]; 25 } 26 cha[n+1]=0-a[n]; 27 int sum=0; 28 int flag=1; 29 if(cha[2]<0||cha[3]<0) flag=0; 30 for(int i=1;i<=n+1;++i){ 31 // cout<<cha[i]<<" "; 32 if(cha[i]>=0) sum+=cha[i]; 33 int temp=i+3; 34 if(temp>n+1) break; 35 if(cha[temp]<0) sum+=cha[temp]; 36 if(sum<0) break; 37 } 38 // cout<<endl; 39 if(sum) flag=0; 40 printf("Case #%d: ",k); 41 if(flag) printf("Yes\n"); 42 else printf("No\n"); 43 } 44 return 0; 45 }
2017 ECL-FINAL J.Straight Master
标签:div problem c++ \n name else 注意 fine span
原文地址:https://www.cnblogs.com/wangcwcgnaw/p/9936832.html