Educational Codeforces Round 11
A. Co-prime Array
http://codeforces.com/contest/660/problem/A
题意:给出一段序列,插进一些数,使新的数列两两成互质数,求插最少的个数,并输出这个序列。
思路:最优的就是插入1,1与非1的数都互质。
- #include<bits/stdc++.h>
- using namespace std;
- int gcd(int a,int b){
- return b==?a:gcd(b,a%b);
- }
- int main(){
- int n,t=,a[],b[];
- scanf("%d",&n);
- for(int i=;i<n;i++){
- cin>>a[i];
- if(gcd(a[i],a[i-])!=)
- b[t++]=;
- b[t++]=a[i];
- }
- cout<<t-n<<endl;
- cout<<b[];
- for(int i=;i<t;i++)
- cout<<" "<<b[i];
- cout<<endl;
- return ;
- }
B. Seating On Bus
http://codeforces.com/contest/660/problem/B
题意:不是很懂题目意思,看样例找规律好了
- #include<bits/stdc++.h>
- using namespace std;
- int n,m;
- int main()
- {
- cin>>n>>m;
- for (int i=;i<=*n;i++)
- {
- if (*n+i<=m)
- cout<<*n+i<<' ';
- if (i<=m)
- cout<<i<<' ';
- }
- return ;
- }
C. Hard Process
http://codeforces.com/contest/660/problem/C
题意:给你k个机会,每次可以把一个0变成1,然后形成最长的都是1的子序列,输出变换后的序列
思路:dp和二分
- #include<bits/stdc++.h>
- using namespace std;
- const int maxn = 1e6;
- int n,k;
- int a[maxn],sum[maxn];
- int main()
- {
- scanf("%d%d",&n,&k);
- for(int i=;i<=n;i++)
- {
- scanf("%d",&a[i]);
- a[i]=-a[i];//将数字互换是为了后面寻找0最多的序列
- }
- for(int i=;i<=n;i++)
- sum[i]=sum[i-]+a[i];
- int ans1=,ans2=;
- for(int i=;i<=n;i++)
- {
- int l = i,r = n,ans=;
- while(l<=r)
- {
- int mid=(l+r)/;
- if(sum[mid]-sum[i-]>k)r=mid-;
- else l=mid+,ans=mid-i+;//二分找到1尽可能多的地方
- }
- if(ans>ans1)
- {
- ans1=ans;
- ans2=i;
- }
- }
- cout<<ans1<<endl;
- for(int i=ans2;i<=n;i++)
- {
- if(ans1==)break;
- if(a[i]==)a[i]=;
- if(a[i]==)ans1--;
- }
- for(int i=;i<=n;i++)
- cout<<-a[i]<<" ";
- }
Educational Codeforces Round 11的更多相关文章
- Educational Codeforces Round 11 C. Hard Process 前缀和+二分
题目链接: http://codeforces.com/contest/660/problem/C 题意: 将最多k个0变成1,使得连续的1的个数最大 题解: 二分连续的1的个数x.用前缀和判断区间[ ...
- 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 ...
- Educational Codeforces Round 11 D. Number of Parallelograms 暴力
D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...
- Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process 题目连接: http://www.codeforces.com/contest/660/problem/C Description You are given an a ...
- Educational Codeforces Round 11 B. Seating On Bus 水题
B. Seating On Bus 题目连接: http://www.codeforces.com/contest/660/problem/B Description Consider 2n rows ...
- 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 ...
- 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 ...
- Educational Codeforces Round 11 _D
http://codeforces.com/contest/660/problem/D 这个题据说是很老的题了 然而我现在才知道做法 用map跑了1953ms: 题目大意 给你n个点的坐标 求这些点能 ...
- Educational Codeforces Round 11 A
A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
随机推荐
- win2003域控制器密码遗忘如何修改
在公司遇到这么个事儿,员工搭建QC服务器,设置了域账户登陆系统.但忘记了登录密码,使用PE直接修改sam文件不好用. 1.使用PE进系统修改组登陆方式的账号administrator密码 需符合复 ...
- OC1_点语法
// // Dog.h // OC1_点语法 // // Created by zhangxueming on 15/6/16. // Copyright (c) 2015年 zhangxueming ...
- Factory Method模式
Factory Method(工厂方法)模式属于GoF设计模式中的创建型分组,它用于在不之制定待创建对象的具体类的情况下创建对象.--<asp.net设计模式> 说白了就是一个人想要出国旅 ...
- 详解null
前言 在java中初始化的时候经常用到null,也经常会碰到空指针异常(NullPointerException),由于碰到的频率比较高,我认为有必要进行一下了解,揭开它的神秘面纱. 一.null是代 ...
- lucene4入门(1)
欢迎转载http://www.cnblogs.com/shizhongtao/p/3440325.html lucene你可以理解为一种数据库,他是全文搜索的一种引擎. 1.首先去官网download ...
- 致vi老大 2011.1
文/安然 亲爱的,你即将离去 飞机起飞的一刻, 请珍藏起我们2010的回忆 桃源仙谷,曾留下我们踏青的足迹 难忘,石头上小憩 小北门外,我们在大排档里尽情欢喜 见证,杯盘狼藉 饺子店,是冬日里四面八方 ...
- Mac OS X开发者准备工作
迁移到Mac平台做开发后,需要有一系列的准备工作来使我们的工作更顺畅. 1. 安装Homebrew包管理器 苹果系统自带了一个包管理器,但是并不是很好用.现在,现在比较流行的是Homebrew,非常好 ...
- PHP利用微信跳转的Code参数获取用户的openid
//获取微信登录用户信息function getOpenID($appid,$appsecret,$code){ $url="https://api.weixin.qq.com/sns/ ...
- 解决xtraFinder在EI下不能使用问题
在EI (10.11)下,由于SIP(System Integrity Protection)机制,导致一些第三方插件不能使用,如xtrafinder. 要想使用,在目前的情况下,启用的方法:一种是安 ...
- preventDefault()、stopPropagation()、return false 之间的区别
“return false”之所以被误用的如此厉害,是因为它看起来像是完成了我们交给它的工作,浏览器不会再将我们重定向到href中的链接,表单也不会被继续提交,但这么做到底有什么不对呢? 可能在你刚开 ...