Codeforces Education Round 11
A(模拟+数学)
题意:在一个数列当中最少添加多少个数可以使它们两两互质,并打印出添加以后的数列
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
const int maxn=;
const int maxm=;
int a[maxn];
int gcd(int a,int b)
{
if(b==) return a;
return gcd(b,a%b);
}
int n;
int main()
{
while(cin>>n)
{
for(int i=;i<n;i++)
scanf("%d",&a[i]);
vector<int>b;
int cnt=;
for(int i=;i<n-;i++)
{
if(gcd(a[i],a[i+])>=){
cnt++;
int k;
for(int j=;j<=maxm;j++){
if(gcd(a[i],j)<&&gcd(j,a[i+])<){
k=j; break;
}
}
b.push_back(a[i]);
b.push_back(k);
}
else{
b.push_back(a[i]);
}
}
b.push_back(a[n-]);
cout<<cnt<<endl;
for(int i=;i<b.size()-;i++)
cout<<b[i]<<" ";
cout<<b[b.size()-]<<endl;
}
return ;
}
B(队列模拟)
题意:根据公交车上下车的顺序,打印下车的顺序
分析:用队列直接进行模拟即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
const int maxn=;
int a[maxn][];
int n,m;
int main()
{
while(cin>>n>>m)
{
queue<int>que[];
int k=;
int cnt=;
for(;;)
{
if(cnt>=n) break;
if(k>m) break;
que[].push(k);
k++;
if(k>m) break;
que[].push(k);
k++;
cnt++;
}
for(;;)
{
if(k>m) break;
que[].push(k);
k++;
if(k>m) break;
que[].push(k);
k++;
}
vector<int>b;
int t;
int f1=,f2=,f3=,f4=;
for(;;)
{
if(que[].empty()){
f2=;
}else{
t=que[].front();
que[].pop();
b.push_back(t);
}
if(que[].empty()){
f1=;
}else{
t=que[].front();
que[].pop();
b.push_back(t);
}
if(que[].empty()){
f3=;
}else{
t=que[].front();
que[].pop();
b.push_back(t);
}
if(que[].empty()){
f4=;
}else{
t=que[].front();
que[].pop();
b.push_back(t);
}
if(f1&&f2&&f3&&f4) break;
}
for(int i=;i<b.size()-;i++)
cout<<b[i]<<" ";
cout<<b[b.size()-]<<endl;
}
return ;
}
C(dp+统计)
题意:有一由0与1组成的串,可以将其中的k个0改为1,问最长的连续1的串为多长
分析:这道题看了题解,对于区间[l,r]来说统计其上0的个数是否会大于k,若小于k,则区间[l+1,r]上个数也小于k。所以我们统计区间[1,n]上0个数小于k的最长区间即可。统计的时候才用二分思想,从l和r两个方向同步进行
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
const int maxn=;
int a[maxn];
int dp[maxn];
int main()
{
int n,k;
while(cin>>n>>k)
{
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
if(!a[i]) //统计0到i中0的个数
dp[i]=dp[i-]+;
else
dp[i]=dp[i-];
}
int left=,right=,mx=,j=;
for(int i=;i<=n;i++)
{
while(dp[i]-dp[j]>k) j++;
if(mx<i-j)
{
mx=i-j;
left=j+;
right=i;
}
}
cout<<mx<<endl;
for(;left<=right;left++) a[left]=;
for(int i=;i<n;i++)
printf("%d ",a[i]);
printf("%d\n",a[n]);
}
return ;
}
Codeforces Education Round 11的更多相关文章
- Codeforces Global Round 11 个人题解(B题)
Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...
- Codeforces Beta Round #11 B. Jumping Jack 数学
B. Jumping Jack 题目连接: http://www.codeforces.com/contest/11/problem/B Description Jack is working on ...
- Codeforces Beta Round #11 A. Increasing Sequence 贪心
A. Increasing Sequence 题目连接: http://www.codeforces.com/contest/11/problem/A Description A sequence a ...
- 状压dp找寻环的个数 Codeforces Beta Round #11 D
http://codeforces.com/problemset/problem/11/D 题目大意:给你n个点,m条边,找该图中有几个换 思路:定义dp[i][j]表示i是圈的集合,j表示该集合的终 ...
- [Codeforces Education Round 6E] New Year Tree
[题目链接] https://codeforces.com/contest/620/problem/E [算法] 显然 , 一棵子树的DFS序必然为连续的一段 用线段树维护颜色数即可 [代码] #in ...
- Codeforces Global Round 11 A~D题解
A.Avoiding Zero 题目链接:https://codeforces.ml/contest/1427 题目大意:给定一个数组a1,a2...,an,要求找出一个a重排后的数组b1,b2,.. ...
- Codeforces Global Round 11【ABCD】
比赛链接:https://codeforces.com/contest/1427 A. Avoiding Zero 题意 将 \(n\) 个数重新排列使得不存在为 \(0\) 的前缀和. 题解 计算正 ...
- Codeforces Global Round 11 D. Unshuffling a Deck(构造/相邻逆序对)
题目链接:https://codeforces.com/contest/1427/problem/D 题意 给出一个大小为 \(n\) 的排列,每次操作可以将 \(n\) 个数分为 \(1 \sim ...
- Codeforces Global Round 11 C. The Hard Work of Paparazzi(dp/最长上升子序列)
题目链接:https://codeforces.com/contest/1427/problem/C 题意 \(r\) 行与 \(r\) 列相交形成了 \(r \times r\) 个点,初始时刻记者 ...
随机推荐
- Android OpenGL ES(十)绘制三角形Triangle .
三角形为OpenGL ES支持的面,同样创建一个DrawTriangle Activity,定义6个顶点使用三种不同模式来绘制三角形: float vertexArray[] = { -0.8f, - ...
- http请求连接
1.在Info.plist中添加NSAppTransportSecurity类型Dictionary.2.在NSAppTransportSecurity下添加NSAllowsArbitraryLoad ...
- Java中Date和Calender类的使用方法
查看文章 Java中Date和Calender类的使用方法 2009-10-04 20:49 Date和Calendar是Java类库里提供对时间进行处理的类,由于日期在商业逻辑的应用中占据着 ...
- php 后台权限例子 (mysql 数据表)
说明 超级管理员的权限最高 可以操作所有的功能 !!! 超级管理员给特定的用户分配对应的权限 下文注解: 用户表 关联 用户组表 每个用户组对应特定的功能权限 !! ...
- php截取中文字符串,英文字符串,中英文字符串长度的方法
今天学习了php函数截取中文字符串,英文字符串,中英文字符串的函数使用方法.对中英文截取方法不理解,此处先做记录. PHP自带的函数如strlen().mb_strlen()都是通过计算字符串所占字节 ...
- java 基础的几种算法
1:冒泡排序:2个之间进行循环筛选 public void sort(int[] a) { int temp = 0; for (int i = a.length - 1; i > 0; i ...
- Win7下安装配置Java
1 安装JDK java.sun.com 下载 Java SE Development Kit 2 配置环境变量 变量名:JAVA_HOME 变量值:C:\Program Files (x86)\J ...
- PAT (Advanced Level) 1104. Sum of Number Segments (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- nginx slab内存管理
本来这一篇作为nginx系列的开头是不合适的,不过由于nginx进程框架自己的梳理还没完成,这部分又刚好整理完了,就从这开始吧.这儿谈的是nginx的slab的内存管理方式,这种方式的内存管理在ngi ...
- mongodb综述
摘要:mongodb相对于mysql的优势在于性能和分布式扩展方面