Codeforces Round #428 (Div. 2)
终于上蓝名了,hahahahaha,虽然这场的 B 题因为脑抽了,少考虑一种情况终判错了,还是很可惜的。。
B题本来过来1500个人,终判之后只剩下了200多个,真的有毒!!!!
题目大意:你需要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 ;
}
题目大意:有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 ;
}
题目大意:给你一颗树,有一个球从 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)的更多相关文章
- CodeForces 839C - Journey | Codeforces Round #428 (Div. 2)
起初误以为到每个叶子的概率一样于是.... /* CodeForces 839C - Journey [ DFS,期望 ] | Codeforces Round #428 (Div. 2) */ #i ...
- CodeForces 839D - Winter is here | Codeforces Round #428 (Div. 2)
赛后听 Forever97 讲的思路,强的一匹- - /* CodeForces 839D - Winter is here [ 数论,容斥 ] | Codeforces Round #428 (Di ...
- 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 ...
- Codeforces Round #428 (Div. 2) 题解
题目链接:http://codeforces.com/contest/839 A. Arya and Bran 题意:每天给你一点糖果,如果大于8个,就只能给8个,剩下的可以存起来,小于8个就可以全部 ...
- 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 ...
- Codeforces Round #428 (Div. 2)E. Mother of Dragons
http://codeforces.com/contest/839/problem/E 最大团裸题= =,用Bron–Kerbosch算法,复杂度大多博客上没有,维基上查了查大约是O(3n/3) 最大 ...
- 【Codeforces Round #428 (Div. 2) B】Game of the Rows
[Link]:http://codeforces.com/contest/839/problem/B [Description] 给你n排的如题目所示的位置; 同一排中(1,2) 算相邻; (3,4) ...
- 【Codeforces Round #428 (Div. 2) C】Journey
[Link]:http://codeforces.com/contest/839/problem/C [Description] 给一棵树,每当你到一个点x的时候,你进入x的另外一每一个出度的概率都是 ...
- 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 ...
随机推荐
- Linux下安装mysql(示例mysql5.6安装)
1.首先检查你的linux上是否已经安装了mysql rpm -qa|grep mysql 2.如果mysql的版本不是想要的版本.需要把mysql卸载 yum remove mysql mysql- ...
- 10 SpringBoot全面接管SpringMVC
Spring Boot官方文档描述 If you want to keep Spring Boot MVC features and you want to add additional MVC co ...
- ping不同网站总结
用高级设置法预防Ping 用网络防火墙阻隔Ping 启用IP安全策略防Ping IP安全机制(IP Security)即IPSec策略,用来配置IPSec安全服务.这些策略可为多数现有网络中地多数通信 ...
- JavaScript之JS单线程|事件循环|事件队列|执行栈
本博文基于知乎"JavaScript作用域问题?"一问,而引起了对JavaScript事件循环和单线程等概念与实践上的研究.深入理解. 一.概念 0.关键词:JavaScript单 ...
- 最新Linux系统Ubuntu16.04搭建HUSTOJ(LAMP环境)
应该跟着下面的步骤就OK了吧! 1.升级软件库,更新软件 打开终端 输入 sudo apt-get update sudo apt-get upgrade 2.安装mysql5.7 (注意:mysql ...
- Sqoop异常:Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
18/12/07 01:09:03 INFO mapreduce.ImportJobBase: Beginning import of staffException in thread "m ...
- C#的五种访问修饰符
简述: 所有类型和类型成员都具有可访问性级别,用来控制是否可以在您程序集的其他代码中或其他程序集中使用它们. 可使用访问修饰符指定声明类型或成员的可访问性. 在C#语言中,共有五种访问修饰符:publ ...
- npm 无法安装 ionic 解决办法
一般从 node.js官网下载安装完之后,npm也会同时安装完. 如果通过 $ npm install -g cordova ionic 去安装,往往会失败.这个是由于GFW,很多插件下载不下来,还好 ...
- MyEclipse2017 CI-7的破解
下载了一个最新版的MyEclipse,网上下载了破解工具,按照步骤完成后破解失败.很纳闷,于是网上查看,说是破解器的版本须与MyEclipse的版本对应,不对应的话,是没有效果的.如我的是CI-7版本 ...
- ubuntu数据库迁移
环境:ubuntu16.04 简介:本教程演示如何从旧数据库服务器服转移到另一个新服务器. 场景:假设你有自己的云服务器安装了WordPress站点,你为了更多的内存和处理能力想升级到新的服务器. 操 ...