Codeforces #640 div4 F~G (构造二连弹)

题意:求一个只由\(01\)组成的字符串,使得它所有长度为\(2\)的子串满足:每对子串的数字和为\(0,1,2\)的个数为\(a,b,c\).
题解:我们先考虑子串数字和为\(1\)的情况,构造出一个\(10\)的循环串,然后在它的头部尾部适当添加\(1\)和\(0\),使得a和c也满足即可.需要特判\(b=0\)的情况,并且\(b\)奇偶不同构造情况也不同.
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL; int t;
int a,b,c;
string s;
int main() {
ios::sync_with_stdio(false);
cin>>t;
while(t--){
s="";
cin>>a>>b>>c;
if(b==0){
if(c){
c++;
while(c--) s+="1";
}
if(a){
a++;
while(a--) s+="0";
}
}
else if(b%2==1){
int tmp=(b+1)/2;
while(tmp--) s+="10";
while(c--) s="1"+s;
while(a--) s+="0";
}
else{
int tmp=b/2;
while(tmp--) s+="10";
while(c--) s="1"+s;
while(a--) s+="0";
s+="1";
}
cout<<s<<endl;
} return 0;
}

题意:给你一个数\(n\),构造一个\(1\le p \le n\)的序列,对于\(\forall\;1\le i < n\)有:\(2 \le |p_{i}-p_{i+1}| \le 4\).如果不存在,输出\(-1\).
题解:易知:当且仅当\(n=2\;or\;n=3\)时不满足条件.
首先先将\(1\)~\(n\)中所有的偶数输出,然后:
1.如果\(n\)是偶,那么就先输出第二大和最大的奇数,剩下的奇数递减输出即可.
2.如果n是奇,那么就先输出第三大的奇数,剩下的奇数递减输出即可.
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 2e4;
const int mod = 1e9 + 7;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL; int t;
int n; int main() {
ios::sync_with_stdio(false);
cin>>t;
while(t--){
cin>>n;
if(n==2 || n==3) puts("-1");
else{
for(int i=2;i<=n;i+=2){
printf("%d ",i);
}
if(n%2==0){
printf("%d %d ",n-3,n-1);
for(int i=n-5;i>=1;i-=2){
printf("%d ",i);
}
}
else if(n%2==1){
printf("%d ",n-4);
printf("%d ",n);
for(int i=n-2;i>=1;i-=2){
if(i!=n-4)
printf("%d ",i);
}
}
puts("");
}
} return 0;
}
Codeforces #640 div4 F~G (构造二连弹)的更多相关文章
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Educational Codeforces Round 40 F. Runner's Problem
Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...
- Educational Codeforces Round 66 差G
Educational Codeforces Round 66 F 题意:长度为 n 的序列,求有多少个区间 \([l,r]\) ,使得其构成了一个 1~r-l+1 的排列. \(n \le 3*10 ...
- Codeforces 1154 - A/B/C/D/E/F/G - (Undone)
链接:https://codeforces.com/contest/1154 A - Restoring Three Numbers - [水] #include<bits/stdc++.h&g ...
- Codeforces 659 - A/B/C/D/E/F/G - (Undone)
链接:https://codeforces.com/contest/659 A - Round House - [取模] AC代码: #include<bits/stdc++.h> usi ...
- codeforces gym 100952 A B C D E F G H I J
gym 100952 A #include <iostream> #include<cstdio> #include<cmath> #include<cstr ...
- codeforces gym101243 A C D E F G H J
gym101243 A #include<iostream> #include<cstdio> #include<cmath> #include<cstrin ...
- Codeforces 1214 F G H 补题记录
翻开以前打的 #583,水平不够场上只过了五题.最近来补一下题,来记录我sb的调试过程. 估计我这个水平现场也过不了,因为前面的题已经zz调了好久-- F:就是给你环上一些点,两两配对求距离最小值. ...
- [codeforces/edu2]总结(F)
链接:http://codeforces.com/contest/600 A题: 字符串处理. B题: sort+upper_bound C题: 统计一下每种字符的个数,然后贪心. (1) 如果没有奇 ...
随机推荐
- java.net.NoRouteToHostException: 没有到主机的路由
今天在配置Jenkins 的云服务器的时候提示:java.net.NoRouteToHostException: 没有到主机的路由,网上查到的没有主机路由问题提到的大多是防火墙问题. 查看防火墙状态: ...
- CSS实现迷你键盘
最近做了一个迷你键盘的dome,这里分享给大家 dome下载地址(点击下载) 代码如下: <!DOCTYPE html> <html lang="en" > ...
- 参数模型检验过滤器 .NetCore版
最近学习 .NETCore3.1,发现过滤器的命名空间有变化. 除此以外一些方法的名称和使用方式也有变动,正好重写一下. 过滤器的命名空间的变化 原先:System.Web.Http.Filters; ...
- ROS教程(二):创建工作空间(图文)
ros教程:创建工作空间 目录 前言 一.工作空间? 二.创建一个工作空间 1.创建目录 2.编译 前言 使用catkin创建一个工作空间 一.工作空间? 在ROS系统下,我们所有的项目都放在一个工作 ...
- MySQL全面瓦解21(番外):一次深夜优化亿级数据分页的奇妙经历
背景 1月22号晚上10点半,下班后愉快的坐在在回家的地铁上,心里想着周末的生活怎么安排. 突然电话响了起来,一看是我们的一个开发同学,顿时紧张了起来,本周的版本已经发布过了,这时候打电话一般来说是线 ...
- 手写Netty之多路复用Select小案例
注意:本文只是将上文多路复用器Select.Poll.Epoll区别梳理中提出的概念与Netty中的步骤联系起来,方便后面回顾,代码中注释很多,对于大家来说如果不是怀有同样的目的,不一定有用. 单线程 ...
- a.default.ERROR.httpAjax is not a function
原因1: 使用的是jQuery的slim构建,它删除了一些东西,ajax就是其中之一. 解决方法: 在此处下载常规(压缩或非压缩)版本的jQuery并将其包含在您的项目中. 原因2: 使用其他库引起了 ...
- Golang拼接字符串的5种方法及其效率_Chrispink-CSDN博客_golang 字符串拼接效率 https://blog.csdn.net/m0_37422289/article/details/103362740
Different ways to concatenate two strings in Golang - GeeksforGeeks https://www.geeksforgeeks.org/di ...
- https://www.exploit-db.com/docs/english/45906-cors-attacks.pdf
https://www.exploit-db.com/docs/english/45906-cors-attacks.pdf What is CORS (cross-origin resource s ...
- MySQL 压测
https://mp.weixin.qq.com/s/vKJZp5cGUetHokGh2EZUXg mysqlslap --iterations=100 --create-schema='test' ...