终于上蓝名了,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. IDA Pro使用(静态分析+动态调试)

    链接:http://skysider.com/?p=458 IDA Pro使用(静态分析+动态调试) 1.静态分析 IDA FLIRT Signature Database —— 用于识别静态编译的可 ...

  3. L1比L2更稀疏

    1. 简单列子: 一个损失函数L与参数x的关系表示为: 则 加上L2正则化,新的损失函数L为:(蓝线) 最优点在黄点处,x的绝对值减少了,但依然非零. 如果加上L1正则化,新的损失函数L为:(粉线) ...

  4. .NET Framework 系统版本支持表

    .tg {border-collapse:collapse;border-spacing:0;border-color:#aabcfe;} .tg td{font-family:Arial, sans ...

  5. android 不同Activity之间数据传递

    1. 传值Activity package mydemo.mycom.demo2; import android.content.Intent; import android.support.v7.a ...

  6. css命名规范: BEM 的命名法

    整理自:前端早读课[第1183期]这些 CSS 命名规范,将省下你大把调试时间 试图解决 3 类问题: 仅从名字就能知道一个 CSS 选择器具体做什么 从名字能大致清楚一个选择器可以在哪里使用 从 C ...

  7. 闭包传递(floyed)

    题目链接: https://cn.vjudge.net/contest/66569#problem/H 题目大意: n代表母牛的个数,m代表给定的信息的组数.每一组数包括a,b. 代表b崇拜a(突然发 ...

  8. Shiro的三种授权(十二)

    前提就是在Realm的授权方法中查询出权限并返回List<String>形式 @Override protected AuthorizationInfo doGetAuthorizatio ...

  9. QT中QString 与 int float double 等类型的相互转换

    Qt中 int ,float ,double转换为QString 有两种方法 1.使用 QString::number(); 如: long a = 63; QString s = QString:: ...

  10. K-means聚类算法原理和C++实现

    给定训练集$\{x^{(1)},...,x^{(m)}\}$,想把这些样本分成不同的子集,即聚类,$x^{(i)}\in\mathbb{R^{n}}$,但是这是个无标签数据集,也就是说我们再聚类的时候 ...