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 ...
随机推荐
- Setup Project 安装项目
从vs2012起,微软已经不支持setup project了.以此纪念一下setup project. 在新建Setup Project 增加安装内容,通常是直接Oupput一个项目,或者直接 ...
- MAC系统介绍
MACOS: UNIX系统图形界面的显示 开发环境: 一种是终端(terminal) 一种是Xcode(ide) MAC快捷键: command(window) + c : 复制 command + ...
- ASP.NET MVC3 使用kindeditor编辑器获取不到值
做开发真的是会遇到各种问题,如果不亲自尝试,不动手,很难发现问题. 下面我们说下在MVC中的用法 1,首先引入js文件 <script type="text/javascript&qu ...
- Entity Framework学习(一)
网上看了很多的资料,发现都不是想要的学习资料,讲的不是很明白,最后在msdn开始自己研究EF MSDN的地址 https://msdn.microsoft.com/zh-cn/library/gg69 ...
- Codevs 2296 仪仗队 2008年省队选拔赛山东
2296 仪仗队 2008年省队选拔赛山东 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 大师 Master 题解 题目描述 Description 作为体育委员,C君负责这次运动 ...
- undrop for innodb c_parser 不完美之处
今天发现c_parser导出数据是会丢掉某些行,给过调试发现是他处理utf8编码时计算有误,目前还没有发现自动解决总是的方法,只会手动改代码来解决. 下一步计划把c_parser移植到windows下 ...
- UML静态类图
0,主要分为类.接口.协作.关系,这四种元素.作用:a,显示类.接口以及他们之间的静态结构和关系:b,用于描述系统的结构化设计. 1,类 CStudent +m_strName : string +S ...
- java学习笔记_MIDI_GUI
import javax.sound.midi.*; import javax.swing.*; import java.awt.event.*; import java.awt.*; class M ...
- iOS 简单总结:description方法\NSLog函数
1.description方法是NSObject自带的方法,包括类方法和对象方法 + (NSString *)description; // 默认返回 类名 - (NSString *)descrip ...
- mysql 运行sql脚本文件
#只运行,不导出 mysql> source /home/user/to_run.sql; #导出 $ mysql -h host -u user -ppassword database < ...