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. Unity Rigidbody 刚体中的Angular Drag和Freeze Position/Rotation

    Rigidbody中 Angular Drag  (角阻力):同样指的是空气阻力,只不过是用来阻碍物体旋转的.如果设置成无限的话,物体会立即停止旋转.如果设置成0,物体在上升过程中,会发生侧翻旋转. ...

  2. Win8、Win10进入SQL server配置管理器

    使用 WIN8.WIN10 访问 SQL Server 配置管理器 因为 SQL Server 配置管理器是 Microsoft 管理控制台程序的一个管理单元而不是单独的程序,所以,当运行 Windo ...

  3. Git sparse checkout

    Git的sparse checkout在clone项目仓库时只clone指定路径下的信息. 步骤如下: (1) mkdir yourdir(2) cd yourdir(3) git init(4) g ...

  4. (转)Single Instance Form in a MDI application

    private void OpenForm<T>() where T : Form, new() { T frm = (T)new List<Form>(this.MdiChi ...

  5. (转)C# 数据类型映射 (SQLite,MySQL,MSSQL,Oracle)

    一.C# vs SQLite: C# SQLite 字段名 类型 库类型 GetFieldType(#) 转换 备注 F_BOOL bool BIT NOT NULL Boolean F_BOOL_N ...

  6. TransparentBlt函数的使用注意事项

    今天客户需要在软件上需要添加一个自己公司的Logo,要求使用镂空透明的形式展现,本来以为很简单的工作没想到在MFC下这么复杂.Logo为BMP格式,白色背景. 以为和在按钮上显示控件差不多,先导入BI ...

  7. 3月3日(2) Search Insert Position

    这题...有点简单吧,为什么只有34%的通过率? 题目意思简单说就是查找index,或者按升序插入的未知,WA一次,罪过,下次要特别注意程序里变量的变化,提交前用样例检查. 简单的我有点不好意思贴代码 ...

  8. bzoj 3626 LCA

    这一道题咋一看只觉得是离线,可以求出所有的f(1,i,z), 答案就等于f(1,r,z)-f(1,l-1,z).但是没有具体的做法,但是求LCA的深度和有一个非常巧妙的做法,每加一个点,就把这个点到根 ...

  9. MFC的规则DLL与扩展DLL

    一.MFC规则DLL     MFC规则DLL可以在该dll内部使用MFC,但是与应用程序的接口不能是MFC的.能够被所有支持dll的编程语言所写的应用程序使用,当然也包括使用MFC创建的应用程序.在 ...

  10. app配置智能硬件的解决方案

    随着越来越多的智能硬件产品上市,越来越多的硬件都戴上了智能的帽子,什么智能插座,智能音箱,智能称等等.凡是所谓的智能,都是通过wifi或者蓝牙来连接互联网,其中蓝牙也只能算是手机的附属品吧.主要还是硬 ...