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\) 个点,初始时刻记者 ...
随机推荐
- 使用React Native一年后的感受
转载自:http://www.dobest.me/blog/2016/06/12/%E4%BD%BF%E7%94%A8React%20Native%E4%B8%80%E5%B9%B4%E5%90%8E ...
- 【转】对于JNI方法名,数据类型和方法签名的一些认识
[转]对于JNI方法名,数据类型和方法签名的一些认识 之前一直用jni,但是没有考虑Java重载函数,如何在jni-C++里命名,今天看到一篇文章,讲到了类型签名. 原文链接:http://www ...
- IDAPython: importing “site” failed
问题:IDA启动时,弹出IDAPython: importing “site” failed对话框. 解决办法:环境变量添加PYTHONHOME,值为python安装路径,比如:C:\Python27
- 留言本,keyCode
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- HDU 4738 Caocao's Bridges(割边)
乍一看一个模板题,仔细一看还是模板题,但是三个坑.1,不是连通图,放0个.2 守卫为0,放1个. 3注意重边. #include<iostream> #include<cstdio& ...
- loadrunner多负载机联合产生负载
解说一: 多机联合产生负载 LOADRUNNER 对应用程序施压时,采用的方法就是让一台机器模拟很多用户,同时向被 测用户发送请求或进行操作.这样,如果一台测试机器模拟的虚拟用户数过多,他本身性能的下 ...
- centos和ubuntu下使用cron设置定时任务
1.启动cron工具[ps:使用root权限] centos启动cron两种方式 a) /etc/init.d/crond start b) service crond start ubuntu启动c ...
- SQL查询重复记录
假设现有一张人员表(表名:Person),若想将姓名.身份证号.住址这三个字段完全相同的记录查找出来,使用 1: SELECT p1.* 2: FROM persons p1,persons p2 3 ...
- 我也谈javascript闭包的原理理解
参考原文:http://www.oschina.net/question/28_41112 前言:还是一篇入门文章.Javascript中有几个非常重要的语言特性——对象.原型继承.闭包.其中闭包 对 ...
- OGG FAQ
Q1:oracle_关于参数.ENABLE_GOLDENGATE_REPLICATION A: So, in order to use OGG, on Oracle 11.2.0.4, or Or ...