本场I题出锅,还有一题没有意义的转盘子毒瘤题
-----------------------------------------------------
J-Lowest Common Ancestor
#include<bits/stdc++.h> #define inf 1e18 #define ll long long #define MAX 1000001 const ll N = 2e5+7; const ll mod = 1e9+7; using namespace std; string d[]={"0","1","10","11","100","101","110","111","1000","1001","1010","1011","1100","1101","1110","1111"}; string dd[]={"0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"}; map<string,string>mp; string did(string s){ string q=""; for(int i=0;i<s.length();++i){ char now=s[i];int p; if('0'<=now&&now<='9') p=now-'0'; else p=now-'a'+10; if(i==0) q+=d[p]; else q+=dd[p]; } return q; } string pip(string s){ string q=""; while(s.length()%4!=0) s="0"+s; for(int i=0;i<s.length();i+=4){ q=q+mp[s.substr(i,4)]; } return q; } int main(){ mp["0000"]="0"; mp["0001"]="1"; mp["0010"]="2"; mp["0011"]="3"; mp["0100"]="4"; mp["0101"]="5"; mp["0110"]="6"; mp["0111"]="7"; mp["1000"]="8"; mp["1001"]="9"; mp["1010"]="a"; mp["1011"]="b"; mp["1100"]="c"; mp["1101"]="d"; mp["1110"]="e"; mp["1111"]="f"; int t;scanf("%d",&t); for(int _=1;_<=t;++_){ printf("Case #%d: ",_); string s1,s2,t1,t2,ans=""; cin>>s1>>s2; t1=did(s1);t2=did(s2); int len=min(t1.length(),t2.length()); for(int i=0;i<len;++i){ if(t1[i]==t2[i]) ans+=t1[i]; else break; } ans=pip(ans); cout<<ans<<" "; } return 0; }
F-Interstellar Love
#include<bits/stdc++.h> #define inf 1e18 #define ll long long #define MAX 1000001 const ll N = 2e5+7; const ll mod = 1e9+7; using namespace std; int fa[N],d[N],vis[N]; int find(int x){ return fa[x]==x?x:fa[x]=find(fa[x]); } int main(){ int t;scanf("%d",&t); for(int _=1;_<=t;++_){ int cnt=0,n,m; printf("Night sky #%d:",_); scanf("%d%d",&n,&m); for(int i=1;i<=n;++i) fa[i]=i,d[i]=0,vis[i]=0; for(int i=1;i<=m;++i){ int u,v; scanf("%d%d",&u,&v); d[u]++;d[v]++; u=find(u);v=find(v); if(u==v) vis[u]=1; else fa[u]=v,vis[v]|=vis[u]; } int ans=0; for(int i=1;i<=n;++i) if(find(i)==i&&d[i]!=0){ ans++;if(vis[i]) cnt++; } printf(" %d constellations, of which %d need to be fixed. ",ans,cnt); } return 0; } //不是环的个数而是需要修复星座的个数
D-Soccer Standings
#include<bits/stdc++.h> #define inf 0x3f3f3f3f #define MAX 1000001 #define inf 0x3f3f3f3f #define ll long long #define MAX 1000001 const ll N = 2e5+7; const ll mod = 1e9+7; using namespace std; struct node{ string name; int point; int win; int loss; int draw; int goalget; int goalall; int diff; }a[50]; map<string,int>mp; int cmp(node x,node y){ if(x.point==y.point){ if(x.diff==y.diff){ if(x.goalget==y.goalget){ return x.name<y.name; } else{ return x.goalget>y.goalget; } } else{ return x.diff>y.diff; } } else{ return x.point>y.point; } } int main(){ int t;scanf("%d",&t); for (int cas=1;cas<=t;cas++){ printf("Group %d: ",cas); mp.clear(); int n,g; scanf("%d%d",&n,&g); for(int i=1;i<=n;++i){ string s;cin>>s; mp[s]=i; a[i].name=s; a[i].diff=a[i].draw=a[i].win=a[i].point=a[i].goalget=a[i].loss=a[i].goalall=0; } for(int i=1;i<=g;++i){ string n1,n2;int s1,s2; cin>>n1>>s1>>n2>>s2; int num1=mp[n1],num2=mp[n2]; a[num1].goalget+=s1; a[num1].goalall+=s2; a[num2].goalget+=s2; a[num2].goalall+=s1; if(s1>s2){ a[num1].point+=3; a[num1].win++; a[num2].loss++; } else if(s1<s2){ a[num2].point+=3; a[num2].win++; a[num1].loss++; } else{ a[num1].point++; a[num2].point++; a[num1].draw++; a[num2].draw++; } } for(int i=1;i<=n;++i){ a[i].diff=a[i].goalget-a[i].goalall; } sort(a+1,a+1+n,cmp); for(int i=1;i<=n;++i){ cout<<a[i].name; printf(" %d %d %d %d %d %d ",a[i].point,a[i].win,a[i].loss,a[i].draw,a[i].goalget,a[i].goalall); } printf(" "); } return 0; }