2-5下午测试 -- 409总结

· · 个人记录

又到了总结时间了,这是2-5下午测试的总结,咱们话不多说直接开始吧!!!!!!

2-5下午测试的总结

T1:P1125 [NOIP 2008 提高组] 笨小猴

这是一道十分简单的橙题,我觉得这题要降到红题都可以

```cpp #include<bits/stdc++.h> using namespace std; int a[30]; bool isp(int x){ if(x<2){ return 0; } for(int i=2;i*i<=x;i++){ if(x%i==0){ return 0; } } return 1; } int main(){ string s; cin >> s; for(int i=0;i<s.size();i++){ a[s[i]-'a'+1]++; } int maxn=0,minn=1e9; for(int i=1;i<=26;i++){ if(a[i]==0)continue; maxn=max(maxn,a[i]); minn=min(minn,a[i]); } if(isp(maxn-minn)){ cout << "Lucky Word\n"<<maxn-minn; } else{ cout<< "No Answer\n0"; } return 0; } ``` ## T2:[P1699 [USACO19OPEN] Bucket Brigade B](https://www.luogu.com.cn/problem/P1699?contestId=229077 ) ### bfs模板题 $ \textcolor{green}{ Accepted {}} $代码 ```cpp #include<bits/stdc++.h> using namespace std; char a[15][15]; int dis[15][15]; int vis[15][15]; int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1}; struct node{ int x,y; }; int main(){ int sx,sy; for(int i=1;i<=10;i++){ for(int j=1;j<=10;j++){ cin>> a[i][j]; if(a[i][j]=='B'){ sx=i; sy=j; } } } queue<node>op; op.push({sx,sy}); vis[sx][sy]=1; while(op.size()!=0){ int x=op.front().x; int y=op.front().y; op.pop(); if(a[x][y]=='L'){ cout << dis[x][y]-1; return 0; } for(int i=0;i<4;i++){ int nx=x+dx[i]; int ny=y+dy[i]; if(a[nx][ny]=='R'){ continue; } if(vis[nx][ny]==1){ continue; } if(x>10||x<1||y>10||y<1){ continue; } op.push({nx,ny}); vis[nx][ny]=1; dis[nx][ny]=dis[x][y]+1; } } return 0; } ``` ## T3:[P1091 [NOIP 2004 提高组] 合唱队形](https://www.luogu.com.cn/problem/P1091?contestId=229077) $ \textcolor{green}{ Accepted {}} $代码 ```cpp #include<bits/stdc++.h> using namespace std; #define int long long int a[10005]; int f[10005]; int f1[10005]; signed main(){ int n; cin >> n; for(int i=1;i<=n;i++){ cin >> a[i]; } for(int i=1;i<=n;i++){ f[i]=1; for(int j=1;j<i;j++){ if(a[i]>a[j])f[i]=max(f[i],f[j]+1); } } for(int i=n;i>=1;i--){ f1[i]=1; for(int j=n;j>i;j--){ if(a[i]>a[j])f1[i]=max(f1[i],f1[j]+1); } } int maxn=-1e9; for(int i=1;i<=n;i++){ maxn=max(maxn,f[i]+f1[i]-1); } cout << n-maxn; return 0; } ``` ## T4:[P1566 加等式](https://www.luogu.com.cn/problem/P1566?contestId=229077) $ \textcolor{green}{ Accepted {}} $代码 ```cpp #include<bits/stdc++.h> using namespace std; int n,m,a[1005],dp[1005][10005]; int main(){ int t; cin >> t; while(t--){ cin>> n; for(int i=1;i<=n;i++){ cin >> a[i]; } sort(a+1,a+n+1); memset(dp,0,sizeof dp); dp[0][0]=1; for(int i=1;i<=n;i++){ dp[i][0]=1; for(int j=1;j<=a[n];j++){ if(j<a[i])dp[i][j]=dp[i-1][j]; else dp[i][j]=dp[i-1][j]+dp[i-1][j-a[i]]; } } int ans=0; for(int i=1;i<=n;i++){ ans+=dp[i][a[i]]; } cout << ans-n<<'\n'; } return 0; } ``` ## T5:[B3784 [语言月赛202306] 演唱会](https://www.luogu.com.cn/problem/B3784?contestId=229077) $ \textcolor{green}{ Accepted {}} $代码 ```cpp #include<bits/stdc++.h> #define int long long using namespace std; struct N{ int id,xaz; }l[100005]; bool cmp(N a,N b){ return a.xaz>b.xaz; } signed main(){ int f=0,maxn=0,id; int n,m,a,b; cin >> n>>m>> a>>b; for(int i=1;i<=a;i++){ for(int j=1;j<=n;j++){ int x; scanf("%d",&x); l[j].xaz+=x; l[j].id=j; if(b==i){ if(maxn<x){ maxn=x; id=j; } } } } sort(l+1,l+n+1,cmp); for(int i=1;i<=m;i++){ if(l[i].id==id){ f=i; } } if(f){ cout << id<<' '; for(int i=1;i<=m;i++){ if(l[i].id!=id)cout <<l[i].id<<" "; } } else{ for(int j=1;j<m;j++){ cout <<l[j].id<<" "; } cout << id; } return 0; } ``` 后面的题我就没补完,希望大家自己写出来 ### 好了今天的总结就到此为止了,我们下次再见!!