layout: post

title: Codeforces Round 252 (Div. 2)

author: "luowentaoaa"

catalog: true

tags:

mathjax: true

- codeforces

- 群论

传送门

A.Valera and Antique Items (签到)

题意

如果当前钱数比一组数中最小的还要大就+1

思路

直接模拟

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const ll mod=1e9+7;
  5. const int maxn=1e6+50;
  6. const ll inf=0x3f3f3f3f3f3f3f3fLL;
  7. vector<int>ve;
  8. int main()
  9. {
  10. std::ios::sync_with_stdio(false);
  11. std::cin.tie(0);
  12. std::cout.tie(0);
  13. int n,v,ans=0;
  14. cin>>n>>v;
  15. for(int i=1;i<=n;i++){
  16. int t,f=0;
  17. cin>>t;
  18. for(int j=1;j<=t;j++){
  19. int a;cin>>a;
  20. if(a<v)f=1;
  21. }
  22. if(f)ans++,ve.push_back(i);
  23. }
  24. cout<<ans<<endl;
  25. for(int i=0;i<ans;i++)cout<<ve[i]<<" ";
  26. return 0;
  27. }

B.Valera and Fruits (模拟)

题意

n天,每天有一些水果,水果保质期为两天,你一天最多手机K个水果问你最多收集几个水果

题解

直接搞两个数组模拟就行。优先把昨天的收集

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const ll mod=1e9+7;
  5. const int maxn=1e6+50;
  6. const ll inf=0x3f3f3f3f3f3f3f3fLL;
  7. int sum[maxn];
  8. int ex[maxn];
  9. int main()
  10. {
  11. std::ios::sync_with_stdio(false);
  12. std::cin.tie(0);
  13. std::cout.tie(0);
  14. int n,v;cin>>n>>v;
  15. int mx=0;
  16. for(int i=1;i<=n;i++){
  17. int time,num;
  18. cin>>time>>num;
  19. sum[time]+=num;
  20. mx=max(mx,time);
  21. }
  22. mx++;int ans=0;
  23. for(int i=1;i<=mx;i++){
  24. int remain=v;
  25. if(ex[i]>=remain){
  26. ans+=remain;
  27. ex[i+1]+=sum[i];
  28. }
  29. else{
  30. ans+=ex[i];
  31. remain-=ex[i];
  32. if(sum[i]>=remain){
  33. ans+=remain;
  34. ex[i+1]+=sum[i]-remain;
  35. }
  36. else{
  37. ans+=sum[i];
  38. }
  39. }
  40. }
  41. cout<<ans;
  42. return 0;
  43. }

C.Valera and Tubes (模拟)

题意

用面积大于2并且连续的正好k个水管填满整个矩形

思路

因为水管可以弯曲,先用K-1面积为2的水管,然后用剩余的用一个水管填满就行


  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const ll mod=1e9+7;
  5. const int maxn=1e6+50;
  6. const ll inf=0x3f3f3f3f3f3f3f3fLL;
  7. vector<int>x,y;
  8. int main()
  9. {
  10. std::ios::sync_with_stdio(false);
  11. std::cin.tie(0);
  12. std::cout.tie(0);
  13. int n,m,k;
  14. cin>>n>>m>>k;
  15. for(int i=1;i<=n;i++){
  16. if(i&1){
  17. for(int j=1;j<=m;j++)x.push_back(i),y.push_back(j);
  18. }
  19. else{
  20. for(int j=m;j>=1;j--)x.push_back(i),y.push_back(j);
  21. }
  22. }
  23. int cnt=0;
  24. for(int i=1;i<k;i++){
  25. cout<<"2"<<" ";
  26. cout<<x[cnt]<<" "<<y[cnt]<<" ";cnt++;
  27. cout<<x[cnt]<<" "<<y[cnt];cnt++;
  28. cout<<endl;
  29. }
  30. cout<<x.size()-cnt<<" ";
  31. for(int i=cnt;i<x.size();i++){
  32. cout<<x[i]<<" "<<y[i]<<" ";
  33. }
  34. return 0;
  35. }

D. Valera and Swaps(群论 置换群)

题意

给你一个排列,让你进行若干次对换使得新排列再进行最少K次对换回复最小排列

(1,2,3)

思路

1.对于一个环,最少需要进行环的长度-1次操作回复原排列,

2.让两个环合并之后,可以增加一次操作 比如4 + 3 =7 这样就是原本需要3+2=5 ->6次

3.让一个环拆开,可以减少一次操作 同上

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const ll mod=1e9+7;
  5. const int maxn=1e6+50;
  6. const ll inf=0x3f3f3f3f3f3f3f3fLL;
  7. int n,m;
  8. int p[maxn];
  9. int id[maxn];
  10. int cal(){
  11. fill(id+1,id+1+n,0);
  12. int ans=0,cnt=0;
  13. for(int i=1;i<=n;i++){
  14. if(id[i])continue;
  15. id[i]=++cnt;
  16. int num=0;
  17. for(int j=p[i];!id[j];j=p[j]){
  18. id[j]=id[i];
  19. num++;
  20. }
  21. ans+=num;
  22. }
  23. return ans;
  24. }
  25. vector<pair<int,int> >ans;
  26. int main()
  27. {
  28. std::ios::sync_with_stdio(false);
  29. std::cin.tie(0);
  30. std::cout.tie(0);
  31. cin>>n;
  32. for(int i=1;i<=n;i++){
  33. cin>>p[i];
  34. }
  35. int m;cin>>m;
  36. while(true){
  37. int now=cal();
  38. if(now==m)break;
  39. else if(now<m){
  40. for(int i=2;i<=n;i++){
  41. if(id[i]!=id[1]){
  42. swap(p[i],p[1]);
  43. ans.push_back(make_pair(1,i));
  44. break;
  45. }
  46. }
  47. }
  48. else{
  49. int f=-1;
  50. for(int i=1;i<=n;i++){
  51. if(p[i]!=i){
  52. f=i;break;
  53. }
  54. }
  55. for(int j=f+1;j<=n;j++){
  56. if(id[f]==id[j]){
  57. swap(p[f],p[j]);
  58. ans.push_back(make_pair(f,j));
  59. break;
  60. }
  61. }
  62. }
  63. }
  64. cout<<ans.size()<<endl;
  65. for(int i=0;i<ans.size();i++)
  66. cout<<ans[i].first<<" "<<ans[i].second<<" ";
  67. return 0;
  68. }

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)

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int maxn=1e5+50;
  5. ll x,k;
  6. double p;
  7. double dp[500][500];
  8. int flag[550][550];
  9. int main()
  10. {
  11. cin>>x>>k>>p;
  12. p/=100.0;
  13. for(int i=0;i<=k;i++){
  14. int o=i+x;
  15. while(o%2==0){
  16. dp[0][i]++;
  17. o/=2;
  18. }
  19. }
  20. for(int i=1;i<=k;i++){
  21. for(int j=0;j<=k;j++){
  22. dp[i][j<<1]+=(dp[i-1][j]+1)*p;
  23. dp[i][j]+=dp[i-1][j+1]*(1.0-p);
  24. }
  25. }
  26. cout<<fixed;
  27. cout<<setprecision(10)<<dp[k][0]<<endl;
  28. return 0;
  29. }

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. 关于Maven项目install时出现No compiler is provided in this environment的处理

    关于Maven项目build时出现No compiler is provided in this environment的处理 新配置的Eclipse环境,运行现有项目没问题,一日,从svn上检出了一 ...

  2. Codeforces Round #525 (Div. 2)D. Ehab and another another xor problem

    D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Descripti ...

  3. bzoj 2304 [Apio2011]寻路 Dij+模拟+恶心建图

    [Apio2011]寻路 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 624  Solved: 193[Submit][Status][Discus ...

  4. Qt5 界面中文乱码问题

    1.文件所在项目文件  xxx.pro 中添加: QMAKE_CXXFLAGS += -execution-charset:utf- 2.文件以 UTF-8 编码保存 3.添加  utf-8 BOM

  5. Extend the size of ext3 partition online in VM

    1. Increase disk space in vCenter 2. scan disk on the Linux VM # fdisk -lu > /tmp/fdisk. # > / ...

  6. 使用vue做移动app时,调用摄像头扫描二维码

    现在前端技术发展飞快,前端都能做app了,那么项目中,也会遇到调用安卓手机基层的一些功能,比如调用摄像头,完成扫描二维码功能 下面我就为大家讲解一下,我在项目中调用这功能的过程. 首先我们需要一个中间 ...

  7. 【CodeForces】841D. Leha and another game about graph(Codeforces Round #429 (Div. 2))

    [题意]给定n个点和m条无向边(有重边无自环),每个点有权值di=-1,0,1,要求仅保留一些边使得所有点i满足:di=-1或degree%2=di,输出任意方案. [算法]数学+搜索 [题解] 最关 ...

  8. 【POJ 1719】 Shooting Contest (二分图匹配)

    题目链接 把每一列能射的两行和这一列连边,然后跑一边匈牙利就行了. #include <cstdio> #include <cstring> #include <algo ...

  9. mobius反演讲解

    mobius反演的基本形式为,假设知道函数F(x)=Σf(d) d|x,那么我们可以推出f(x)=Σmiu(d)*F(x/d) d|x,另一基本形式为假设知道函数F(x)=Σf(d) x|d,那么我们 ...

  10. HoneyPy 模拟Nginx服务器脚本

    HoneyPy是一个Python写的低交互式蜜罐,可以通过自定义Plugins的方式来配置不同的场景.这里是一个模拟Nginx空白页面的代码: # Auth xiaoxiaoleo # http:// ...