Codeforces Round #309 (Div. 1)
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)的更多相关文章
- 贪心 Codeforces Round #309 (Div. 2) B. Ohana Cleans Up
题目传送门 /* 题意:某几列的数字翻转,使得某些行全为1,求出最多能有几行 想了好久都没有思路,看了代码才知道不用蠢办法,匹配初始相同的行最多能有几对就好了,不必翻转 */ #include < ...
- 找规律 Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks
题目传送门 /* 找规律,水 */ #include <cstdio> #include <iostream> #include <algorithm> #incl ...
- 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 ...
- 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/ ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #309 (Div. 2)
A. Kyoya and Photobooks Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He ha ...
- Codeforces Round #309 (Div. 1) A(组合数学)
题目:http://codeforces.com/contest/553/problem/A 题意:给你k个颜色的球,下面k行代表每个颜色的球有多少个,规定第i种颜色的球的最后一个在第i-1种颜色的球 ...
随机推荐
- ARTS打卡计划第九周
Algorithms: https://leetcode-cn.com/problems/merge-two-sorted-lists/submissions/ 合并两个链表 Review: “Pu ...
- Leetcode题目200.岛屿数量(BFS+DFS+并查集-中等)
题目描述: 给定一个由 '1'(陆地)和 '0'(水)组成的的二维网格,计算岛屿的数量.一个岛被水包围,并且它是通过水平方向或垂直方向上相邻的陆地连接而成的.你可以假设网格的四个边均被水包围. 示例 ...
- NUnit -- Test discovery or execution might not work for this project
[7/31/2019 2:06:58.100 PM Warning] No test matches the given testcase filter `FullyQualifiedName=Sil ...
- vs下qt的信号与槽实现
实现主窗口中Add按钮的功能, 这一部分要特别注意,除了实现功能代码外,还需自己手动添加一些其他的代码(Qt Creator可以自动添加). 我们需要在2个地方添加代码. 第1个是在addressbo ...
- Android跨进程通信Content Provider
Content Provider ContentProvider在android中的作用是对外共享数据,也就是说你可以通过ContentProvider把应用中的数据共享给其他应用访问,其他应用可以通 ...
- springboot 获取控制器参数的几种方式
这里介绍springboot 获取控制器参数有四种方式 1.无注解下获取参数 2.使用@RequestParam获取参数 3.传递数组 4.通过URL传递参数 无注解下获取参数无注解下获取参数,需要控 ...
- Selenium 2自动化测试实战37(自动发邮件功能)
自动发邮件功能 例如,如果想在自动化脚本运行完成之后,邮箱就可以收到最新的测试报告结果.SMTP(Simple Mail Transfer Protocol)是简单邮件传输协议,它是一组用于由源地址到 ...
- [Distributed ML] Yi WANG's talk
王益,分布式机器学习的践行者,他的足迹值得后来者学习. 膜拜策略: LinkedIn高级分析师王益:大数据时代的理想主义和现实主义(图灵访谈)[心路历程] 分布式机器学习的故事-王益[历史由来] 分布 ...
- Mysql——常用命令
查看版本:show variables like '%version%' 或者 select version() 是否开启binlog:show variables like 'log_bin ...
- 关于Content-Type中application/x-www-form-urlencoded 和 multipart/form-data的区别及用法
http://blog.csdn.net/soonfly/article/details/52082547 Form的enctype属性表示页面表单数据向服务器传输时的编码方式, 常用有两种:appl ...