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的更多相关文章

  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. 【转载】LinkedIn是如何优化Kafka的

    http://www.wtoutiao.com/p/18d5RY0.html 在LinkedIn的数据基础设施中,Kafka是核心支柱之一.来自LinkedIn的工程师曾经就Kafka写过一系列的专题 ...

  2. Httpclient 和jsoup结和提取网页内容(某客学院视频链接)

    最近在极客学院获得体验会员3个月,然后就去上面看了看,感觉课程讲的还不错.整好最近学习Android,然后去上面找点视频看看.发现只有使用RMB买的会员才能在上面下载视频.抱着试一试的态度,去看他的网 ...

  3. 把CheckedListBoxControl设置为单选框

    private void chkControl_ItemChecking(object sender, DevExpress.XtraEditors.Controls.ItemCheckingEven ...

  4. Contoso 大学 - 3 - 排序、过滤及分页

    原文 Contoso 大学 - 3 - 排序.过滤及分页 目录 Contoso 大学 - 使用 EF Code First 创建 MVC 应用 原文地址:http://www.asp.net/mvc/ ...

  5. Swift中的循环语句

    循环语句能够使程序代码重复执行.Swift编程语言支持4种循环构造类型:while.do while.for和for in.for和while循环是在执行循环体之前测试循环条件,而do while是在 ...

  6. SOA 的基本概念及设计原则浅议

    SOA是英文词语"Service Oriented Architecture"的缩写,中文有多种翻译,如"面向服务的体系结构"."以服务为中心的体系结 ...

  7. spring aop配置文档部分翻译

    欢迎转载交流: http://www.cnblogs.com/shizhongtao/p/3476973.html 下面的文字来自官方文档的翻译,具体事例以后奉上. Advisors "ad ...

  8. Linux设备总线

    kobject和kset是Linux设备模型中最基本的元素,其中,kset是同种类型kobject对象的集合.每个在内核中注册的kobject对象都对于sysfs文件系统中的一个目录.下面是自己花的一 ...

  9. 模板:Set类

    头文件: #include <set> 定义: Set<string> set1; 添加: set1.insert("the"); 查询/获取元素 set1 ...

  10. Linux 信号量 生产者消费者小例题

    菜鸟偶遇信号量,擦出火花(只有不熟才会有火花).于是上网搜资料和看<Unix环境高级编程>实现了几个小例题,高手请勿喷!这几位写得非常好啊: 题目来源: http://www.it165. ...