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种颜色的球 ...
随机推荐
- Qt5.11.2 VS2015编译activemq发送程序 _ITERATOR_DEBUG_LEVEL错误和崩溃解决
1.问题描述: 运行环境是 win10 64位系统,开发环境是VS2015 ,Qt 5.11.2.开发activemq发送程序,遇到问题 (1)Qt5AxContainer.lib error LNK ...
- python 列表切片之负数的含义代码示例
a = list(range(10)) print(a[::]) #复制一个列表 print(a[::2]) #每隔2个取一次 print(a[::3]) #每隔3个取一次 print(a[::-1] ...
- springboot+shiro 跨域解决(OPTIONS)
拦截器判断 拦截器截取到请求先进行判断,如果是OPTIONS请求的话,则放行 import com.alibaba.fastjson.JSON; import com.zp.demo.util.Jwt ...
- Flutter移动电商实战 --(13)ADBanner组件的编写
1.AdBanner组件的编写 我们还是把这部分单独出来,需要说明的是,这个Class你也是可以完全独立成一个dart文件的.代码如下: 广告图片 class AdBanner extends Sta ...
- 前端知识点回顾之重点篇——ES6的Promise对象
Promise Promise 是异步编程的一种解决方案,比传统的解决方案--回调函数和事件--更合理和更强大. 所谓Promise,简单说就是一个容器,里面保存着某个未来才会结束的事件(通常是一个异 ...
- leetcode16 最接近的三数之和
做了几周的hard之后,这道题居然轻易就解出来了,稍微debug了一下就ac了,算是有了一丢丢提高把: 思路 这道题因为和三数之和很像,所以充分利用双指针的思想:先排序,然后再固定一个数i,i取值从[ ...
- Camera 录制视频的实现
使用 Camera 录制视频, 实现步骤如下: 需要权限: android.permission.CAMERA android.permission.RECORD_AUDIO android.perm ...
- Hander创建消息
每一个消息都需要被指定的Handler处理,通过Handler创建消息便可以完成此功能.Android消息机制中引入了消息池.Handler创建消息时首先查询消息池中是否有消息存在,如果有直接从消息池 ...
- python从入门到放弃之Tensorflow(一)
Tensorflow使用错误集锦: 错误1 : FutureWarning: Conversion of the second argument of issubdtype from ‘float’ ...
- Mybatis中表名当做变量
做业务时,有时候会遇到不同SQL语句之中,只有使用的表名不用而已,其他参数和取得值都是一样的情况.这种时候必然想到把表名当做一个变量传到共通的SQL语句中. 当然正常的传入参数的方式#{param}肯 ...