A. Kyoya and Colored Balls

大意: 给定$k$种颜色的球, 第$i$种颜色有$c_i$个, 一个合法的排列方案满足最后一个第$i$种球的下一个球为第$i+1$种球, 求合法方案数.

简单组合, 添加第$i$种时必须在最后放一个$i$, 剩余任意放, 可重组合算下贡献即可.

#include <iostream>
#include <cstdio>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
using namespace std;
typedef long long ll;
const int P = 1e9+7, P2 = 998244353, INF = 0x3f3f3f3f;
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
const int N = 1e6+10;
int n, fac[N], ifac[N];
int C(int n, int m) {
if (m>n) return 0;
int t = (ll)fac[n]*ifac[m]%P*ifac[n-m]%P;
return t;
}
int main() {
fac[0]=ifac[0]=1;
REP(i,1,N-1) fac[i]=(ll)fac[i-1]*i%P;
ifac[N-1] = inv(fac[N-1]);
PER(i,1,N-2) ifac[i]=(ll)ifac[i+1]*(i+1)%P;
scanf("%d", &n);
int ans = 1, sum = 0;
REP(i,1,n) {
int t;
scanf("%d", &t);
ans = (ll)ans*C(sum+t-1,t-1)%P;
sum += t;
}
printf("%d\n", ans);
}

B. Kyoya and Permutation

大意: 定义了一种对排列的操作, 若一个排列操作后不变则为一个好排列, 求第$k$个好排列.

找下规律发现每个好排列的每个置换大小不超过2, 且大小为2的置换两个数要相邻.

所以可以得到$n$的好排列个数$F(n)$是满足递推$F(1)=1,F(2)=2,F(n)=F(n-1)+F(n-2)$.

#include <iostream>
#include <cstdio>
#define REP(i,a,n) for(int i=a;i<=n;++i)
using namespace std; typedef long long ll;
int n;
ll f[100], k; int main() {
f[0] = 1, f[1] = 1;
REP(i,2,88) f[i]=f[i-1]+f[i-2];
scanf("%d%lld", &n, &k);
REP(i,1,n) {
if (k<=f[n-i]) printf("%d ",i);
else {
k -= f[n-i];
printf("%d %d ", i+1, i);
++i;
}
}
puts("");
}

C. Love Triangles

大意: 给定$n$节点$m$条边无向图, 每条边为0或1, 求补全为完全图, 且任意一个三元环的三条边恰好全1或恰好一个1的方案数.

显然确定两边后第三条边就已经固定了, 所以可以检验出每个连通块是否合法, 假设共cnt个连通块, 答案就是$2^{cnt-1}$.

#include <iostream>
#include <cstdio>
#include <queue>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
using namespace std;
typedef long long ll;
const int N = 1e6+10, P = 1e9+7;
int n, m, ans, vis[N];
struct _ {int to,w;};
vector<_> g[N];
void dfs(int x) {
for (_ e:g[x]) {
if (vis[e.to]==-1) {
vis[e.to] = vis[x]^e.w;
dfs(e.to);
}
else if (vis[e.to]!=(vis[x]^e.w)) ans = 0;
}
}
int main() {
scanf("%d%d", &n, &m);
while (m--) {
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
g[u].pb({v,!w}),g[v].pb({u,!w});
}
memset(vis,-1,sizeof vis);
ans = (P+1)/2;
REP(i,1,n) if (vis[i]==-1) {
vis[i] = 1, ans = (ll)ans*2%P, dfs(i);
}
printf("%d\n", ans);
}

D Nudist Beach

大意: 给定$n$节点$m$条边无向图, 标记了$k$个点. 要求从未标记的点中选出一个点集$S$, 每个点的价值是$\frac{A}{B}$, $A$为相邻的选中的点, $B$为相邻所有点, 整个点集的价值为所有点价值的最小值. 求$S$价值的最大值.

01分数规划问题, 转为二分答案即可.

#include <iostream>
#include <cstdio>
#include <queue>
#define REP(i,a,n) for(int i=a;i<=n;++i)
using namespace std; const double eps = 1e-8;
const int N = 1e5+10;
int n, m, k;
int deg[N], vis[N], cnt[N], used[N];
vector<int> g[N];
queue<int> q;
int chk(double x) {
REP(i,1,n) cnt[i] = 0;
REP(i,1,n) if (!vis[i]) {
used[i] = 1;
for (int j:g[i]) ++cnt[j];
}
REP(i,1,n) if (cnt[i]<x*deg[i]) q.push(i);
while (q.size()) {
int u = q.front(); q.pop();
if (!used[u]) continue;
used[u] = 0;
for (int v:g[u]) if (--cnt[v]<x*deg[v]) q.push(v);
}
int tot = 0;
REP(i,1,n) tot += used[i];
return tot;
} int main() {
scanf("%d%d%d", &n, &m, &k);
REP(i,1,k) {
int t;
scanf("%d", &t);
vis[t] = 1;
}
REP(i,1,m) {
int u, v;
scanf("%d%d", &u, &v);
g[u].push_back(v),g[v].push_back(u);
++deg[u],++deg[v];
}
double l = -eps, r = 1, ans;
REP(i,1,200) {
double mid = (l+r)/2;
if (chk(mid)) ans=mid,l=mid+eps;
else r=mid-eps;
}
chk(ans);
int tot = 0;
REP(i,1,n) tot += used[i];
printf("%d\n", tot);
REP(i,1,n) if (used[i]) printf("%d ", i);
puts("");
}

E.

Codeforces Round #309 (Div. 1)的更多相关文章

  1. 贪心 Codeforces Round #309 (Div. 2) B. Ohana Cleans Up

    题目传送门 /* 题意:某几列的数字翻转,使得某些行全为1,求出最多能有几行 想了好久都没有思路,看了代码才知道不用蠢办法,匹配初始相同的行最多能有几对就好了,不必翻转 */ #include < ...

  2. 找规律 Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks

    题目传送门 /* 找规律,水 */ #include <cstdio> #include <iostream> #include <algorithm> #incl ...

  3. Codeforces Round #309 (Div. 1) C. Love Triangles dfs

    C. Love Triangles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/553/pro ...

  4. Codeforces Round #309 (Div. 1) B. Kyoya and Permutation 构造

    B. Kyoya and Permutation Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  5. Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls 排列组合

    C. Kyoya and Colored Balls Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  6. Codeforces Round #309 (Div. 2) B. Ohana Cleans Up 字符串水题

    B. Ohana Cleans Up Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/554/pr ...

  7. Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks 字符串水题

    A. Kyoya and Photobooks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  8. C. Kyoya and Colored Balls(Codeforces Round #309 (Div. 2))

    C. Kyoya and Colored Balls Kyoya Ootori has a bag with n colored balls that are colored with k diffe ...

  9. Codeforces Round #309 (Div. 2)

    A. Kyoya and Photobooks Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He ha ...

  10. Codeforces Round #309 (Div. 1) A(组合数学)

    题目:http://codeforces.com/contest/553/problem/A 题意:给你k个颜色的球,下面k行代表每个颜色的球有多少个,规定第i种颜色的球的最后一个在第i-1种颜色的球 ...

随机推荐

  1. zookeeper备忘

    ZooInspector https://issues.apache.org/jira/secure/attachment/12436620/ZooInspector.zip 参考:https://b ...

  2. mac安装phpmysql

    1.百度搜“phpmadmin”,还是一样,第二个因为是PC版本,不能用,点击第一个连接,去phpmyadmin的官网. 2.下载完毕后,进入到下载文件保存目录,双击压缩包,压缩包则会自动解压. 3. ...

  3. 【Linux命令】find命令

    [find命令] 说明:find命令用来在指定目录下查找文件.任何位于参数之前的字符串都将被视为欲查找的目录名.如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件.并且将查 ...

  4. SpringMVC整合SpringFox实践总结

    项目中使用的swagger框架在生成api文档时存在一些问题: 1. 控制器下方法无法点击展开 2.api内容结构混乱 基于上述原因,重新整合重构了一下api文档生成的代码.在此将重整过程记录下来,方 ...

  5. RabbitMQ学习之:(八)Topic Exchange (转贴+我的评论)

    From: http://lostechies.com/derekgreer/2012/05/18/rabbitmq-for-windows-topic-exchanges/ RabbitMQ for ...

  6. mysql 截取字符函数substring(param1,param2,param3) 的用法

    substring(paramter1,paramter2,paramter3) 截取字段长度 paramter1  被截取的字段paramter2 从第几位开始截取,负数表示从末尾开始数,的位数开始 ...

  7. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-2.快速搭建SpringBoot项目,采用IDEA

    笔记 2.快速搭建SpringBoot项目,采用IDEA     简介:使用SpringBoot start在线生成项目基本框架并导入到IDEA中 参考资料:         IDEA使用文档    ...

  8. RDD的cache 与 checkpoint 的区别

    问题:cache 与 checkpoint 的区别? 关于这个问题,Tathagata Das 有一段回答: There is a significant difference between cac ...

  9. 安装k8s-1master多node节点

    卸载比较新的18.3版本,安装17.03版本 删除旧版本 sudo yum remove docker \ docker-client \ docker-client-latest \ docker- ...

  10. 5.Linux文件权限

    Linux用户类别 root:这是系统特权用户类,他们都有访问root登录账号的权限 owner:这是实际拥有文件的用户 group:这是共享文件的组访问权的用户类的用户组名称 world:这是不属于 ...