这一场有点坑
A题,求最大值之后相减
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-7; const int N=1000+10,maxn=500+100,inf=0x3f3f3f; int a[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n,maxx=-1,ans=0; cin>>n; for(int i=0;i<n;i++) { cin>>a[i]; maxx=max(a[i],maxx); } for(int i=0;i<n;i++) ans+=maxx-a[i]; cout<<ans<<endl; return 0; } /******************** ********************/
B,暴力dfs,注意剪枝
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-7; const int N=1000+10,maxn=500+100,inf=0x3f3f3f; char p[4]={'R','B','Y','G'}; string ans; bool ok(string s) { for(int i=0;i+3<s.size();i++) { int rr=0,bb=0,yy=0,gg=0; for(int j=0;j<4;j++) { if(s[i+j]=='R')rr++; else if(s[i+j]=='B')bb++; else if(s[i+j]=='Y')yy++; else gg++; } if(rr!=1||gg!=1||yy!=1||bb!=1)return 0; } return 1; } void dfs(int x,string t) { // cout<<t<<endl; if(x==t.size()) { if(ok(t))ans=t; return ; } if(t[x]=='!') { for(int i=0;i<4;i++) { t[x]=p[i]; if(x>=3) { int rr=0,bb=0,yy=0,gg=0; for(int j=0; j<4; j++) { if(t[x-j]=='R')rr++; else if(t[x-j]=='B')bb++; else if(t[x-j]=='Y')yy++; else gg++; } if(rr!=1||gg!=1||yy!=1||bb!=1)continue; } dfs(x+1,t); } } else dfs(x+1,t); } int main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin>>s; int kr=0,kb=0,ky=0,kg=0; dfs(0,s); for(int i=0;i<s.size();i++) { if(s[i]=='!') { if(ans[i]=='R')kr++; else if(ans[i]=='B')kb++; else if(ans[i]=='Y')ky++; else if(ans[i]=='G')kg++; } } cout<<kr<<" "<<kb<<" "<<ky<<" "<<kg<<endl; return 0; } /******************** !!!!YGRB YGR!YGRB ********************/
C分类讨论,O(1)模拟
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-7; const int N=1000+10,maxn=500+100,inf=0x3f3f3f; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n,m,k,x,y; cin>>n>>m>>k>>x>>y; if(n==1) { if(k%m==0)cout<<k/m<<" "<<k/m<<" "<<k/m<<endl; else cout<<k/m+1<<" "<<k/m<<" "<<(k%m>=y?k/m+1:k/m)<<endl; return 0; } if(n==2) { ll s=k/(2*m),p=k%(2*m),ans; if(p>=(x-1)*m+y)ans=s+1; else ans=s; if(p==0)cout<<s<<" "<<s<<" "<<ans<<endl; else cout<<s+1<<" "<<s<<" "<<ans<<endl; return 0; } ll s=k/((2*n-2)*m),p=k%((2*n-2)*m); ll maxx,minn,ans; if(m<p&&p<=n*m)maxx=s*2+1; else if(p<=m)maxx=s*2; else if(p>n*m)maxx=s*2+2; maxx=max(maxx,1ll); if(p<n*m)minn=s; else minn=s+1; // cout<<s<<" "<<p<<endl; if(x==1) { if(p>=y)ans=s+1; else ans=s; } else if(2<=x&&x<=n-1) { if(p<(x-1)*m+y)ans=s*2; else if(p>=(x-1)*m+y&&p<(2*n-x-1)*m+y)ans=s*2+1; else ans=s*2+2; } else { if(p>=(n-1)*m+y)ans=s+1; else ans=s; } cout<<maxx<<" "<<minn<<" "<<ans<<endl; return 0; } /******************** 47 39 1772512 1 37 ********************/