提交时间:2021-05-12 18:49:44

运行 ID: 19221

#include<bits/stdc++.h> using namespace std; int a[1010],r[1010],dp[110][110]; int n,ans,ma; void init() { cin>>n>>r[1]; for(int i=1;i<=n;++i){ a[i]=r[i]%10; r[i+1]=(r[i]*6807+2831)%201701; } } int check(int x) { int le,ri,i; for(i=1;i<=n;++i) if(a[i]>=x){le=i;break;} for(i=n;i>=1;--i) if(a[i]>=x){ri=i;break;} for(i=le+1;i<=ri-1;++i) if(a[i]<x)ans++; cout<<le<<" "<<ri<<" "<<x<<" "<<ans<<endl; } int main() { init(); for(int i=0;i<=9;++i) check(i); cout<<ans; return 0; } 方法二:O(n^2) #include<bits/stdc++.h> using namespace std; int a[1010],r[1010]; int n,ans,tot; void init() { cin>>n>>r[1]; for(int i=1;i<=n;++i){ a[i]=r[i]%10; r[i+1]=(r[i]*6807+2831)%201701; } } int check(int x) { int max1=0,max2=0,minn; for(int i=1;i<=x-1;++i) max1=max(max1,a[i]); for(int i=x+1;i<=n;++i) max2=max(max2,a[i]); minn=min(max1,max2); if(minn>a[x])return minn-a[x]; else return 0; } int main() { init(); for(int i=2;i<=n-1;++i){ ans+=check(i); } cout<<ans; return 0; }