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. Django 模版语法 一

    创建项目 django_template 和 app django-admin startproject django_template python manage.py startapp app01 ...

  2. Oracle 实现查询不区分大小写(设置数据库)

    转http://blog.csdn.net/shl7765856/article/details/7622756 查询数据的时候. SQL Server 默认 不区分大小写. 如果要区分,就要额外的设 ...

  3. 每周一赛(E题,广搜求方案)

    Description In this problem, you are given an integer number s. You can transform any integer number ...

  4. HTML、CSS常用技巧

    一.HTML 在介绍HTML之前,我们先看一下HTML的文档树结构,主要包括哪些: (一).头部标签 1,Doctype Doctype告诉浏览器使用什么样的HTML或XHTML规范来解析HTML文档 ...

  5. Nginx学习总结(4)——负载均衡session会话保持方法

    负载均衡时,为了保证同一用户session会被分配到同一台服务器上,可以使用以下方法: 1.使用cookie 将用户的session存入cookie里,当用户分配到不同的服务器时,先判断服务器是否存在 ...

  6. 用bootstrap_table实现html 表格翻页

    资料网址 百度经验:HTML表格分页,table分页怎么做? 官网(下载链接和官方教程) (右上角可选语言) 文档 以下内容基本摘自官网 用法 1.下载资料 官网下载: 下下来长这样: 其中src里面 ...

  7. Webdriver概述(selenium对应浏览器版本)

    Webdriver (Selenium2)是一种用于Web应用程序的自动测试工具,它提供了一套友好的API,与Selenium 1(Selenium-RC)相比,Webdriver 的API更容易理解 ...

  8. z_algorithm

    //对于字符串a的每个后缀,匹配它与a的第一个后缀的最长公共前缀,复杂度线性void z_algorithm(char *a,int len) { z[]=len; ,j=,k;i<len;i= ...

  9. 编程数学(A-2)-次方

    百度百科:次方. 特别是一个数的负次方需要注意.

  10. 全文搜索(A-3)-推荐系统构建步骤

    用户研究 用户建模 系统建造