codeforces round #428 div2
A:暴力模拟,能加就加,如果累计到了8就加上,每次累积
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k ,cnt = ;
scanf("%d%d", &n, &k);
for(int i = ; i <= n; ++i)
{
int x;
scanf("%d", &x);
cnt += x;
if(cnt >= )
{
k -= ;
cnt -= ;
}
else
{
k -= cnt;
cnt = ;
}
if(k <= )
{
printf("%d\n", i);
return ;
}
}
puts("-1");
return ;
}
B:模拟,情况有点多,先每四个人分配位置,四人座不够分配二人座,然后每两个人分配,两人坐没了分配四人座,分配四人座的时候每次统计+1,如果两人四人都没了两个四人座剩下的可以给两个人坐在边上,剩下一个人就把两人坐四人座分配,两人座可以做一个人,四人座可以做两个人,之前统计+1可以坐一个人
#include<bits/stdc++.h>
using namespace std;
const int N = ;
int n, k;
int a[N];
int main()
{
scanf("%d%d", &n, &k);
int cnt1 = n * , cnt2 = n, one = ;
for(int i = ; i <= k; ++i)
{
scanf("%d", &a[i]);
int x = a[i] / ;
a[i] %= ;
if(cnt2 >= x) cnt2 -= x;
else
{
x -= cnt2;
cnt2 = ;
if(cnt1 >= * x) cnt1 -= * x;
else
{
puts("NO");
return ;
}
}
}
for(int i = ; i <= k; ++i)
{
if(a[i] == ) continue;
int x = a[i] / ;
a[i] %= ;
if(cnt1 >= x) cnt1 -= x;
else
{
x -= cnt1;
cnt1 = ;
if(cnt2 >= x)
{
cnt2 -= x;
one += x;
}
else if(one >= x * )
{
one -= x * ;
}
else
{
puts("NO");
return ;
}
}
}
one += * cnt2 + cnt1;
for(int i = ; i <= k; ++i)
{
if(a[i] == ) continue;
--one;
if(one < )
{
puts("NO");
return ;
}
}
puts("YES");
return ;
}
C:一个比较简单的概率dp,每次dp[v]=dp[u]/(size[u]-(last == 0)),如果是根节点last=0没有前继,概率就是度数,否则度数-1,然后叶子结点的概率乘上步长就是答案
#include<bits/stdc++.h>
using namespace std;
const int N = ;
int n;
double ans;
double dp[N];
vector<int> G[N];
void dfs(int u, int last, int dis)
{
if(G[u].size() == ) ans += dp[u] * (double)dis;
for(int i = ; i < G[u].size(); ++i)
{
int v = G[u][i];
if(v == last) continue;
dp[v] = dp[u] * 1.0 / (double)(G[u].size() - (last != ));
dfs(v, u, dis + );
}
}
int main()
{
scanf("%d", &n);
dp[] = 1.0;
for(int i = ; i < n; ++i)
{
int u, v;
scanf("%d%d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
dfs(, , );
// for(int i = 1; i <= n; ++i) printf("dp[%d]=%.6f\n", i, dp[i]);
printf("%.8f\n", ans);
return ;
}
D:一个很好的题,我们用容斥原理来做,设cnt[i]表示能整除i的a[i]的个数,ans[i]表示gcd为i的子序列的答案,我们发现直接计算ans似乎有些困难,但是我们可以容斥,我们放宽条件,先找出gcd能整除i的子序列的人的总和的可能的总数,是C(n,1)*1+C(n,2)*2+C(n,3)*3+...+C(n,n)*n,意思是n个人选1个人的方案数*1个人,n个人选两个人*两个人,统计了所有子序列的总人数,然后我们加一项C(n,0)*0,然后倒序相加,就得到了n*(C(n,0)+C(n,1)+...+C(n,n))/2=n*2^n/2=n*2^n-1,这是gcd是n的倍数的答案,然后根据容斥原理,我们把ans[i*2],ans[i*3]...减去,剩下的就是答案
这其实跟莫比乌斯反演挺像的,就是限制太强就用容斥弱化一下
#include<bits/stdc++.h>
using namespace std;
const int N = , mod = ;
int n;
int a[N], has[N * ], cnt[N * ];
long long ans[N * ];
long long answer;
inline int read()
{
int x = , f = ; char c = getchar();
while(c < '' || c > '') { if(c == '-') f = -; c = getchar(); }
while(c >= '' && c <= '') { x = x * + c - ''; c = getchar(); }
return x * f;
}
long long power(long long x, long long t)
{
long long ret = ;
for(; t; t >>= , x = x * x % mod) if(t & ) ret = ret * x % mod;
return ret;
}
int main()
{
scanf("%d", &n);
for(int i = ; i <= n; ++i)
{
a[i] = read();
++has[a[i]];
}
for(int i = ; i <= ; ++i)
for(int j = i; j <= ; j += i) cnt[i] += has[j];
for(int i = ; i >= ; --i) if(cnt[i] > )
{
ans[i] = (long long)cnt[i] * (long long)power(, cnt[i] - ) % mod;
for(int j = i * ; j <= ; j += i) ans[i] -= ans[j];
answer = (answer + (long long)i * ans[i]) % mod;
}
printf("%lld\n", (answer % mod + mod) % mod);
return ;
}
codeforces round #428 div2的更多相关文章
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- 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 #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- Codeforces Round #626 Div2 D,E
比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...
随机推荐
- 数据结构代码实现之队列的链表实现(C/C++)
上班闲着无聊,一直想着要开始写博客,但又不知道写什么.最近又回顾了下数据结构的知识,那就从数据结构开始吧. 前言 关于C语言结构体的知识以及队列的特性请读者自行了解,此处不做过多解释,嘻嘻. 同时此篇 ...
- SQlServer中的MD5加密
SELECT sys.fn_varbintohexstr(HASHBYTES('MD5', '我'));
- python面向对象编程设计与开发
一.什么是面向对象的程序设计 1.何为数据结构? 数据结构是指相互之间存在一种或多种特定关系的数据元素的集合,如列表.字典. 2.何为编程? 编程是指程序员用特定的语法+数据结构+算法,组成的代码,告 ...
- 在 Sublime Text 直接运行 Javascript 调试控制台
转载自:http://www.jianshu.com/p/43b0726792f7 sublime text javascript Sublime Text是深受喜欢的多语言编辑器,很多开发人员都选择 ...
- JavaEE JDBC 核心API
JDBC接口核心的API @author ixenos java.sql.* 和 javax.sql.* |- Driver接口: 表示java驱动程序接口.所有的具体的数据库厂商要来实现此接口 ...
- noip模拟赛 斐波那契
分析:暴力分有90,真良心啊. a,b这么大,连图都建不出来,肯定是有一个规律.把每个点的父节点写出来:0 1 1 12 123 12345 12345678,可以发现每一个循环的长度刚好是斐波那契数 ...
- hdu 1166 树状数组模板题
#include<stdio.h> #include<string.h> #define N 51000 int c[N],n; int number(int x) { r ...
- vagrant的学习 之 ThinkPHP5.1
vagrant的学习 之 ThinkPHP5.1 本文根据慕课网的视频教程练习,感谢慕课网! 慕课视频学习地址:https://www.imooc.com/video/14218. 慕课的参考文档地址 ...
- JSP的隐藏对象
以下内容引用自http://wiki.jikexueyuan.com/project/jsp/implicit-objects.html: JSP隐式对象是Java对象,JSP容器使隐式对象在每一个页 ...
- linux 虚拟网卡
linux中可以通过一个物理网卡,模拟出多个虚拟网卡,并在网卡中配置ip. 下面做一个实验. 实验描述: 我们有server A (ip 10.79.148.205),server B (10.79. ...