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种颜色的球 ...
随机推荐
- python中with语句的使用
引言 with 语句是从 Python 2.5 开始引入的一种与异常处理相关的功能(2.5 版本中要通过 from __future__ import with_statement 导入后才可以使用) ...
- ELK(ElasticSearch, Logstash, Kibana) 实现 Java 分布式系统日志分析架构
一.首先理解为啥要使用ELK 日志主要分为三类:系统日志.应用程序日志和安全日志.系统运维和开发人员可以通过日志了解服务器软硬件信息.检查配置过程中的错误及错误发生的原因.通过分析日志可以了解服务器的 ...
- RabbitMQ 简使用案例
第一步导入依赖 : <dependency> <groupId>com.rabbitmq</groupId> <artifactId>amqp-clie ...
- 图解golang内存分配机制 (转)
一般程序的内存分配 在讲Golang的内存分配之前,让我们先来看看一般程序的内存分布情况: 以上是程序内存的逻辑分类情况. 我们再来看看一般程序的内存的真实(真实逻辑)图: Go的内存分配核心思想 G ...
- Leetcode题目200.岛屿数量(BFS+DFS+并查集-中等)
题目描述: 给定一个由 '1'(陆地)和 '0'(水)组成的的二维网格,计算岛屿的数量.一个岛被水包围,并且它是通过水平方向或垂直方向上相邻的陆地连接而成的.你可以假设网格的四个边均被水包围. 示例 ...
- IntelliJ IDEA 2017.3 搭建一个多模块的springboot项目(二)
上一篇我成功搭建了一个项目,名叫bale-project,下面我们继续搭建子模块. 在项目名称上右键,New->Module,新建一个模块. 这次我们选择Spring Initializr 起个 ...
- Android蓝牙开发技术学习总结
Android开发,提供对蓝牙的通讯栈的支持,允许设别和其他的设备进行无线传输数据.应用程序层通过安卓API来调用蓝牙的相关功能,这些API使程序无线连接到蓝牙设备,并拥有P2P或者多端无线连接的特性 ...
- PCL点云库(Point Cloud Library)简介
博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=29 什么是PCL PCL(Point Cloud Library)是在吸收了 ...
- Qt编写自定义控件13-多态进度条
前言 多态进度条,顾名思义,有多重状态,其实本控件主要是用来表示百分比进度的,由于之前已经存在了百分比进度条控件,名字被霸占了,按照先来先得原则,只好另外取个别名叫做多态进度条,应用场景是,某种任务有 ...
- 九十七:CMS系统之模板抽离和个人信息页面
模板抽取,将公共的页面抽出来作为模板 {% from 'common/_macros.html' import static %}<!DOCTYPE html><html lang= ...