A. Co-prime Array

http://codeforces.com/contest/660/problem/A

题意:给出一段序列,插进一些数,使新的数列两两成互质数,求插最少的个数,并输出这个序列。

思路:最优的就是插入1,1与非1的数都互质。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int gcd(int a,int b){
  4. return b==?a:gcd(b,a%b);
  5. }
  6. int main(){
  7. int n,t=,a[],b[];
  8. scanf("%d",&n);
  9. for(int i=;i<n;i++){
  10. cin>>a[i];
  11. if(gcd(a[i],a[i-])!=)
  12. b[t++]=;
  13. b[t++]=a[i];
  14. }
  15. cout<<t-n<<endl;
  16. cout<<b[];
  17. for(int i=;i<t;i++)
  18. cout<<" "<<b[i];
  19. cout<<endl;
  20. return ;
  21. }

B. Seating On Bus

http://codeforces.com/contest/660/problem/B

题意:不是很懂题目意思,看样例找规律好了

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n,m;
  4. int main()
  5. {
  6. cin>>n>>m;
  7. for (int i=;i<=*n;i++)
  8. {
  9. if (*n+i<=m)
  10. cout<<*n+i<<' ';
  11. if (i<=m)
  12. cout<<i<<' ';
  13. }
  14. return ;
  15. }

C. Hard Process

http://codeforces.com/contest/660/problem/C

题意:给你k个机会,每次可以把一个0变成1,然后形成最长的都是1的子序列,输出变换后的序列

思路:dp和二分

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 1e6;
  4. int n,k;
  5. int a[maxn],sum[maxn];
  6. int main()
  7. {
  8. scanf("%d%d",&n,&k);
  9. for(int i=;i<=n;i++)
  10. {
  11. scanf("%d",&a[i]);
  12. a[i]=-a[i];//将数字互换是为了后面寻找0最多的序列
  13. }
  14. for(int i=;i<=n;i++)
  15. sum[i]=sum[i-]+a[i];
  16. int ans1=,ans2=;
  17. for(int i=;i<=n;i++)
  18. {
  19. int l = i,r = n,ans=;
  20. while(l<=r)
  21. {
  22. int mid=(l+r)/;
  23. if(sum[mid]-sum[i-]>k)r=mid-;
  24. else l=mid+,ans=mid-i+;//二分找到1尽可能多的地方
  25. }
  26. if(ans>ans1)
  27. {
  28. ans1=ans;
  29. ans2=i;
  30. }
  31. }
  32. cout<<ans1<<endl;
  33. for(int i=ans2;i<=n;i++)
  34. {
  35. if(ans1==)break;
  36. if(a[i]==)a[i]=;
  37. if(a[i]==)ans1--;
  38. }
  39. for(int i=;i<=n;i++)
  40. cout<<-a[i]<<" ";
  41. }

Educational Codeforces Round 11的更多相关文章

  1. Educational Codeforces Round 11 C. Hard Process 前缀和+二分

    题目链接: http://codeforces.com/contest/660/problem/C 题意: 将最多k个0变成1,使得连续的1的个数最大 题解: 二分连续的1的个数x.用前缀和判断区间[ ...

  2. Educational Codeforces Round 11 E. Different Subsets For All Tuples 动态规划

    E. Different Subsets For All Tuples 题目连接: http://www.codeforces.com/contest/660/problem/E Descriptio ...

  3. Educational Codeforces Round 11 D. Number of Parallelograms 暴力

    D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...

  4. Educational Codeforces Round 11 C. Hard Process 二分

    C. Hard Process 题目连接: http://www.codeforces.com/contest/660/problem/C Description You are given an a ...

  5. Educational Codeforces Round 11 B. Seating On Bus 水题

    B. Seating On Bus 题目连接: http://www.codeforces.com/contest/660/problem/B Description Consider 2n rows ...

  6. Educational Codeforces Round 11 A. Co-prime Array 水题

    A. Co-prime Array 题目连接: http://www.codeforces.com/contest/660/problem/A Description You are given an ...

  7. Educational Codeforces Round 11 B

    Description Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of th ...

  8. Educational Codeforces Round 11 _D

    http://codeforces.com/contest/660/problem/D 这个题据说是很老的题了 然而我现在才知道做法 用map跑了1953ms: 题目大意 给你n个点的坐标 求这些点能 ...

  9. Educational Codeforces Round 11 A

    A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...

随机推荐

  1. win2003域控制器密码遗忘如何修改

    在公司遇到这么个事儿,员工搭建QC服务器,设置了域账户登陆系统.但忘记了登录密码,使用PE直接修改sam文件不好用.   1.使用PE进系统修改组登陆方式的账号administrator密码 需符合复 ...

  2. OC1_点语法

    // // Dog.h // OC1_点语法 // // Created by zhangxueming on 15/6/16. // Copyright (c) 2015年 zhangxueming ...

  3. Factory Method模式

    Factory Method(工厂方法)模式属于GoF设计模式中的创建型分组,它用于在不之制定待创建对象的具体类的情况下创建对象.--<asp.net设计模式> 说白了就是一个人想要出国旅 ...

  4. 详解null

    前言 在java中初始化的时候经常用到null,也经常会碰到空指针异常(NullPointerException),由于碰到的频率比较高,我认为有必要进行一下了解,揭开它的神秘面纱. 一.null是代 ...

  5. lucene4入门(1)

    欢迎转载http://www.cnblogs.com/shizhongtao/p/3440325.html lucene你可以理解为一种数据库,他是全文搜索的一种引擎. 1.首先去官网download ...

  6. 致vi老大 2011.1

    文/安然 亲爱的,你即将离去 飞机起飞的一刻, 请珍藏起我们2010的回忆 桃源仙谷,曾留下我们踏青的足迹 难忘,石头上小憩 小北门外,我们在大排档里尽情欢喜 见证,杯盘狼藉 饺子店,是冬日里四面八方 ...

  7. Mac OS X开发者准备工作

    迁移到Mac平台做开发后,需要有一系列的准备工作来使我们的工作更顺畅. 1. 安装Homebrew包管理器 苹果系统自带了一个包管理器,但是并不是很好用.现在,现在比较流行的是Homebrew,非常好 ...

  8. PHP利用微信跳转的Code参数获取用户的openid

    //获取微信登录用户信息function getOpenID($appid,$appsecret,$code){   $url="https://api.weixin.qq.com/sns/ ...

  9. 解决xtraFinder在EI下不能使用问题

    在EI (10.11)下,由于SIP(System Integrity Protection)机制,导致一些第三方插件不能使用,如xtrafinder. 要想使用,在目前的情况下,启用的方法:一种是安 ...

  10. preventDefault()、stopPropagation()、return false 之间的区别

    “return false”之所以被误用的如此厉害,是因为它看起来像是完成了我们交给它的工作,浏览器不会再将我们重定向到href中的链接,表单也不会被继续提交,但这么做到底有什么不对呢? 可能在你刚开 ...