A-暴力模拟
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include <bits/stdc++.h> using namespace std; typedef long long ll; string day[]={"Monday","Tuesday","Wednesday","Thursday","Friday"}; int t; ll y11,m1,d1,y2,m2,d2; string s1; int main(){ cin>>t; while(t--){ cin>>y11>>m1>>d1; cin>>s1; cin>>y2>>m2>>d2; ll ans1=y11*360+(m1-1)*30+d1; ll ans2=y2*360+(m2-1)*30+d2; int tt=0; for(int i=0;i<=4;i++){ if(s1==day[i]){ tt=i; break; } } if(ans1>=ans2){ ans1-=ans2; ans1%=5; cout<<day[(tt-ans1+5)%5]<<endl; }else{ ans2-=ans1; ans2%=5; cout<<day[(tt+ans2)%5]<<endl; } } return 0; }
B-dp+组合数
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include<bits/stdc++.h> typedef long long ll; using namespace std; const ll mod=998244353; const int maxn=110; int n,k,m,t; char st[maxn],ed[maxn]; ll dp[maxn][maxn]; ll C[maxn][maxn]; void init(){ C[0][0]=1; for(int i=1;i<=105;i++){ C[i][0]=C[i][i]=1; for(int j=1;j<i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod; } } int main(){ init(); scanf("%d",&t); while(t--){ scanf("%d%d%d",&n,&k,&m); scanf("%s",st+1);scanf("%s",ed+1); memset(dp,0,sizeof(dp)); int s=0; for(int i=1;i<=n;i++){ if(st[i]!=ed[i]) s++; } dp[0][s]=1; for(int i=0;i<k;i++){ for(int j=0;j<=n;j++){ if(dp[i][j]==0) continue; for(int kk=0;kk<=j;kk++){ //DAODA int k2=m-kk;// bu dao da if(k2>(n-j)) continue; if(k2<0) continue; dp[i+1][(j-kk)+k2]=(dp[i+1][(j-kk)+k2]+dp[i][j]*C[j][kk]%mod*C[n-j][k2]%mod)%mod; } } } printf("%lld\n",dp[k][0]); } return 0; }
C-傻逼题
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include<bits/stdc++.h> using namespace std; #define maxn 100005 #define ll long long ll t,x,y,n,k,ans; char s[maxn]; int main(){ cin>>t; while(t--){ ans=x=y=0; cin>>n>>k; scanf("%s",s); int len=strlen(s); for(int i=0;i<len;i++){ if(s[i]=='R')x++; if(s[i]=='L')x--; if(s[i]=='U')y++; if(s[i]=='D')y--; ans=max(ans,abs(x)+abs(y)); } x*=(k-1);y*=(k-1); ans=max(ans,abs(x)+abs(y)); for(int i=0;i<len;i++){ if(s[i]=='R')x++; if(s[i]=='L')x--; if(s[i]=='U')y++; if(s[i]=='D')y--; ans=max(ans,abs(x)+abs(y)); } cout<<ans<<endl; } }
D-简单图论
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include<bits/stdc++.h> using namespace std; #define ll long long ll n,k,m; char s[200005]; int main(){ int t; cin>>t; while(t--){ cin>>k; scanf("%s",s); cin>>n>>m; for(int i=1;i<=m;i++){ int u,v; scanf("%d%d",&u,&v); } ll tot=(m-n+1)%k; cout<<3-(s[tot]-'0')<<endl; } }
F-贪心
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include<bits/stdc++.h> using namespace std; #define ll long long int n,a[100005]; int main(){ int t;cin>>t; while(t--){ cin>>n;ll sum=0; for(int i=1;i<=n;i++)scanf("%d",&a[i]); for(int i=1;i<=n;i++) sum+=a[i]; ll p=sum%n,q=sum/n,ans=p; for(int i=1;i<=n;i++) if(a[i]<q)ans+=(q-a[i]); cout<<ans<<endl; } }
H-贪心
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include<bits/stdc++.h> #include<queue> #define maxn 100005 using namespace std; struct Node{ int l,r; bool operator<(Node a)const {return r>a.r;} }p[maxn]; int cmp(Node a,Node b){ if(a.l==b.r)return a.r<b.r; return a.l<b.l; } priority_queue<Node>pq; int t,n,m; int main(){ cin>>t; while(t--){ cin>>n; for(int i=1;i<=n;i++)scanf("%d%d",&p[i].l,&p[i].r); sort(p+1,p+1+n,cmp); while(!pq.empty())pq.pop(); // pq.push(p[1]); int id=1,ans=0,pos=p[1].l; while(id<=n){//把所有包含pos的线段加入pq,移动pos if(id>n)break; else pos=p[id].l; while(id<=n && pos<=p[id].r && pos>=p[id].l){ pq.push(p[id++]); } while(pq.size() && pos<p[id].l){ if(pos<=pq.top().r)ans++,pos++; pq.pop(); } } while(pq.size()){ if(pos<=pq.top().r)ans++,pos++; pq.pop(); } cout<<ans<<endl; } }
L-拓扑排序
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include <bits/stdc++.h> using namespace std; #define pb push_back #define clr(a,b) memset(a,b,sizeof(a)) #define REP(i,s,t) for(int i=s;i<=t;i++) const int N = 110; vector<int>G1[N],G2[N]; bool fp; int n,m,cnt1,cnt2; int in[N],vis[N]; inline void init(){ fp=false; REP(i,0,n)G1[i].clear(); REP(i,0,n)G2[i].clear(); clr(in,0); } inline void Toposort(){ queue<int>q; REP(i,1,n) if(in[i]==0){ q.push(i); } int num=0; while(!q.empty()){ int u=q.front();q.pop(); num++; for(int i=0;i<G1[u].size();i++){ int v=G1[u][i]; in[v]--; if(in[v]==0)q.push(v); } } if(num<n)fp=true; } void dfs1(int u){ vis[u]=1; for(int i=0;i<G1[u].size();i++){ int v=G1[u][i]; if(!vis[v]){ cnt1++,dfs1(v); //将其正向能够达到的点全部标记 } } } void dfs2(int u){ vis[u]=1; for(int i=0;i<G2[u].size();i++){ int v=G2[u][i]; if(!vis[v]){ cnt2++,dfs2(v); } } } int main(){ int T;cin>>T; while(T--){ init(); scanf("%d%d",&n,&m); REP(i,1,m){ int u,v;scanf("%d%d",&u,&v); G1[u].pb(v);G2[v].pb(u); in[v]++; if(u==v)fp=true; } Toposort(); if(fp){ REP(i,1,n)printf("0"); puts(""); }else{ REP(i,1,n){ cnt1=cnt2=0; clr(vis,0);dfs1(i); clr(vis,0);dfs2(i); //printf("cnt1=%d,cnt2=%d\n",cnt1,cnt2); if(cnt1<=n/2 && cnt2<=n/2){ printf("1"); }else printf("0"); } puts(""); } // if(T)printf(" "); // else puts(""); } }