Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) A.B.C
2017-03-07 14:49
399 查看
A. Andryusha and Socks
思路:模拟即可
B. The Meeting Place Cannot Be Changed
思路:二分搜索,如果时间t可以满足所有人到达同一个点,则检查t/2是否也可以,然后根据题目要求精度达到1e-7退出
C. Andryusha and Colored Balloons
思路:树上dfs,每个节点的颜色是不和父亲节点和祖父亲节点相同的最小的未使用颜色。
思路:模拟即可
#include<bits/stdc++.h> using namespace std; const int maxn=1e5+10; bool vis[maxn]; int main(){ int n; scanf("%d",&n); memset(vis,false,sizeof(vis)); int now=0,maxx=0; for(int i=0;i<2*n;i++){ int temp; scanf("%d",&temp); if(!vis[temp]){ now+=1; vis[temp]=true; }else{ now-=1; } if(now>maxx) maxx=now; } printf("%d",maxx); }
B. The Meeting Place Cannot Be Changed
思路:二分搜索,如果时间t可以满足所有人到达同一个点,则检查t/2是否也可以,然后根据题目要求精度达到1e-7退出
#include<bits/stdc++.h> using namespace std; const int maxn=60000+10; struct p{ int dis,v; }; p per[maxn]; int n; int md,sd; double s; double eps=1e-7; bool check(double t){ double a,b; for(int i=1;i<=n;i++){ double x=(double)per[i].dis-(double)per[i].v*t; double y=(double)per[i].dis+(double)per[i].v*t; if(i==1){ a=x,b=y; }else{ if(a>y || b<x) return false; if(a<=x) a=x; if(b>=y) b=y; } } return true; } int main(){ scanf("%d",&n); md=-1,sd=0x3f3f3f3f; for(int i=1;i<=n;i++){ scanf("%d",&per[i].dis); if(per[i].dis>md) md=per[i].dis; if(per[i].dis<sd) sd=per[i].dis; } for(int i=1;i<=n;i++){ scanf("%d",&per[i].v); } double l,r,ans; l=0,r=1e9; while(r-l>=eps){ double mid=(l+r)/2; if(check(mid)){ ans=mid; r=mid; }else l=mid; } printf("%.7f",ans); }
C. Andryusha and Colored Balloons
思路:树上dfs,每个节点的颜色是不和父亲节点和祖父亲节点相同的最小的未使用颜色。
#include<bits/stdc++.h> using namespace std; const int maxn=2*1e5+10; vector<int>E[maxn]; int n; int ans[maxn]; int fa[maxn]; set<int>sum; void dfs(int now){ int cnt=1; for(int i=0;i<E[now].size();i++){ int p=E[now][i]; if(p!=fa[now]){ while(cnt==ans[now] || cnt==ans[fa[now]]) cnt++; ans[p]=cnt; sum.insert(cnt); fa[p]=now; dfs(p); cnt++; } } } int main(){ scanf("%d",&n); for(int i=1;i<n;i++){ int a,b; scanf("%d%d",&a,&b); E[a].push_back(b); E[b].push_back(a); } ans[1]=1; fa[1]=1; dfs(1); sum.insert(1); printf("%d\n",sum.size()); for(int i=1;i<=n;i++) printf("%d ",ans[i]); }
相关文章推荐
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)A,B,C
- 【解题报告】Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)
- [Updating]Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)解题报告
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B.(三分)
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C (dfs+vector)
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals )D. Innokenty and a Football League(2-sat)
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B.(三分)
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) A. Andryusha and Socks
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed
- Codeforces Round #403 (Div. 1, based on Technocup 2017 Finals) A. Andryusha and Colored Balloons
- 【三分】Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C Andryusha and Colored Balloons
- 【贪心】【DFS】Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C. Andryusha and Colored Balloons
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)【A,B,C】
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)A模拟 B三分 C dfs D map
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals
- 【2-SAT】Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League
- Codeforces Round #403 (Div. 1, based on Technocup 2017 Finals)