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. Linux相关——关于文件调用

    本文主要记录几个常见文件调用(表示为了造数据试了n种方法,,,发现了一些神奇的东西,会在下面一一说明. 首先在程序中我们可以打开和关闭程序. 常见的freopen用法简单,但是只能使用一次,如果在程序 ...

  2. [Leetcode] rotate image 旋转图片

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...

  3. 解决IE下页面空白或者报错:[vuex] vuex requires a Promise polyfill in this browser

    [vuex] vuex requires a Promise polyfill in this browser 上述错误的原因是不支持 Promise 方法,导致页面出现空白无法加载. 解决方法如下: ...

  4. HDU 多校对抗赛 J Time Zone

    Time Zone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  5. 怎么让Intellj Idea 把数据库的表映射成hibernate的domain对象

    步骤如下: 第一步:连接数据源: 点击:idea右边的database.如下图所示: 或者你依次点击:view-->Tool windows--->database 然后你将看在如下点击下 ...

  6. ACM-ICPC 2018 南京赛区网络预赛 Sum

    A square-free integer is an integer which is indivisible by any square number except 11. For example ...

  7. php windows rename 中文出错

    php windows rename 中文出错 rename()函数可以重命名文件.目录等,但是要注意目的地和起始地址的编码. 比如:我的PHP文件编码是UTF-8,但是在WINDOW系统中中文默认编 ...

  8. 「6月雅礼集训 2017 Day1」说无可说

    [题目大意] 给出n个字符串,求有多少组字符串之间编辑距离为1~8. n<=200,∑|S| <= 10^6 [题解] 首先找编辑距离有一个n^2的dp,由于发现只找小于等于8的,所以搜旁 ...

  9. 51nod 1020 逆序排列——dp

    在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序.一个排列中逆序的总数就称为这个排列的逆序数. 如2 4 3 1中,2 1,4 3,4 1,3 1是逆序 ...

  10. 【BZOJ 3907】网格(Catalan数)

    题目链接 这个题推导公式跟\(Catalan\)数是一样的,可得解为\(C_{n+m}^n-C_{n+m}^{n+1}\) 然后套组合数公式\(C_n^m=\frac{n!}{m!(n-m)!}\) ...