Codeforces Round #428
来源:互联网 发布:highcharts more.js 编辑:程序博客网 时间:2024/05/29 18:42
CF839A Arya and Bran(模拟)
#include <bits/stdc++.h>using namespace std;#define N 200010#define inf 0x3f3f3f3f inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f;}int n,k,remain,x;int main(){// freopen("a.in","r",stdin); n=read();k=read();remain=0; for(int i=1;i<=n;++i){ scanf("%d",&x);remain+=x; if(remain>=8) k-=8,remain-=8; else k-=remain,remain=0; if(k<=0){ printf("%d\n",i);return 0; } } puts("-1"); return 0;}
CF839B Game of the Rows(贪心)
比赛时漏了一种情况:两个人的一组也可以拆成两个1人,也就是说如果只剩四人座了,可以做三组2人。分清情况讨论即可:记x为本组人数
1.x>=3,有四人座先坐四人座,没四人座坐二人座,都没了则输出NO,这样之后每组人数都不会超过2人。
2.x==2,有两人座先坐两人座,没两人座坐四人座,注意此时还可以再带一个1人。都没了,只能拆成两个1人。
3.最后只剩一堆1人了,两人座能坐一个1人,四人座能坐两个1人,能坐下则输出YES,坐不下输出NO
#include <bits/stdc++.h>using namespace std;#define N 100010#define inf 0x3f3f3f3f inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f;}int n,m,seat[5],cnt[3];int main(){// freopen("a.in","r",stdin); n=read();m=read();seat[2]=n<<1;seat[4]=n; while(m--){ int x=read(); while(x>=3){ if(seat[4]) x-=4,seat[4]--; else if(seat[2]) x-=2,seat[2]--; else{puts("NO");return 0;} } if(x>0) cnt[x]++; } while(cnt[2]){ if(seat[2]) cnt[2]--,seat[2]--; else if(seat[4]) cnt[2]--,cnt[1]--,seat[4]--;//2人坐四人座,可以再捎一个1人 else cnt[1]+=2,cnt[2]--;//不能坐在一起,还能拆成2个1人 } if(cnt[1]<=seat[2]+seat[4]*2) puts("YES"); else puts("NO"); return 0;}
CF839C Journey(树+概率)
题目显然是给了我们一棵树,根为1。记根的深度为0,因为马只能往子节点走,所以答案显然就是每个叶子的深度*到达每个叶子的概率,记一下每个节点有几个儿子,用一遍dfs即可。
#include <bits/stdc++.h>using namespace std;#define N 100010#define inf 0x3f3f3f3f inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f;}struct edge{ int to,next;}data[N<<1];int n,h[N],size[N],num=0,fa[N];double ans=0;void dfs(int x,int dep,double p){ if(size[x]==1){ans+=(double)dep*p;return;} for(int i=h[x];i;i=data[i].next){ int y=data[i].to; if(y==fa[x]) continue; fa[y]=x;dfs(y,dep+1,p*1.0/(size[x]-1)); }}int main(){// freopen("a.in","r",stdin); n=read(); for(int i=1;i<n;++i){ int x=read(),y=read(); data[++num].to=y;data[num].next=h[x];h[x]=num; data[++num].to=x;data[num].next=h[y];h[y]=num; size[x]++;size[y]++; } for(int i=h[1];i;i=data[i].next) fa[data[i].to]=1,dfs(data[i].to,1,1.0/size[1]); printf("%.15lf",ans); return 0;}
阅读全文
0 0
- Codeforces Round #428
- Codeforces Round #428 D
- Codeforces Round #428
- Codeforces Round #428 (Div. 2)
- Codeforces Round #428 (Div. 2)
- Codeforces Round #428 (Div. 2)
- CodeForces round 428 div2 only
- Codeforces Round #428 (Div. 2)
- Codeforces Round #428 (Div. 2)
- 【codeforces】Codeforces Round #363
- Codeforces Round #428 (Div. 2)比赛总结
- Codeforces Round #428 (Div. 2)(A+B)
- Codeforces Round #428 (Div. 2) ABCD
- Codeforces Round #428 (Div 2) A
- Codeforces Round #428 (Div 2) B
- Codeforces Round #428 (Div 2) C
- Codeforces Round #428 (Div. 2) -ABC
- Codeforces Round 428 div2 A-C
- 学习笔记 AVL树
- IE下 jquery的fadeIn与fadeOut方法失效的BUG
- 1110. Complete Binary Tree (25)
- 度度熊回家 (模拟)
- 多线程阻塞类型
- Codeforces Round #428
- bzoj 1602: [Usaco2008 Oct]牧场行走(暴力LCA)
- python opencv入门 傅里叶变换(25)
- 代码REVIEW
- 怎样学习嵌入式Linux
- 实现判断商品折扣价格
- 工作中小细节总结(六)
- gabor
- LeetCode(五)387. First Unique Character in a String&409. Longest Palindrome