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)的更多相关文章

  1. 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 ...

  2. Codeforces Round #252 (Div. 2) D

    http://codeforces.com/problemset/problem/441/D 置换群的基本问题,一个轮换内交换成正常顺序需要k-1次,k为轮换内元素个数 两个轮换之间交换元素,可以把两 ...

  3. codeforces Round #252 (Div. 2) C - Valera and Tubes

    贪心算法,每条路径最短2格,故前k-1步每次走2格,最后一步全走完 由于数据比较小,可以先打表 #include <iostream> #include <vector> #i ...

  4. Codeforces Round #252 (Div. 2) B. Valera and Fruits

    #include <iostream> #include <vector> #include <algorithm> #include <map> us ...

  5. Codeforces Round #252 (Div. 2) A - Valera and Antique Items

    水题 #include <iostream> #include <set> #include <vector> #include <algorithm> ...

  6. CodeForces 441E(Codeforces Round #252 (Div. 2))

    思路:dp[i][now][mark][len]   i 表示当前第i 次now存的是后8位,mark为第9位为0还是1 len第九位往高位还有几位和第9位相等.  只存后8位的原因:操作只有200次 ...

  7. Codeforces Round #252 (Div. 2) 441B. Valera and Fruits

    英语不好就是坑啊.这道题把我坑残了啊.5次WA一次被HACK.第二题得分就比第一题高10分啊. 以后一定要加强英语的学习,要不然就跪了. 题意:有一个果园里有非常多树,上面有非常多果实,为了不然成熟的 ...

  8. Codeforces Round #252 (Div. 2)-C,D

    C题就是一个简单的模拟.首先给每一个人两个.然后把剩下的都给一个人就好了. 给的时候蛇形给. #include<stdio.h> #include<string.h> #inc ...

  9. 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 ...

随机推荐

  1. P1717 钓鱼

    题目描述 话说发源于小朋友精心设计的游戏被电脑组的童鞋们藐杀之后非常不爽,为了表示安慰和鼓励,VIP999决定请他吃一次“年年大丰收”,为了表示诚意,他还决定亲自去钓鱼,但是,因为还要准备2013NO ...

  2. BZOJ1558 [JSOI2009]等差数列 【线段树】

    题目链接 BZOJ1558 题解 等差数列,当然是差分一下 差分值相同的连续位置形成等差数列,我们所选的两个等差数列之间可以有一个位置舍弃 例如: \(1 \; 2 \; 3 \; 6 \; 8 \; ...

  3. 如何开始创建第一个基于Spring MVC的Controller

    万事开头难,良好的开端是成功的一半! 以下示例怎么开始创建我们的第一个Spring MVC控制器Controller 1.新建一个java类,命名为:MyFirstController,包含以下代码, ...

  4. 树形DP小结

    树形DP1.简介:树是一种数据结构,因为树具有良好的子结构,而恰好DP是从最优子问题更新而来,那么在树上做DP操作就是从树的根节点开始深搜(也就是记忆化搜索),保存每一步的最优结果.tips:树的遍历 ...

  5. How to setup Active Directory (AD) In Windows Server 2016

    Windows Server 2016 is the newest server operating system released by Microsoft in October 12th, 201 ...

  6. js+json实现ajax实例

    前期准备: 安装wampserver或者其他相似软件来搭建本地集成安装环境 html.js.css等文件需要放置在wampserver中的www目录中,默认运行index页面 bootstrap.cs ...

  7. GET和POST本质上有什么区别,这才是标准答案

    不知道各位读者在面试的时候,有没有被问过这个问题:"请说一下GET和POST两者的本质区别".基本上做过WEB开发的,对这个问题,都可以回答出一堆的区别. 比如: 最直接的区别,G ...

  8. [51nod1009]数字1的数量

    解题关键:数位dp,对每一位进行考虑,通过过程得出每一位上1出现的次数 1位数的情况: 在解法二中已经分析过,大于等于1的时候,有1个,小于1就没有. 2位数的情况: N=13,个位数出现的1的次数为 ...

  9. c++对拍实现

    直接上代码吧. #include<bits/stdc++.h> using namespace std; int main(){ while(1){ system("./cute ...

  10. windows支持applocker的版本

    Operating system requirements   The following table show the on which operating systems AppLocker fe ...