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的更多相关文章

  1. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  2. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  3. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  4. CodeForces 839C - Journey | Codeforces Round #428 (Div. 2)

    起初误以为到每个叶子的概率一样于是.... /* CodeForces 839C - Journey [ DFS,期望 ] | Codeforces Round #428 (Div. 2) */ #i ...

  5. CodeForces 839D - Winter is here | Codeforces Round #428 (Div. 2)

    赛后听 Forever97 讲的思路,强的一匹- - /* CodeForces 839D - Winter is here [ 数论,容斥 ] | Codeforces Round #428 (Di ...

  6. 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 ...

  7. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  8. Codeforces Round #361 div2

    ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...

  9. Codeforces Round #626 Div2 D,E

    比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...

随机推荐

  1. ruby on rails 常见配置错误解决

    error:in `require': cannot load such file -- sqlite3/sqlite3_native (LoadError) 先删除 Ruby下的D:\Ruby22- ...

  2. VS2017 + Qt5 + OpenCV400 环境配置

    首先为VS2017 IDE点赞. 配置核心 配置 Qt5 和 OpenCV400,最主要的就是头文件路径.库路径以及库文件名字. 配置方法和步骤 新建一个工程,或者打开一个已有的工程: 选择 View ...

  3. Unity3D 固定功能函数

    Unity 3D 测试固定功能函数执行顺序 1. 在GameObject和脚本激活状态下,测试: 2. 在GameObject激活状态下,测试: 3. 在2种情况都不激活的状态下测试:脚本无输出: 函 ...

  4. javascript倒计时代码及倒计时弹窗

    在前端开发中,难免会用到倒计时.如做的双十一活动,在距活动开始的半个月前需要做些宣传工作,需要告知用户优惠活动什么时候开始.这个时候就要用到倒计时,如在整站的某个页面提醒用户活动什么时候开始等.而在活 ...

  5. JavaWeb 项目,更改本地文件需刷新才有效问题 (tomcat相关)

    问题 如果JavaWeb项目需要读取实时更新的本地文件内容,可能遇到必须在更新后手动refresh才能有效的问题. 原因 这是由于项目实际上是运行在Tomcat中,而非本地的工作目录.eclipse可 ...

  6. Python接口测试之对MySQL的操作(六)

    本文章主要来说python对mysql数据库的基本操作,当然,前提是已经搭建了python环境和搭建了Mysql 数据库的环境,python操作mysql数据库提供了MySQLdb库,下载的地址为: ...

  7. 【NOIP2017练习】怎样更有力气(二分答案,线性扫描)

    题意:OI大师抖儿在夺得银牌之后,顺利保送pku.这一天,抖儿问长者:“我虽然已经保送了,但我的志向是为国家健康工作五十年.请问我应该怎样变得更有力气?”   长者回答:“你啊,Too Young T ...

  8. 【Nginx】负载均衡-IP哈希策略剖析

    转自:江南烟雨 IP哈希初始化 IP哈希的初始化函数ngx_http_upstream_init_ip_hash(ngx_http_upstream_ip_hash_module.c): static ...

  9. 正则表达式的捕获组(capture group)在Java中的使用

    原文:http://blog.csdn.net/just4you/article/details/70767928 ------------------------------------------ ...

  10. centos 命令行中 * 和 . 的区别

    錯誤    cp /home/test1/* /home/test2/ –a          用參數*將不可以複製linux中.開頭的隱藏文件 正確    cp /home/test1/. home ...