Codeforces Round 252 (Div. 2)
layout: post
title: Codeforces Round 252 (Div. 2)
author: "luowentaoaa"
catalog: true
tags:
mathjax: true
- codeforces
- 群论
A.Valera and Antique Items (签到)
题意
如果当前钱数比一组数中最小的还要大就+1
思路
直接模拟
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=1e6+50;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
vector<int>ve;
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int n,v,ans=0;
cin>>n>>v;
for(int i=1;i<=n;i++){
int t,f=0;
cin>>t;
for(int j=1;j<=t;j++){
int a;cin>>a;
if(a<v)f=1;
}
if(f)ans++,ve.push_back(i);
}
cout<<ans<<endl;
for(int i=0;i<ans;i++)cout<<ve[i]<<" ";
return 0;
}
B.Valera and Fruits (模拟)
题意
n天,每天有一些水果,水果保质期为两天,你一天最多手机K个水果问你最多收集几个水果
题解
直接搞两个数组模拟就行。优先把昨天的收集
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=1e6+50;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
int sum[maxn];
int ex[maxn];
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int n,v;cin>>n>>v;
int mx=0;
for(int i=1;i<=n;i++){
int time,num;
cin>>time>>num;
sum[time]+=num;
mx=max(mx,time);
}
mx++;int ans=0;
for(int i=1;i<=mx;i++){
int remain=v;
if(ex[i]>=remain){
ans+=remain;
ex[i+1]+=sum[i];
}
else{
ans+=ex[i];
remain-=ex[i];
if(sum[i]>=remain){
ans+=remain;
ex[i+1]+=sum[i]-remain;
}
else{
ans+=sum[i];
}
}
}
cout<<ans;
return 0;
}
C.Valera and Tubes (模拟)
题意
用面积大于2并且连续的正好k个水管填满整个矩形
思路
因为水管可以弯曲,先用K-1面积为2的水管,然后用剩余的用一个水管填满就行
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=1e6+50;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
vector<int>x,y;
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int n,m,k;
cin>>n>>m>>k;
for(int i=1;i<=n;i++){
if(i&1){
for(int j=1;j<=m;j++)x.push_back(i),y.push_back(j);
}
else{
for(int j=m;j>=1;j--)x.push_back(i),y.push_back(j);
}
}
int cnt=0;
for(int i=1;i<k;i++){
cout<<"2"<<" ";
cout<<x[cnt]<<" "<<y[cnt]<<" ";cnt++;
cout<<x[cnt]<<" "<<y[cnt];cnt++;
cout<<endl;
}
cout<<x.size()-cnt<<" ";
for(int i=cnt;i<x.size();i++){
cout<<x[i]<<" "<<y[i]<<" ";
}
return 0;
}
D. Valera and Swaps(群论 置换群)
题意
给你一个排列,让你进行若干次对换使得新排列再进行最少K次对换回复最小排列
(1,2,3)
思路
1.对于一个环,最少需要进行环的长度-1次操作回复原排列,
2.让两个环合并之后,可以增加一次操作 比如4 + 3 =7 这样就是原本需要3+2=5 ->6次
3.让一个环拆开,可以减少一次操作 同上
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=1e6+50;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
int n,m;
int p[maxn];
int id[maxn];
int cal(){
fill(id+1,id+1+n,0);
int ans=0,cnt=0;
for(int i=1;i<=n;i++){
if(id[i])continue;
id[i]=++cnt;
int num=0;
for(int j=p[i];!id[j];j=p[j]){
id[j]=id[i];
num++;
}
ans+=num;
}
return ans;
}
vector<pair<int,int> >ans;
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>p[i];
}
int m;cin>>m;
while(true){
int now=cal();
if(now==m)break;
else if(now<m){
for(int i=2;i<=n;i++){
if(id[i]!=id[1]){
swap(p[i],p[1]);
ans.push_back(make_pair(1,i));
break;
}
}
}
else{
int f=-1;
for(int i=1;i<=n;i++){
if(p[i]!=i){
f=i;break;
}
}
for(int j=f+1;j<=n;j++){
if(id[f]==id[j]){
swap(p[f],p[j]);
ans.push_back(make_pair(f,j));
break;
}
}
}
}
cout<<ans.size()<<endl;
for(int i=0;i<ans.size();i++)
cout<<ans[i].first<<" "<<ans[i].second<<" ";
return 0;
}
E.Valera and Number(概率,DP,位运算)
题意
给一个数x,执行k轮操作,每次当前的x有p%几率乘二,有(1-p)%几率加一,问最后x期望有几个2的因子
思路
首先一个数X中2的因子个数=转化为二进制后末尾0的个数,所以可以把这题转化成用DP求末尾又多少个0;
用dp[i][j],表示X+j进行i轮操作后的末尾的0的个数。 那么答案就是dp[K][0];
所以对于DP[i][j] 他有两个转移
dp[i][j]+=(dp[i-1][j/2]+1)p
dp[i][j]+=(dp[i-1][j-1])(1-p)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+50;
ll x,k;
double p;
double dp[500][500];
int flag[550][550];
int main()
{
cin>>x>>k>>p;
p/=100.0;
for(int i=0;i<=k;i++){
int o=i+x;
while(o%2==0){
dp[0][i]++;
o/=2;
}
}
for(int i=1;i<=k;i++){
for(int j=0;j<=k;j++){
dp[i][j<<1]+=(dp[i-1][j]+1)*p;
dp[i][j]+=dp[i-1][j+1]*(1.0-p);
}
}
cout<<fixed;
cout<<setprecision(10)<<dp[k][0]<<endl;
return 0;
}
Codeforces Round 252 (Div. 2)的更多相关文章
- Codeforces Round #252 (Div. 2) B. Valera and Fruits(模拟)
B. Valera and Fruits time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #252 (Div. 2) D
http://codeforces.com/problemset/problem/441/D 置换群的基本问题,一个轮换内交换成正常顺序需要k-1次,k为轮换内元素个数 两个轮换之间交换元素,可以把两 ...
- codeforces Round #252 (Div. 2) C - Valera and Tubes
贪心算法,每条路径最短2格,故前k-1步每次走2格,最后一步全走完 由于数据比较小,可以先打表 #include <iostream> #include <vector> #i ...
- Codeforces Round #252 (Div. 2) B. Valera and Fruits
#include <iostream> #include <vector> #include <algorithm> #include <map> us ...
- Codeforces Round #252 (Div. 2) A - Valera and Antique Items
水题 #include <iostream> #include <set> #include <vector> #include <algorithm> ...
- CodeForces 441E(Codeforces Round #252 (Div. 2))
思路:dp[i][now][mark][len] i 表示当前第i 次now存的是后8位,mark为第9位为0还是1 len第九位往高位还有几位和第9位相等. 只存后8位的原因:操作只有200次 ...
- Codeforces Round #252 (Div. 2) 441B. Valera and Fruits
英语不好就是坑啊.这道题把我坑残了啊.5次WA一次被HACK.第二题得分就比第一题高10分啊. 以后一定要加强英语的学习,要不然就跪了. 题意:有一个果园里有非常多树,上面有非常多果实,为了不然成熟的 ...
- Codeforces Round #252 (Div. 2)-C,D
C题就是一个简单的模拟.首先给每一个人两个.然后把剩下的都给一个人就好了. 给的时候蛇形给. #include<stdio.h> #include<string.h> #inc ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
随机推荐
- [洛谷P2044][NOI2012]随机数生成器
题目大意:给你$m,a,c,X_0,n,g$,求$X_{n+1}=(a\cdot X_n+c) \bmod{m}$,最后输出对$g$取模 题解:矩阵快速幂+龟速乘,这里用了$long\;double$ ...
- 对web开发从业者的发展方向的思考
最近在读子柳的<淘宝技术这十年>,“牛P列传”这一章中介绍了很多淘宝技术发展史上做出重要贡献的“牛P人物”(阿里的技术岗按能力分级,从P1~P10). 读到采访小马的这一段: 子柳:畅想一 ...
- [Leetcode] candy 糖果
There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...
- LA4273 Post Offices
题目戳这里. 村庄排序.状态\(f[j][i]\)表示考虑前\(i\)个村庄,造\(j\)个邮局且\(i\)造了邮局的最小代价.我们用\(Lb_i,Rb_i\)表示在第\(i\)个村庄造邮局,邮局最左 ...
- 强大的JQuery数组封装使用
JQuery对数组的处理非常便捷并且功能强大齐全,一步到位的封装了很多原生js数组不能企及的功能.下面来看看JQuery数组的强大之处在哪. $.each(array, [callback]) 遍历 ...
- poj 1523 割点 tarjan
Description Consider the two networks shown below. Assuming that data moves around these networks on ...
- docker compose,link,Odoo
1.报错: /usr/bin/docker-current: Error response from daemon: driver failed programming external connec ...
- 纯手工 CheckboxTree 实现
数据结构及页面显示格式: INSERT INTO AS_CombRules VALUES('', '', '', '', '', '', '') 实现 CheckboxTree 功能: html代码: ...
- 最大流算法 ISAP 模板 和 Dinic模板
ISAP // UVa11248 Frequency Hopping:使用ISAP算法,加优化 // Rujia Liu struct Edge { int from, to, cap, flow; ...
- 线段树+矩阵快速幂 Codeforces Round #373 (Div. 2) E
http://codeforces.com/contest/719/problem/E 题目大意:给你一串数组a,a[i]表示第i个斐波那契数列,有如下操作 ①对[l,r]区间+一个val ②求出[l ...