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. 获取登录的IP或者信息

    这是转载的,也不想去检查性能,对于这些成熟的代码,发在这里完全是懒,仅此而已! 1.获取客户端IP /// <summary> /// 获取客户端Ip /// </summary&g ...

  2. UML——动态建模

  3. PullToRefreshListView手动刷新问题

    1.第一次进入界面刷新无效,需要延时刷新 new Handler().postDelayed(new Runnable() { @Override public void run() { // TOD ...

  4. 动态图片加到UIImageView中

    //1.添加一个.gif类型的动态的图片,用到URLForResource方法,gif是图片的格式,FlagZombie是图片的名字 @implementation ViewController- ( ...

  5. 3月3日[Go_deep]Populating Next Right Pointers in Each Node

    原题:Populating Next Right Pointers in Each Node 简单的链表二叉树增加Next节点信息,没什么坑.不过还是WA了两次,还是有点菜,继续做,另外leetcod ...

  6. 隐藏win7盘符

    1.隐藏盘符: //新建注册表,隐藏X盘符 int regeditme() { HKEY hkey; DWORD dwLastError= ;//隐藏X盘2^25 J:2^9=512 X:盘符与挂载的 ...

  7. DTCMS中部分IE8不支持webupload上传附件的控件,更改为ajaxfileupload

    dialog\dialog_attach.aspx <!DOCTYPE html> <html> <head> <meta http-equiv=" ...

  8. redis学习系列

    redis学习系列 基本看完 最近在看redis的代码,简单记录下自己认为重要的点,自己写比较费时间的,我会把查到的资料贴出来方便查看 淘宝的redis内存分析 http://www.searchtb ...

  9. python(六)面向对象

    1.封装 支持多重继承,但如果不需要的时候最好不要使用,避免出现不必要的bug: 2.继承 3.多态 4.构造函数 5.私有和共有 在属性前写两个下滑线定义就是私有的

  10. TCP三次握手原理与SYN攻击

    本文内容包括以下几点 1.TCP三次握手四次挥手解析 2.迭代型服务器程序编写,并给出客户端,结合这一模式详细介绍Berkeley套接字的使用 3.介绍SYN攻击的原理 TCP连接建立,传输数据,连接 ...