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 题意: 给定大 ...
随机推荐
- Qt Widgets Application可执行程序发布方式
前言 写好的Qt程序想打包发布,之前按照Qt快速入门系列教程里的方法,直接选release,构建,之后找到exe,拷贝几个dll,然而报错如图: 后来找到教程:http://tieba.baidu.c ...
- 关于OPENSSL的EVP函数的使用
4月份没什么做,就是做了OPENSSL的 加密和解密的应用,现在公开一下如何调用OPENSSL对字符串进行加密和解密,当中也学会了对加密数据进行BASE64编码,现在公开一下代码,在这感谢GITHUB ...
- 前端开发:JavaScript---DOM & BOM
DOM:Document Object Model 文档对象类型 模态框案例 <!DOCTYPE html> <html lang="en"> <h ...
- openjudge7624 山区建小学
描述 政府在某山区修建了一条道路,恰好穿越总共m个村庄的每个村庄一次,没有回路或交叉,任意两个村庄只能通过这条路来往.已知任意两个相邻的村庄之间的距离为di(为正整数),其中,0 < i < ...
- Visual C++ 网络编程 笔记
第一章 网络分层模型 OSI模型应用层:服务于应用程序的协议,比如用于域名解析的DNS协议,用于下载界面内容的HTTP协议表示层:处理不同硬件和操作系统之间的差异,确保应用层之间顺利通信 and 加密 ...
- sqlserver2008 存储过程使用表参数
----首先,我们定义一个表值参数类型,其实就是一个表变量 Create type dbo.tp_Demo_MultiRowsInsert as Table ( [PName] [Nvar ...
- BootStrap3栅格系统与布局
栅格系统与布局 Use our powerful mobile-first flexbox grid to build layouts of all shapes and sizes thanks t ...
- java 8种基本类型与对应的包装类
数据类型 包装类 字节长度 默认值 有效位 byte Byte 1 0 -128~127 short Short 2 0 -32768~32767 int Integer 4 0 -2^31-1~2^ ...
- Ubuntu 16.04安装Ubuntu After Install工具实现常用软件批量安装
这个软件集成了常用且好用的软件,且只需要选择需要的软件之后自动安装好,不需要额外设置. 安装: sudo add-apt-repository ppa:thefanclub/ubuntu-after- ...
- linux 用 rsync 快速删除大量小文件
假设我们在目录 /tmp/to_delete 下有很多小文件 a1 a2 a3 f1 f2 f3 现在我们想快速的删除f 开头的文件. 如果文件量大,用rm 可能会失败,而且会很慢, 所以用rsync ...