A
签到
#include <bits/stdc++.h> #define ll long long using namespace std; const int maxn = 150; int p[maxn],s[maxn],mx[maxn],c[maxn]; int main() { int n,m,k; cin>>n>>m>>k; for(int i = 1;i <= n;i++){ cin>>p[i]; } for(int i = 1;i <= n;i++){ cin>>s[i]; } for(int i = 1;i <= n;i++){ if(p[mx[s[i]]] < p[i]){ mx[s[i]] = i; } } int tot = 0; for(int i = 1;i <= k;i++){ cin>>c[i]; if(mx[s[c[i]]] != c[i]) tot++; } cout<<tot; return 0; }
B
签到
#include <bits/stdc++.h> #define ll long long using namespace std; const int maxn = 1050; const int maxm = 200050; int a[maxn],vis[maxm]; int main() { int n; cin>>n; for(int i = 1;i <= n;i++){ cin>>a[i]; } int ans = 0; for(int i = 1;i <= n;i++){ for(int j = i+1;j <= n;j++){ vis[a[i]+a[j]]++; ans = max(vis[a[i]+a[j]],ans); } } cout<<ans; return 0; }
C
模拟
#include<bits/stdc++.h> using namespace std; int n,k,i,j,m,l,b[150],c[150],a[1500],d[1500],f[1500]; int main() { for(scanf("%d%d",&n,&k); i<n; ++i,scanf("%d",a+i)); for(m=-(k=min(k,n)); m<n;) { for(i=1; i<=k; (c[i]==a[b[i]]?(b[i]=j,d[j]=c[i]=1,++m):++c[i]),++i) if(c[i]==a[b[i]]) for(j=1; j<=n&&d[j]; ++j); for(l=(200*m+n)/(n<<1),i=1; i<=k; f[b[i]]|=(c[i]==l),++i); } for(k=0,i=1; i<=n; k+=f[i++]); printf("%d ",k),exit(0); }
D
尺取法,剪裁区间细节很多
#include <bits/stdc++.h> #define ll long long using namespace std; const int maxn = 500050; int m,n,k,s; int a[maxn],b[maxn]; int t[maxn]; int now[maxn]; bool vis[maxn]; int main() { ios::sync_with_stdio(false); cin>>m>>k>>n>>s; for(int i = 1;i <= m;i++) { cin >> a[i]; } for(int i = 1;i <= s;i++){ cin>>b[i]; t[b[i]]++; } if(s > k){ cout<<-1; return 0; } int lp = 1; int wst = 0; int ansl = 0,ansr = 0,ans = maxn; int cnt=0; int lm = m - n*k; for(int j = 1;j <= m;j++){ if(!t[a[j]]){ wst++; }else{ if(now[a[j]] < t[a[j]])cnt++; else wst++; now[a[j]]++; } while(now[a[lp]] > t[a[lp]] || !t[a[lp]]){ if(lp > j) break; if(!t[a[lp]]){ wst--; lp++; }else{ now[a[lp]]--; wst--; lp++; } } if(cnt == s){ int tl = lp; int tr = j; int tw = max(tr-tl+1-k,0); //int cut = wst + min(tr%k,(tl-1)%k); int cut = min((tl-1)%k+tw,tw+(tr-tw)%k); if(cut <= lm){ ansl = lp; ansr = j; ans = cut; } } } if(ans > lm) cout<<"-1"; else{ memset(now,0,sizeof(now)); cout<<m-n*k<<endl; int tt = m-n*k; for(int i = ansl;i <= ansr;i++){ if(tt <= 0) break; now[a[i]]++; if(now[a[i]] > t[a[i]]){ vis[i] = true; tt--; } } for(int i = ansl-1;i >= 1 && tt > 0;i--,tt--){ vis[i] = true; } for(int i = ansr+1;i <= m && tt > 0;i++,tt--){ vis[i] = true; } for(int i = 1;i <= m;i++){ if(vis[i]) cout<<i<<" "; } cout<<endl; } return 0; }
F
DP
#include <bits/stdc++.h> #define ll long long using namespace std; const int maxn = 5050; char s[maxn]; int n,a,b; int dp[maxn]; int f[maxn][maxn]; int main() { ios::sync_with_stdio(false); cin>>n>>a>>b; cin>>(s+1); for(int i = 2;i <= n;i++){ for(int j = 1;j < i;j++){ if(s[i] == s[j]) f[i][j] = f[i-1][j-1] + 1; } } for(int i = 1;i <= n;i++){ dp[i] = min(a*i,dp[i-1]+a); for(int j = 1;j < i;j++){ dp[i] = min(dp[i],dp[i-min(i-j,f[i][j])]+b); } } cout<<dp[n]; return 0; }