PROBLEM D - Round Subset

  OvO http://codeforces.com/contest/837/problem/D

  837D

  DP,

  dp[i][j]代表已经选择了i个元素,当2的个数为j的时候5的个数的最大值

  得注意最大值(貌似因为这个喵呜了一大片喵~☆)

 

  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <cmath>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. typedef long long ll;
  10.  
  11. const int M=64*202;
  12. const int N=M-2;
  13.  
  14. int n,k;
  15. int f[222][M]; //f[i][j] used num=i, sum of k2=j, val of f[i][j] = max sum of k5
  16. int k2[222],k5[222];
  17.  
  18. void init()
  19. {
  20. memset(k2,0,sizeof(k2));
  21. memset(k5,0,sizeof(k5));
  22. memset(f,-1,sizeof(f));
  23. }
  24.  
  25. int main()
  26. {
  27. int i,j,t;
  28. ll tmp;
  29. cin>>n>>k;
  30. init();
  31. for(i=1;i<=n;i++)
  32. {
  33. scanf("%I64d",&tmp);
  34. while(tmp%2==0)
  35. tmp/=2,k2[i]++;
  36. while(tmp%5==0)
  37. tmp/=5,k5[i]++;
  38. }
  39. f[0][0]=0;
  40. for(i=1;i<=n;i++)
  41. for(j=k;j>=1;j--)
  42. for(t=N;t>=k2[i];t--)
  43. if(f[j-1][t-k2[i]]!=-1)
  44. f[j][t]=max(f[j][t],f[j-1][t-k2[i]]+k5[i]);
  45. int ans=0;
  46. for(t=0;t<=N;t++)
  47. ans=max(ans,min(t,f[k][t]));
  48. cout<<ans<<endl;
  49. return 0;
  50. }

 

PROBLEM E - Round Subset

  OvO http://codeforces.com/contest/837/problem/E

  837E

  当B和A公约数不为1的时候(开始的时候,或者B减了一定次数1的时候),就相当于A和B同除以gcd(A,B),然后B继续一次减1。

  这样只要每次计算出每次B要减多少次1才能和A有不为1的公约数。

  那么预处理出A的质因数,然后每次对A的质因数判断一下,哪个最近(也就是模最小)即可。

  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <cstdio>
  6.  
  7. using namespace std;
  8.  
  9. typedef long long ll;
  10.  
  11. const ll M=1e6+44;
  12. const ll inf=1e18;
  13.  
  14. ll A,B;
  15. ll prim[M];
  16. ll lp,nump[M];
  17. ll ans;
  18.  
  19. void init(ll spl)
  20. {
  21. ll i,j;
  22. lp=0;
  23. for(i=2;i*i<=spl;i++)
  24. if(spl%i==0)
  25. {
  26. prim[++lp]=i;
  27. nump[lp]=0;
  28. while(spl%i==0)
  29. spl/=i,nump[lp]++;
  30. }
  31. if(spl!=1)
  32. {
  33. prim[++lp]=spl;
  34. nump[lp]=1;
  35. }
  36. }
  37.  
  38. void deal()
  39. {
  40. if(B==0)
  41. return ;
  42. if(A==1)
  43. {
  44. ans+=B;
  45. return ;
  46. }
  47. ll i,j,mn;
  48. ll tmp,gcd;
  49. mn=inf;
  50. for(i=1;i<=lp;i++)
  51. {
  52. tmp=B%prim[i];
  53. if(tmp<mn)
  54. mn=tmp;
  55. }
  56. tmp=mn;
  57. ans+=tmp;
  58. B-=tmp;
  59. gcd=__gcd(A,B);
  60. A/=gcd; B/=gcd;
  61. for(i=1;i<=lp;i++)
  62. if(gcd%prim[i]==0)
  63. {
  64. while(gcd%prim[i]==0)
  65. gcd/=prim[i],nump[i]--;
  66. if(nump[i]==0)
  67. {
  68. swap(nump[i],nump[lp]);
  69. swap(prim[i],prim[lp]);
  70. lp--; i--;
  71. }
  72. }
  73. deal();
  74. }
  75.  
  76. void solve()
  77. {
  78. ans=0;
  79. deal();
  80. printf("%I64d\n",ans);
  81. }
  82.  
  83. int main()
  84. {
  85. scanf("%I64d%I64d",&A,&B);
  86. init(A);
  87. solve();
  88. return 0;
  89. }

  

  

PROBLEM F - Prefix Sums

  OvO http://codeforces.com/contest/837/problem/F

  837F

  由于新生成的m+1个数列第一个肯定为0,所以可以忽略掉,当作每次新生成的数列只拥有m个元素

  然后 举个栗子

  当s={1,0,0,0,0} 可以得到如下矩阵

  

  显然这拥有某神秘三角的性质

  然后二分答案,每次通过组合数来算就行了,由于太大直接退出,所以不会超时(如果C(p,q),p-q<q的话,转化为C(p,p-q))

  

  1. #include <iostream>
  2. #include <cstring>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <cstdio>
  6.  
  7. using namespace std;
  8.  
  9. typedef long long ll;
  10.  
  11. const ll M=2e5+44;
  12.  
  13. ll n,k;
  14. ll sum;
  15. ll s[M];
  16.  
  17. bool check(ll spl)
  18. {
  19. ll i,j,t,x,y,p,q;
  20. double sum=0,tmp;
  21. for(t=0;t<n;t++)
  22. {
  23. if(s[t]==0) continue;
  24. x=spl; y=(n-1)-t; //s[i]*c(y+x-1,x-1)
  25. p=x-1; q=x+y-1; //c(q,p)
  26. p=min(q-p,p);
  27. tmp=s[t];
  28. for(i=q,j=p;j>=1;j--,i--)
  29. {
  30. tmp=tmp*i/j;
  31. if(tmp>=k)
  32. return true;
  33. }
  34. sum+=tmp;
  35. if(sum>=k) return true;
  36. }
  37. return false;
  38. }
  39.  
  40. void solve()
  41. {
  42. ll li=0,ri=k,mid;
  43. while(li<ri-1)
  44. {
  45. // cout<<li<<' '<<ri<<endl;
  46. mid=(li+ri)>>1;
  47. if(check(mid))
  48. ri=mid;
  49. else
  50. li=mid;
  51. }
  52. cout<<ri<<endl;
  53. }
  54.  
  55. int main()
  56. {
  57. ll i,j,tmp;
  58. cin>>n>>k;
  59. for(i=0;i<n;i++)
  60. {
  61. scanf("%I64d",&s[i]);
  62. if(s[i]>=k)
  63. {
  64. printf("0\n");
  65. return 0;
  66. }
  67. }
  68. solve();
  69. return 0;
  70. }

  

Educational Codeforces Round 26 [ D. Round Subset ] [ E. Vasya's Function ] [ F. Prefix Sums ]的更多相关文章

  1. 【动态规划】【滚动数组】Educational Codeforces Round 26 D. Round Subset

    给你n个数,让你任选K个,使得它们乘起来以后结尾的0最多. 将每个数的因子2和因子5的数量求出来,记作a[i]和b[i]. 答案就是max{ min{Σa[i],Σb[i]} }(a[i],b[i]是 ...

  2. Educational Codeforces Round 26 F. Prefix Sums 二分,组合数

    题目链接:http://codeforces.com/contest/837/problem/F 题意:如题QAQ 解法:参考题解博客:http://www.cnblogs.com/FxxL/p/72 ...

  3. CodeForces 837D - Round Subset | Educational Codeforces Round 26

    /* CodeForces 837D - Round Subset [ DP ] | Educational Codeforces Round 26 题意: 选k个数相乘让末尾0最多 分析: 第i个数 ...

  4. Educational Codeforces Round 26

    Educational Codeforces Round 26 困到不行的场,等着中午显示器到了就可以美滋滋了 A. Text Volume time limit per test 1 second ...

  5. CodeForces 837F - Prefix Sums | Educational Codeforces Round 26

    按tutorial打的我血崩,死活挂第四组- - 思路来自FXXL /* CodeForces 837F - Prefix Sums [ 二分,组合数 ] | Educational Codeforc ...

  6. CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26

    /* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...

  7. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  8. Educational Codeforces Round 60 (Rated for Div. 2) 题解

    Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...

  9. Educational Codeforces Round 58 (Rated for Div. 2) 题解

    Educational Codeforces Round 58 (Rated for Div. 2)  题目总链接:https://codeforces.com/contest/1101 A. Min ...

随机推荐

  1. Mysql创建、使用循环函数

    创建函数 create procedure names() begin declare i int default 0; while i < 3000 do INSERT INTO studen ...

  2. redis 命令 setbit、bitcount、getbit、bitop

    1.SETBIT key offset value 对 key 所储存的字符串值,设置或清除指定偏移量上的位(bit). 在redis中,存储的字符串都是以二级制的进行存在的. 举例: 设置一个 ke ...

  3. List 集合 一行4个排序

    List<string> list = new List<string>(); ; i < ; i++) { list.Add(i.ToString()); } int ...

  4. 适配方案(二)之PC端适配

    PC端 特点 PC端的屏幕具备以下特点: 屏幕大小一般是大于 13.3英寸 用户会经常拖拉浏览器的大小 原因 正是因为 PC端上的浏览器大小会经常被改变,而且改变的范围还很大,用户会全屏浏览器,用户也 ...

  5. 向PHP发送HTTP-Get请求

    1.get.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  6. WebStrom 中文显示异常中文变样乱码

    问题描述 WebStorm 编辑文件时中文显示异常,大小不一 菜单栏字体需要更换 解决方法 修改编辑器字体 菜单栏默认字体取消 设置效果 编辑文件时中英文显示 菜单栏 其他相关 关于编码格式,这里未做 ...

  7. Anaconda--机器学习环境搭建

    使用Anaconda为机器学习和深度学习设置Python环境 一.安装Anaconda,并更新到最新版本 1.Anaconda 安装: 官方网站下载地址 https://www.anaconda.co ...

  8. 一种移动端position:absolute布局:

    一种移动端position:absolute布局:   1.他父级不需要加上 position:relative; 如果父级不是不是body,则加position:absolute; 2.红色加量部分 ...

  9. JAVA 分布式

    什么是分布式系统? 要理解分布式系统,主要需要明白一下2个方面: 1.分布式系统一定是由多个节点组成的系统. 其中,节点指的是计算机服务器,而且这些节点一般不是孤立的,而是互通的. 2.这些连通的节点 ...

  10. hbase shell 基本操作

    hbase shell  基本操作 启动HBASE [hadoop@master ~]$hbase shell      2019-01-24 13:53:59,990 WARN  [main] ut ...