传送门:https://ac.nowcoder.com/acm/contest/12794
A Binarize It
大于等于这个数的最小二次方数
#include<bits/stdc++.h> using namespace std; #define N 10002 #define LL long long int n; LL a[N]; int main() { cin>>n; a[0]=1; for(int i=1;i<=22;i++) { a[i]=1<<i; } for(int i=1;i<=n;i++) { int x; cin>>x; LL ans=*lower_bound(a+1,a+22+1,x); printf("Input value: %d %d ",x,ans); } return 0; }
B g2g c u l8r
字符串中单词替换
唉 比赛时处理的不是很顺手
#include<bits/stdc++.h> using namespace std; int n,p; map<string,string>a; string s[22]; int main() { cin>>n; for(int i=1;i<=n;i++) { string s1,s2; cin>>s[i];getchar(); getline(cin,s2); a[s[i]]=s2; } int m; cin>>m;getchar(); for(int i=1;i<=m;i++) { string ss; getline(cin,ss); int len=ss.length(); string gg=""; for(int j=0;j<len;j++) { if(ss[j]!=' '&&j!=len-1) { gg.append(1,ss[j]); } if(j==len-1) { gg.append(1,ss[j]); if(a.find(gg)==a.end()) { cout<<gg<<endl; }else cout<<a[gg]<<endl; gg=""; } if(ss[j]==' ') { if(a.find(gg)==a.end()) { cout<<gg<<" "; }else cout<<a[gg]<<" "; gg=""; } } } return 0; }
C Tip to be Palindrome
输入n,求m,m>=0.2*n且m+n为最小的回文数
#include<bits/stdc++.h> using namespace std; int n; int ok(int x) { int sum=0; int m=x; while(x>0) { sum=sum*10+x%10; x=x/10; } return sum==m; } int main() { cin>>n; for(int i=1;i<=n;i++) { int p,xf; cin>>p; xf=ceil(1.*p*0.2); int gg=xf+p; for(int j=gg;;j++) { if(ok(j)) { printf("Input cost: %d %d %d ",p,j-p,j); break; } } } return 0; }
D Soccer Standings
模拟题 读懂题就好
cmp函数写错改了半天 这也太令人伤心了
#include<bits/stdc++.h> using namespace std; struct p { int points,wins,losses,draws,goalscor,goalal; int id; }a[33]; map<int,string>g; map<string,int>gg; bool cmp(p x,p y) { //if(x.points>y.points) if(x.points>y.points) return 1; else { if(x.points==y.points) { if((x.goalscor-x.goalal)>(y.goalscor-y.goalal)) return 1; else { if((x.goalscor-x.goalal)==(y.goalscor-y.goalal)) { if(x.goalscor>y.goalscor)return 1; else { if(x.goalscor==y.goalscor) { if(g[x.id]<g[y.id]) return 1; } } } } } } return x.points>y.points; } int main() { int T,js=0; cin>>T; while(T--) { int n,m; js++; cin>>n>>m; for(int i=1;i<=n;i++) { string s; cin>>s; g[i]=s; gg[s]=i; a[i].id=i; a[i].draws=a[i].goalal=a[i].goalscor=a[i].losses=a[i].wins=a[i].points=0; } for(int i=1;i<=m;i++) { string s1,s2; int c1,c2; cin>>s1>>c1>>s2>>c2; int id1=gg[s1]; int id2=gg[s2]; if(c1>c2) { a[id1].wins++; a[id1].points+=3; a[id1].goalscor+=c1; a[id1].goalal+=c2; a[id2].losses++; a[id2].goalal+=c1; a[id2].goalscor+=c2; } if(c1==c2) { a[id1].points++; a[id2].points++; a[id1].goalscor+=c1; a[id2].goalscor+=c2; a[id1].goalal+=c2; a[id2].goalal+=c1; a[id1].draws++; a[id2].draws++; } if(c1<c2) { a[id1].losses++; a[id2].wins++; a[id2].points+=3; a[id1].goalscor+=c1; a[id2].goalscor+=c2; a[id1].goalal+=c2; a[id2].goalal+=c1; } } sort(a+1,a+n+1,cmp); printf("Group %d: ",js); for(int i=1;i<=n;i++) { int idd=a[i].id; cout<<g[idd]<<" "<<a[i].points<<" "<<a[i].wins<<" "<<a[i].losses<<" "<<a[i].draws<<" "<<a[i].goalscor<<" "<<a[i].goalal<<endl; } cout<<endl; } return 0; }
E NIH Budget
分组背包
#include<bits/stdc++.h> using namespace std; #define N 100002 int dp[N]; int js; struct p { int w,v; }a[N]; int main() { int T; cin>>T; while(T--) { js++; vector<int>ve[11]; int n,m,cnt=0; cin>>n>>m; memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) { for(int j=1;j<=4;j++) { int x,y; cin>>x>>y; a[++cnt].w=x; a[cnt].v=y; ve[i].push_back(cnt); } } for(int i=1;i<=n;i++) { for(int j=m;j>=0;j--) { for(int k=0;k<4;k++) { int x=ve[i][k]; if(j>=a[x].w) dp[j]=max(dp[j],dp[j-a[x].w]+a[x].v); } } } printf("Budget #%d: Maximum of %d lives saved. ", js,dp[m]); } return 0; }
F Interstellar Love
图论 找环
#include<bits/stdc++.h> using namespace std; #define N 1002 #define M 10002 int vis[N]; int head[N]; int sumedge; bool yes_,has_; int js=0; struct Edge { int x,y,nxt; Edge(int x=0,int y=0,int nxt=0): x(x),y(y),nxt(nxt){} }edge[M<<1]; void add(int x,int y) { edge[++sumedge]=Edge(x,y,head[x]); head[x]=sumedge; } void Init() { sumedge=0; memset(vis,0,sizeof(vis)); memset(head,0,sizeof(head)); } void dfs(int now,int fa) { vis[now]=1;js++; // cout<<now<<endl; for(int i=head[now];i;i=edge[i].nxt) { int v=edge[i].y; if(v==fa) continue; if(vis[v]) has_=1; if(!vis[v]) { dfs(v,now); } } return ; } int main() { int T,cnt=0; cin>>T; while(T--) { cnt++; int n,m; int ans1=0,ans2=0; cin>>n>>m; Init(); for(int i=1;i<=m;i++) { int x,y; cin>>x>>y; add(x,y); add(y,x); } for(int i=1;i<=n;i++) { if(!vis[i]) { dfs(i,-1); if(js>1) { ans1++; if(has_) { ans2++; } } js=has_=0; } } printf("Night sky #%d: %d constellations, of which %d need to be fixed. ",cnt,ans1,ans2); } return 0; }
G Plate Spinning
分析问题发现是
比较2.5*n与p的大小 注意特判
唉 我读错题了
#include<bits/stdc++.h> using namespace std; int t; int main() { cin>>t; for(int i=1;i<=t;i++) { int n,p; cin>>n>>p; printf("Circus Act %d: ",i); if(n==1||2*p>=5*n) printf("Chester can do it! "); else printf("Chester will fail! "); } return 0; }