终于上蓝名了,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. JavaScript 无刷新修改浏览器URL地址栏

    //发现地址栏已改为:newUrlvar stateObject = {}; var title = "Wow Title"; var newUrl = "/my/awe ...

  2. golang error信息转字符串 x := fmt.Sprintf("%s", err)

    _, _, ch, err := m.ZkConn.ChildrenW(node) if err != nil { x := fmt.Sprintf("%s", err) if s ...

  3. 使用jQuery实现返回顶部功能

    <p id="back-to-top"><a href="#top"><span></span>返回顶部< ...

  4. Python 升级致yum 问题,pip 异常

    升级 Python 导致 yum 和 pip 异常: 一些storm 和 自定义项目 需要升级python版本:Linux 系统默认是2.6 版本 ,所以需要根据业务进行升级操作:Python 官方下 ...

  5. UE4的AI学习(2)——官方案例实例分析

    官方给出的AI实例是实现一个跟随着玩家跑的AI,当玩家没有在AI视野里时,它会继续跑到最后看到玩家的地点,等待几秒后如果仍然看不到玩家,则跑回初始地点.官方的案例已经讲得比较详细,对于一些具体的函数调 ...

  6. G - Preparing for Exams

    题目链接: https://vjudge.net/contest/251958#problem/G 具体思路: 圆内四边形内角互补,所以,如图所示. 证明,三角形oda和三角形obc相似. 第一步,角 ...

  7. mysql 查询优化 ~explain解读之select_type的解读

    一 简介:今天咱们来聊聊explain的select_type 二 类型 (1)SIMPLE 简单的SELECT语句(不包括UNION操作或子查询操作) (2)PRIMARY/UNION PRIMAR ...

  8. ARMV8 datasheet学习笔记1:预备知识

    1. 前言 ARMv8的架构继承以往ARMv7与之前处理器技术的基础; 除了支持现有的16/32bit的Thumb2指令外,也向前兼容现有的A32(ARM 32bit)指令集. 基于64bit的AAr ...

  9. Linux下查看文件或文件夹大小的命令df 、du、ls

    转自:http://www.cnblogs.com/benio/archive/2010/10/13/1849946.html 当磁盘大小超过标准时会有报警提示,这时如果掌握df和du命令是非常明智的 ...

  10. windows上python上传下载文件到linux服务器指定路径【转】

    从windows上传文件到linux,目录下的文件夹自动创建 #!/usr/bin/env python # coding: utf-8 import paramiko import datetime ...