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. jQuery性能优化(转)

    摘要:jQuery是我们经常使用的强大的JS类库,因此它的性能优化十分重要,下面就重几点来说明 原文作者:szyuxueliang    原文地址:http://www.cnblogs.com/yxl ...

  2. 初话C++模板【用自己的话,解释清楚这些】

    用自己的话解释清楚C++的模板编程 模板编程是为了解决什么问题而出现的? 提高代码的重用性,提高代码的利用率. 泛型编程的一种实现. 模板的精神是: 类型参数化. 模板的实现 模板分为:函数模板.类模 ...

  3. Bresenham算法画填充圆及SDL代码实现

    画圆是计算机图形操作中一个非常重要的需求.普通的画圆算法需要大量的浮点数参与运算,而众所周知,浮点数的运算速度远低于整形数.而最终屏幕上影射的像素的坐标均为整形,不可能是连续的线,所以浮点数运算其实纯 ...

  4. sqlserver 大文件脚本执行

    sqlserver2008中需要执行大文件的脚本,查询分析器中打不开,需要用到sql命令,开始使用osql命令,不过提示对应sqlserver2008中的驱动找不到(具体原因未分析-空闲时在处理),使 ...

  5. 重学C++ (1)

    写在开头的话:这学期没有写太多的代码,终于把中英文两篇论文弄完了,趁着中间的空隙,想想找工作的处境.自己也定了自己的方向.不管学什么语言吧,每个语言都有自己的优势和使用的群体.只要自己是良马,终会有伯 ...

  6. jQuery自己编写插件()

    引言: 在项目中不同页面经常要用到已经写好的交互,比如弹窗,比如下拉菜单,比如选项卡,比如删除... 此时如果每次都把代码copy一份无疑是一件比较麻烦并且无趣的事情,而且个人认为有些low了,我们可 ...

  7. Winform程序只允许运行一个程序实例

    /// <summary> /// 应用程序的主入口点. /// </summary> [STAThread] static void Main() { Application ...

  8. C#源码大汇总

    C#高仿QQ2013可在广域网部署聊天系统GG叽叽 动态显示硬盘分区容量饼图 自定义ProgressBar控件高仿Win8进度条 多皮肤精美在线QQ悬浮客服插件 jQuery仿天猫首页多格焦点图片轮播 ...

  9. 静态页面中如何传json数据

    首页传递参数组装成json数据,再编码 var param="{type:'"+type+"',text:'"+select_text+"',sele ...

  10. 当前标识(NT AUTHORITY\NETWORK SERVICE)没有对“C:\WINDOWS2\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files”的写访问权限。

    卸载了域控制器之后,IIS出现“当前标识(NT AUTHORITY\NETWORK SERVICE)没有对“C:\WINDOWS2\Microsoft.NET\Framework\v4.0.30319 ...