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\) 个点,初始时刻记者 ...
随机推荐
- Day02——widow对象
window - 计时器 1、setTimeout()可以用来在指定的时间之后单次调用函数. setTimeount(f,1000);//一秒后调用函数f clearTimeout();取消函数的执行 ...
- IMP指针
可能大家一直看到有许多朋友在Runtime相关文章中介绍IMP指针的概念,那么IMP究竟有什么实际作用呢?让我们先从一个函数看起来. Method Swizzling 如果对Runtime有一定了解的 ...
- Java中的五种单例模式实现方法
[代码] Java中的五种单例模式实现方法 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 2 ...
- XListview的下拉刷新、上拉加载、用Pull解析XML
做之前需要导入XListview的文件,此是用第三方的xListview实现的,东西没写全.此是在Fragment中实现的 //--------------XListView的布局---------- ...
- AI 人工智能 探索 (八)
绑定下,用来释放内存 布局框架.链接:http://pan.baidu.com/s/1eQzSXZO 密码:25ir 这次 我采用 ngui 来设定界面.除工具栏模块外,其他各类ui模块都是 内存池动 ...
- 转:透析QTP自动化测试框架SAFFRON
1.为什么要使用框架? 框架是一组自动化测试的规范.测试脚本的基础代码,以及测试思想.惯例的集合.可用于减少冗余代码.提高代码生产率.提高代码重用性和可维护性.例如QTestWare就是QTP自动化测 ...
- MySQL常用命令总结2
USE db_name; //使用(打开)数据库 SELECT DATABASE(); //查看当前打开的数据库 CREATE TABLE tb_name( column_name data_type ...
- 单词接龙(dragon)
单词接龙(dragon) 题目描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的“龙”(每个单词都最多在“龙”中出现两次) ...
- ZOJ3944People Counting<暴力/枚举>
题意:输入一张照片,给出人物的特征,判断有多少个人. .O. /|\ (.) 思路:按照3*3的图统计,只要有一个点符合就加1 #include<cstdio> #include<i ...
- log4j输出到指定日志文件
log4j.properties: log4j.logger.myTest=DEBUG,console,FILE log4j.appender.console=org.apache.log4j.Con ...