终于上蓝名了,hahahahaha,虽然这场的 B 题因为脑抽了,少考虑一种情况终判错了,还是很可惜的。。

B题本来过来1500个人,终判之后只剩下了200多个,真的有毒!!!!

A - Arya and Bran

题目大意:你需要k个糖果,你每天最多拿8个,有n天,每天提供你a[ i ]个糖果,如果糖果大于8个多出来的

可以储存下来,问你能不能在n天内拿到k个糖果。

思路:模拟就行了。

#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[];
int main()
{
cin>>n>>k;
int sum=;
for(int i=;i<=n;i++) scanf("%d",&a[i]),sum+=a[i];
if(sum<k)
{
puts("-1");
return ;
}
int ans=;
int now=,res=;
while(ans<k)
{
if(now>n)
{
puts("-1");
return ;
}
if(a[now]<=)
{
ans+=a[now];
int p=-a[now];
if(p<=res)
{
ans+=p;
res-=p;
}
else
{
ans+=res;
res=;
}
}
else
{
ans+=;
res+=a[now]-;
}
if(ans>=k) break;
now++;
}
cout<<now<<endl;
return ;
}

B - Game of the Rows

题目大意:有n艘船,每艘船有8个位置,一种两个两连坐,一个四连坐。现在又k个团,分别有a[ i ]个士兵,

要求不同团的士兵不是坐相邻的位置,问你能不能将所有士兵安排到船上。

这确实是个毒题。

思路:看到题目就想到肯定是贪心,我们的首要目标就是要空着的位置尽可能地少,而且四连坐如果坐满

肯定都是一个团的,那么我们先将四连坐能坐满的全部坐满,坐不满的我们就将四连坐分成一个两连坐

和一个单个座位,再用两连坐和单个座位模拟就简单多了,但是我注意了单个座位用完用两连坐代替,

却忘了两连坐用完也能用单个座位代替,GGGGGGG。

#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[];
int main()
{
cin>>n>>k;
int c1=n*,c2=n,c3=;
for(int i=;i<=k;i++) scanf("%d",&a[i]);
for(int i=;i<=k;i++)
{
int w=a[i]/;
if(c2>=w)
{
c2-=w;
a[i]-=w*;
}
}
c1+=c2;
c3+=c2;
for(int i=;i<=k;i++)
{
if(a[i])
{
if(a[i]&)
{
if(c3) c3--;
else c1--;
}
int w=a[i]/;
if(c1>=w) c1-=w;
else c3-=;
if(c3<) //这里GG了
{
puts("NO");
return ;
}
}
//cout<<c1<<endl;
}
puts("YES");
return ;
}

C - Journey

题目大意:给你一颗树,有一个球从 1 好节点还是等概率地向他的子节点转移,如果没有子节点了则停止,

问你球通过的路径长度的期望是多少。(从一个节点转移到其子节点的长度为 1 )。

思路:刚开始以为每一条路都是等概率地错了一发,直接 dfs 每一条路到底将期望加上去。

#include<bits/stdc++.h>
using namespace std;
const int N=;
vector<int> e[N];
int vis[N],sum,len[N];
double ans;
void dfs(int u,int pre,int l,double p)
{
bool flag=false;
for(int i=;i<len[u];i++)
{
int to=e[u][i];
if(to!=pre)
{
flag=true;
if(pre==-) dfs(to,u,l+,p/len[u]);
else dfs(to,u,l+,p/(len[u]-));
}
}
if(!flag)
{
//cout<<u<<endl;
//cout<<p<<endl;
ans+=p*l;
}
}
int main()
{
int n;
cin>>n;
ans=;
for(int i=;i<n;i++)
{
int f,t;
scanf("%d%d",&f,&t);
e[f].push_back(t);
e[t].push_back(f);
len[f]++;
len[t]++;
}
dfs(,-,,);
printf("%.12f\n",ans);
return ;
}

Codeforces Round #428 (Div. 2)的更多相关文章

  1. CodeForces 839C - Journey | Codeforces Round #428 (Div. 2)

    起初误以为到每个叶子的概率一样于是.... /* CodeForces 839C - Journey [ DFS,期望 ] | Codeforces Round #428 (Div. 2) */ #i ...

  2. CodeForces 839D - Winter is here | Codeforces Round #428 (Div. 2)

    赛后听 Forever97 讲的思路,强的一匹- - /* CodeForces 839D - Winter is here [ 数论,容斥 ] | Codeforces Round #428 (Di ...

  3. CodeForces 839B - Game of the Rows | Codeforces Round #428 (Div. 2)

    血崩- - /* CodeForces 839B - Game of the Rows [ 贪心,分类讨论] | Codeforces Round #428 (Div. 2) 注意 2 7 2 2 2 ...

  4. Codeforces Round #428 (Div. 2) 题解

    题目链接:http://codeforces.com/contest/839 A. Arya and Bran 题意:每天给你一点糖果,如果大于8个,就只能给8个,剩下的可以存起来,小于8个就可以全部 ...

  5. Codeforces Round #428 (Div. 2) D. Winter is here 容斥

    D. Winter is here 题目连接: http://codeforces.com/contest/839/problem/D Description Winter is here at th ...

  6. Codeforces Round #428 (Div. 2)E. Mother of Dragons

    http://codeforces.com/contest/839/problem/E 最大团裸题= =,用Bron–Kerbosch算法,复杂度大多博客上没有,维基上查了查大约是O(3n/3) 最大 ...

  7. 【Codeforces Round #428 (Div. 2) B】Game of the Rows

    [Link]:http://codeforces.com/contest/839/problem/B [Description] 给你n排的如题目所示的位置; 同一排中(1,2) 算相邻; (3,4) ...

  8. 【Codeforces Round #428 (Div. 2) C】Journey

    [Link]:http://codeforces.com/contest/839/problem/C [Description] 给一棵树,每当你到一个点x的时候,你进入x的另外一每一个出度的概率都是 ...

  9. Codeforces Round #428 (Div. 2)A,B,C

    A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. python 多线程中子线程和主线程相互通信

    主线程开启多个线程去干活,每个线程需要完成的时间不同,干完活以后都要通知给主线程,下面代码说明该应用: 代码块: import threading import queue import time i ...

  2. MySQL备份可能遇到的坑

    MySQL备份工具,支持各种参数选项,使用不同的选项极有可能影响备份处理过程.本文使用我们常规认为合理的备份参数,测试/验证是否存在容易忽视的坑 # 常规备份参数 # mysqldump shell& ...

  3. 用Quartz 2D画小黄人

    第一步: 先创建一个OneView类,并在storyboard里边拖拽一个UIview,将这个UIview的类改成OneView.如图所示: 第二步: 在新创建的Oneview里,补齐下列代码: // ...

  4. Python算法:推导、递归和规约

    Python算法:推导.递归和规约 注:本节中我给定下面三个重要词汇的中文翻译分别是:Induction(推导).Recursion(递归)和Reduction(规约) 本节主要介绍算法设计的三个核心 ...

  5. 【vim】按时间回退文本 :earlier 1m

    Vim 会记录文件的更改,你很容易可以回退到之前某个时间.该命令是相当直观的.比如: :earlier 1m 会把文件回退到 1 分钟以前的状态. 注意,你可以使用下面的命令进行相反的转换: :lat ...

  6. Linux驱动技术(三) _DMA编程【转】

    转自:https://www.cnblogs.com/xiaojiang1025/archive/2017/02/11/6389194.html DMA即Direct Memory Access,是一 ...

  7. centos系统初始化脚本

    #!/bin/bash #检测是否为root用户 ];then echo "Must be root can do this." exit fi #检测网络 echo " ...

  8. centos6.5下系统编译定制iptables防火墙扩展layer7应用层访问控制功能及应用限制QQ2016上网

    iptables防火墙扩展之layer7应用层访问控制 概述: iptables防火墙是工作在网络层,针对TCP/IP数据包实施过滤和限制,属于典型的包过滤防火墙.以基于网络层的数据包过滤机制为主,同 ...

  9. Dubbo入门---搭建一个最简单的Demo框架

    参考文档: https://blog.csdn.net/noaman_wgs/article/details/70214612/

  10. 1、Appium安装

    1.安装node.js 访问node js官网 https://nodejs.org/en/ 下载并安装node js,找到你系统适合的node js一步步安装即可 2.安装Appium 在cmd中执 ...