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. 集训第五周 动态规划 B题LIS

      Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Des ...

  2. java-得到字符串中出现次数最最多的字符,并打印出字符以及出现次数

    最近面试总被面试到,整理出几种方式(有参考别人的部分) /** * java一个字符串中出现次数最多的字符以及次数 * @param args */ public static void main(S ...

  3. CSS实现折叠面板

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  4. NYOJ-1188并集与交集,STL的灵活运用!

    并集与交集 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 给你两个字符串的集合A和B,让你求这两个字符串集合的并集和交集,按字典序排序后输出. 然后又给出给出两个字符串 ...

  5. 2016 Multi-University Training Contest 3-1011.Teacher Bo,暴力!

    Teacher Bo                                                         Time Limit: 4000/2000 MS (Java/Ot ...

  6. Mysql Replace语句的使用

    Mysql Replace语句的语法: REPLACE [LOW_PRIORITY | DELAYED] [INTO] tbl_name [(col_name,...)] VALUES ({expr ...

  7. HDU 5642 King's Order【数位dp】

    题目链接: http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=677&pid=1003 题意: 求长度为n的序列 ...

  8. 微信浏览器video

    <style> /* 解决上下有黑边,不能全屏 */ video{object-fit: fill;} </style> <video id="videoID& ...

  9. JSTL-SQL标签库

    主页:http://www.cnblogs.com/EasonJim/p/6958992.html的分支页. 本章的前提需要先新建数据表及添加默认数据,脚本如下: -- -- 数据库: `test` ...

  10. maven提示“编码 GBK 的不可映射字符”问题的解决

    pom.xml中加上如下代码 <properties> <!-- spring版本号 --> <spring.version>4.2.3.RELEASE</s ...