• 题意:求一个只由\(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 (构造二连弹)的更多相关文章

  1. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  2. Educational Codeforces Round 40 F. Runner's Problem

    Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...

  3. Educational Codeforces Round 66 差G

    Educational Codeforces Round 66 F 题意:长度为 n 的序列,求有多少个区间 \([l,r]\) ,使得其构成了一个 1~r-l+1 的排列. \(n \le 3*10 ...

  4. Codeforces 1154 - A/B/C/D/E/F/G - (Undone)

    链接:https://codeforces.com/contest/1154 A - Restoring Three Numbers - [水] #include<bits/stdc++.h&g ...

  5. Codeforces 659 - A/B/C/D/E/F/G - (Undone)

    链接:https://codeforces.com/contest/659 A - Round House - [取模] AC代码: #include<bits/stdc++.h> usi ...

  6. codeforces gym 100952 A B C D E F G H I J

    gym 100952 A #include <iostream> #include<cstdio> #include<cmath> #include<cstr ...

  7. codeforces gym101243 A C D E F G H J

    gym101243 A #include<iostream> #include<cstdio> #include<cmath> #include<cstrin ...

  8. Codeforces 1214 F G H 补题记录

    翻开以前打的 #583,水平不够场上只过了五题.最近来补一下题,来记录我sb的调试过程. 估计我这个水平现场也过不了,因为前面的题已经zz调了好久-- F:就是给你环上一些点,两两配对求距离最小值. ...

  9. [codeforces/edu2]总结(F)

    链接:http://codeforces.com/contest/600 A题: 字符串处理. B题: sort+upper_bound C题: 统计一下每种字符的个数,然后贪心. (1) 如果没有奇 ...

随机推荐

  1. Docker学习笔记之基本命令使用

    测试的环境为Ubuntu1804. 1. search命令搜索镜像 sudo docker search centos 搜索centos相关的镜像,可以看到第一个最多星的的centos是官方的镜像,而 ...

  2. Nginx基础知识学习(安装/进程模型/事件处理机制/详细配置/定时切割日志)

    一.Linux下Nginx的安装 1.去官网 http://nginx.org/download/下载对应的Nginx安装包,推荐使用稳定版本. 2.上传Nginx到Linux服务器. 3.安装依赖环 ...

  3. SQL Server management studio使用sa连接时报错与伺服器的连接已成功,但在登入程序是发生错误

    使用Sql Server management studio的sa用户连接数据库时,报如下错误 解决方法: 1.使用windows验证登录 2.右键点击连接,点击属性,点击安全性,选择混合验证 3.重 ...

  4. oracle 12C单实例打PSU

    前提: oracle不管打什么样的补丁,readme都是很好的参考资料. Oracle每季度都会更新一个最新的PSU,现在12.1.0.2.0的最新的PSU是Patch 26925311. 由于今天白 ...

  5. BINARY SEARCH 的一点说明

    在sap 之abap语言中,有‍BINARY SEARCH这个查找条件.使用read table 来读取内表时,使用‍BINARY SEARCH可以大大的提高查找的效率,为什么呢?学过数据库的人会知道 ...

  6. 1.搭建Hadoop实验平台

    节点功能规划 操作系统:CentOS7.2(1511) Java JDK版本:jdk-8u65-linux-x64.tar.gz Hadoop版本:hadoop-2.8.3.tar.gz 下载地址: ...

  7. 核酸检测:让我明白AQS原理

    春节越来越近了,疫情也越来越严重,但挡不住叫练携一家老小回老家(湖北)团聚的冲动.响应国家要求去我们做核酸检测了. 独占锁 早上叫练带着一家三口来到了南京市第一医院做核酸检测,护士小姐姐站在医院门口拦 ...

  8. 利用JavaUDPSocket+多线程模拟实现一个简单的聊天室程序

    对Socket的一点个人理解:Socket原意是指插座.家家户户都有五花八门的家用电器,但它们共用统一制式的插座.这样做的好处就是将所有家用电器的通电方式统一化,不需要大费周章地在墙壁上凿洞并专门接电 ...

  9. 推荐大家去撸60元的阿里云ACA DevOps认证

    要试题的右边扫码支付10元,私聊博客哈,说出你微信号,留下邮箱,发你邮箱Pdf文件,这么便宜拿证!!

  10. Linux安装redis报错:jemalloc/jemalloc.h: No such file or directory踩坑

    报错内容: 针对这个错误,我们可以在README.md 文件中看到解释: --------- Selecting a non-default memory allocator when buildin ...