赞
踩
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; int a[3][10]; int check() { for(int i=1;i<=3;i++) if(a[0][i]!=a[1][i]) return a[0][i]>a[1][i]; } int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { int x,y; scanf("%d%d",&x,&y); a[x][y]++; } printf("%d %d %d\n",a[0][1],a[0][2],a[0][3]); printf("%d %d %d\n",a[1][1],a[1][2],a[1][3]); if(check()) puts("The first win!"); else puts("The second win!"); return 0; }
#include <cstdio> #include <algorithm> #include <iostream> #include <map> using namespace std; string s[201]; map<string,string> s1,s2; int main() { int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { string x,y; cin>>x>>y; s1[x]=y; } for(auto a:s1) for(auto b:s1) { string c=a.first+b.first; string d=a.second+b.second; if(s2.find(c)==s2.end()) s2[c]=d; else s2[c]="D"; } for(int i=1;i<=m;i++) { string x; cin>>x; if(s1.find(x)!=s1.end()) cout<<s1[x]<<endl; else { if(s2.find(x)==s2.end()) cout<<"D"<<endl; else cout<<s2[x]<<endl; } } return 0; }
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <map> #include <queue> using namespace std; int num[10],a[20],b[20]; vector<int> p,v; int ans1=0,ans2=0; int levela; int gcd(int a,int b) { if(!b) return a; return gcd(b,a%b); } inline void pushin(int w[]) { v.clear(); for(int i=1;i<=5;i++) v.push_back(w[i]); sort(v.begin(),v.end()); } int check() { for(int i=1;i<=6;i++) num[i]=0; for(int i=0;i<=4;i++) num[v[i]]++; for(int i=1;i<=6;i++) if(num[i]==5) return 1; for(int i=1;i<=6;i++) if(num[i]==4) return 2; bool flag1=0,flag2=0; for(int i=1;i<=6;i++) { if(num[i]==2) flag1=1; if(num[i]==3) flag2=1; } if(flag1&&flag2) return 3; if(v[0]==2&&v[1]==3&&v[2]==4&&v[3]==5&&v[4]==6) return 4; if(v[0]==1&&v[1]==2&&v[2]==3&&v[3]==4&&v[4]==5) return 5; if(flag2) return 6; flag1=0,flag2=0; for(int i=1;i<=6;i++) { if(num[i]==2) { if(!flag1) flag1=1; else flag2=1; } } if(flag1&&flag2) return 7; if(flag1) return 8; return 9; } void dfs(int now) { if(now==p.size()) { ans2++; pushin(b); if(levela>check()) ans1++; return; } for(int i=1;i<=6;i++) { b[p[now]]=i; dfs(now+1); } } inline void work() { for(int i=1;i<=5;i++) { scanf("%d",&a[i]); } int p1=0,p2=0,p3=0; pushin(a); levela=check(); if(levela==1) { puts("0 0 1"); return; } for(int i=0;i<(1<<5);i++) { int cnt=0; p.clear(); for(int j=1;j<=5;j++) if(i&(1<<(j-1))) cnt++,p.push_back(j); ans1=0,ans2=0; for(int j=1;j<=5;j++) b[j]=a[j]; dfs(0); if(p1==0) { p1=cnt; p2=ans1,p3=ans2; } else { double s1=1.0*ans1/ans2; double s2=1.0*p2/p3; if(s1>s2) p1=cnt,p2=ans1,p3=ans2; if(s1==s2&&cnt<p1) p1=cnt,p2=ans1,p3=ans2; } } int t=gcd(p2,p3); printf("%d %d %d\n",p1,p2/t,p3/t); } int main() { int t; scanf("%d",&t); while(t--) work(); return 0; }
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <map> #include <queue> using namespace std; map<string,vector<string>> edge; map<string,bool> v; map<string,int> num; map<string,string> pre; vector<string> ss; int n; queue<string> dl; int bfs(string st,string ed) { while(!dl.empty()) dl.pop(); num.clear(); dl.push(st); while(!dl.empty()) { string now=dl.front(); dl.pop(); if(now==ed) return num[ed]; for(int i=0;i<edge[now].size();i++) { string p=edge[now][i]; if(num.find(p)!=num.end()) continue; pre[p]=now; num[p]=num[now]+1; dl.push(p); } } return -1; } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { string s1,s2,s3,s4; cin>>s1>>s2>>s3>>s4; edge[s1+" "+s2].push_back(s3+" "+s4); v[s1]=1,v[s3]=1; } string ans1="-1",ans2="-1"; int minx=0x7fffffff; for(auto it:v) { string st=it.first+" 0"; string ed=it.first+" 1"; int d1=bfs(st,ed),d2=bfs(ed,st); if(d1!=-1) { if(d1<minx) minx=d1,ans1=st,ans2=ed; } if(d2!=-1) { if(d2<minx) minx=d2,ans1=ed,ans2=st; } } bfs(ans1,ans2); string now=ans2; while(1) { ss.push_back(now); if(now==ans1) break; now=pre[now]; } reverse(ss.begin(),ss.end()); for(int i=0;i<ss.size();i++) { string p=ss[i]; cout<<p<<" "; if(i!=0&&i!=ss.size()-1) cout<<p<<" "; } cout<<"= "<<ans1<<" "<<ans2<<endl; return 0; }
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <map> #include <queue> #include <cstring> using namespace std; const int maxm=1e5+100; struct node{ int f1,f2; }a[maxm]; int r[maxm]; int dp[maxm][3]; void work() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d%d",&a[i].f1,&a[i].f2); } for(int i=1;i<=n;i++) { scanf("%d",&r[i]); dp[i][0]=dp[i][1]=dp[i][2]=1e6+100; } for(int i=1;i<=n;i++) { int pos1=1,pos2=1,pos3=1,pos4=1; int x=r[i]; if(a[x].f1==1&&a[x].f2==0) pos1=0; if(a[x].f1==1&&a[x].f2==1) pos2=0; if(a[x].f1==0&&a[x].f2==0) pos3=0; if(a[x].f1==0&&a[x].f2==1) pos4=0; dp[i][0]=dp[i-1][0]+pos1; dp[i][1]=min(dp[i-1][0],dp[i-1][1])+min(pos2,pos3); dp[i][2]=min(min(dp[i-1][0],dp[i-1][1]),dp[i-1][2])+pos4; } int ans=1e6+100; for(int i=0;i<=2;i++) ans=min(ans,dp[n][i]); printf("%d\n",ans); } int main() { int t; scanf("%d",&t); while(t--) work(); return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。