终于上蓝名了,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. Java之Jacob调用COM接口DLL-----------------------------------dm。dll

    用Java控制windows了,嗯,低层次按键模拟,可控制游戏,内存也不在话下. 一.环境介绍 1.myeclipse8.5 2.著名按键插件dm.dll  32bit.此插件实现COM接口,百度百科 ...

  2. MyBatis全局配置文件mybatis-config.xml

    1.在官方下载的mybatis-3.4.5.zip压缩包中,有我们需要的mybatis核心jar包和mybatis的快速入门的pdf文件 在mybatis的快速入门的pdf文件中,复制如下代码到我们项 ...

  3. POJ2516 Minimum Cost【最小费用最大流】

    题意: 有N个客户,M个仓库,和K种货物.已知每个客户需要每种货物的数量,每个仓库存储每种货物的数量,每个仓库运输各种货物去各个客户的单位费用.判断所有的仓库能否满足所有客户的需求,如果可以,求出最少 ...

  4. Git查看单个文件修改历史

    1 命令 git log --pretty=oneline  文件名 ➜ admin git:(feature/v1.5.0_20181202_group) git log --pretty=onel ...

  5. 出现fonts/fontawesome-webfont.woff?v=4.5.0 net::ERR_ABORTED

    虽然网页正常显示和运行,但是有2个字体文件出现404错误. 原因:服务器没有配置MIME类型而已. 1. 在IIS网站中,找打网站对应的MIME类型,双击. 2.能看到此网站对应的MIME类型,点击右 ...

  6. 分享一款Markdown的css样式

    使用 本样式在这个样式的基础上做了一些修改, 主要是对于表格和代码块以及一些细节的修改. 主要目的是用在chrome的扩展 Markdown Preview Plus中, 替换其内置的样式. 由于 M ...

  7. cetus系列~ 读写分离具体分析

    一 简介:上一章我们讲了cetus的基本安装,这章继续分析cetus 二 分析 1 基本配置       1 开启主从延迟检测需在后端数据库创建库proxy_heart_beat和表tb_heartb ...

  8. 移动前端框架,require.js压缩

    static css images 不同的页面可以新建不同的图片文件夹(可选) js libs       前端类库 plugs    插件 views    自己写的代码文件 sass/less l ...

  9. Jetson tk1 安装 Intel 7260 无线网卡驱动

    Jseton TK1上没有集成的无线网卡,开发板上有一个mini pci-e接口,可以插入Intel 7260这款继承了wifi和蓝牙功能的无线网卡: 该网卡实物如下图,在淘宝和Amazon上都可以买 ...

  10. 【黑客免杀攻防】读书笔记8 - 软件逆向工程基础2(if-else,三目运算符)

    0x1 if-else分支 if-else分支4种状态 1.1 以常量为判断条件的简单if-else分支 C源代码: 单层if-else判断,常量为判断条件 int _tmain(int argc, ...