2019.5.23 组队赛 2019山东省赛复现
根据题意可知,每月30天,每周5天,也就是说每年也是5的倍数。因此,只要确定一个月的一天是周几,就可以得出所有的答案。按照和他相差的天数取余,然后就可以得到。
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN=1e5+10; map<int,string> mp; int main(){ ll n; cin>>n; while(n--){ int year,month,day; string we; cin>> year>>month>>day>>we; int year2,month2,day2; cin>>year2>>month2>>day2; int tmp = (day2-day)%5; mp[0]="Friday"; mp[1]="Monday"; mp[2]="Tuesday"; mp[3]="Wednesday"; mp[4]="Thursday"; if(we=="Monday"){ tmp++; } if(we=="Tuesday"){ tmp+=2; } if(we=="Wednesday"){ tmp+=3; } if(we=="Thursday"){ tmp+=4; } if(we=="Friday"){ tmp+=5; } tmp=(tmp+5)%5; cout<<mp[tmp]<<endl; } return 0; }
D - Game on a Graph
ZOJ - 4116
做得时候忘记取余。
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN=1e5+10; map<int,string> mp; ll t,n,N,M; char a[MAXN]; int main(){ cin>>n; while(n--){ cin>>t; for(int i =0;i<t;i++) cin>>a[i]; cin>>N>>M; for(int i =1;i<=M;i++){ int qq,ww; cin>>qq>>ww; } if(a[(M-N+1)%t]=='1') cout<<"2"<<endl; else cout<<"1"<<endl; } return 0; }
C - Wandering Robot
ZOJ - 4115
注意第一次遍历也会有最大值。
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN=1e5+10; map<int,string> mp; int main(){ ll n; cin>>n; while(n--){ ll N,M; cin>>N>>M; string ss; cin>>ss; ll x=0,y=0,len=0; for(int i =0;i<ss.length();i++){ if(ss[i]=='R'){ x++; } else if(ss[i]=='L'){ x--; } else if(ss[i]=='U'){ y++; } else if(ss[i]=='D'){ y--; } len=max(len,abs(x)+abs(y)); } x=x*(M-1);y=y*(M-1); len=max(len,abs(x)+abs(y)); for(int i =0;i<ss.length();i++){ if(ss[i]=='R'){ x++; } else if(ss[i]=='L'){ x--; } else if(ss[i]=='U'){ y++; } else if(ss[i]=='D'){ y--; } len=max(len,abs(x)+abs(y)); } cout<<len<<endl; } return 0; }
L - Median
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN=1e5+10; map<int,string> mp; ll t,n,m,flag; int a[107][107],big[107],les[107]; void Floyd(){//该函数将所有得元素链接起来,判断两个元素中间是否有元素。 for(int k =1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) a[i][j]=a[i][j]||(a[i][k]&&a[k][j]); } int main(){ cin>>t; while(t--){ cin>>n>>m; memset(a,0,sizeof(a)); for(int i =1;i<=n;i++) big[i]=0; for(int i =1;i<=n;i++) les[i]=0; for(int i =1;i<=m;i++){ int t1,t2; cin>>t1>>t2; a[t1][t2]=1; } Floyd(); flag=0; for(int i =1;i<=n;i++){ for(int j =1;j<=n;j++){ if(a[i][j]&&a[j][i]){ flag=1; break; } } } if(flag){ for(int i =1;i<=n;i++) cout<<"0"; cout<<endl; continue; } for(int i =1;i<=n;i++){ for(int j=1;j<=n;j++){ if(i!=j&&a[i][j]){ // cout<<i<<" "<<j<<a[i][j]<<endl; big[i]++; les[j]++; } } } for(int i =1;i<=n;i++){ // cout<<big[i]<<" "<<les[i]<<endl; } for(int i =1;i<=n;i++){ if(big[i]>n/2||les[i]>n/2){ cout<<"0"; } else cout<<"1"; } cout<<endl; } return 0; }

浙公网安备 33010602011771号