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\) 个点,初始时刻记者 ...
随机推荐
- OpenGL---------光照的基本知识
从生理学的角度上讲,眼睛之所以看见各种物体,是因为光线直接或间接的从它们那里到达了眼睛.人类对于光线强弱的变化的反应,比对于颜色变化的反应来得灵敏.因此对于人类而言,光线很大程度上表现了物体的立体感. ...
- iOS高德地图自定义annotation添加不同图片
1.model类里面添加index #import <MAMapKit/MAMapKit.h> #import <AMapSearchKit/AMapCommonObj.h> ...
- linux daemon
参考 鸟哥的私房菜 http://linux.vbird.org/linux_basic/0560daemons.php
- 天棋哥哥大战AlphaGo
天棋哥哥大战AlphaGo Time Limit: 1 Sec Memory Limit: 128 MB Submit: 20 Solved: 9 [Submit][Status][Web Boa ...
- Disassembly2:Built-in Type
先贴一段代码: 跟踪后看到:
- Lint Code——最多共线的点的个数
题目链接:http://www.lintcode.com/zh-cn/problem/max-points-on-a-line/# 条件:给一个点数组 目标:求出共线的点的最多个数 实现:时间复杂度- ...
- MapReduce常见算法
1.单词计数 2.数据去重 3.排序 4.Top K(求数据中的最大值) 5.选择 6.投影 7.分组 8.多表连接 9.单表关联
- 第19章 网络通信----UDP程序设计基础
用户数据报协议(UDP)是网络信息传输的另一种形式. 基于UDP通信的基本模式如下: (1)将数据打包(称为数据包),然后将数据包发往目的地. 发送数据包: 使用DatagramSocket()创建一 ...
- 【项目笔记】【bug】数组空指针异常
package com.example.googleplay.ui.holder; import java.util.ArrayList; import android.view.View; impo ...
- postfix中recipient/client/sender/helo四者的区别<转载>
postfix在main.cf中用下面四个做限制,那么这四者到底有什么区别? smtpd_recipient_restrictions smtpd_client_restrictions smtpd_ ...