• 题意:求一个只由\(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. If you see someone without smile

    If you see someone without smile, give them one of yours. 难怪我每次和不认识的人说话都放肆大笑.

  2. 【EXP】比较大的dmp文件导入的时候可以将界面关掉

    有一个需求,将一个dmp文件导入到数据库中,但是这个crt的回话有timeout,3分钟,所以一到三分钟就掉线,导入就失败了,这让人很头疼,关闭界面,imp也就终止了 最后想到了几招,分享一下: 1. ...

  3. 【Oracle】想查询相关的v$视图,但是提示表或视图不存在解决办法

    原因是使用的用户没有相关的查询权限导致 解决办法: grant select  any dictionary to 用户;    --这个权限比较大 这个权限是最低的要求,但是可以访问到v$相关视图 ...

  4. 【九阳神功】Nessus 8_VM不限IP及AWVS破解版合体部署

    Nessus 8下载地址: https://moehu-my.sharepoint.com/personal/ximcx_moebi_org/_layouts/15/download.aspx?Sou ...

  5. oracle新增ID主键列,如何补全旧数据的ID值

    1.创建SEQUENCE CREATE SEQUENCE MONKEY.TEST_ADD_IDCOL_ID CACHE 100; 2.新增表栏位 ALTER TABLE MONKEY.TEST_ADD ...

  6. Java优先队列PriorityQueue的各种打开方式以及一些你不知道的细节

    目录 Java优先队列PriorityQueue的各种打开方式以及一些你不知道的细节 优先队列的默认用法-从小到大排序 对String类用优先队列从大到小排序 通过自定义比较器对自定义的类进行从小到大 ...

  7. JavaScript中函数的定义!

    JavaScript中函数的定义! 1 自定义函数(命名函数) function fun() {}; 2 函数表达式(匿名函数) var fun = function () {}; 3 利用 new ...

  8. Go 和 Syscall

    曹春晖:谈一谈 Go 和 Syscall https://juejin.im/post/6844903845475139597

  9. MFA

    什么是 MFA?_启用和解绑MFA_账号常见问题_账号管理-阿里云 https://help.aliyun.com/knowledge_detail/37215.html

  10. 【PC Basic】CPU、核、多线程的那些事儿

    一.CPU与核的概念 1.半导体中名词[Wafer][Chip][Die]中文名字和用途 Wafer--晶圆 wafer 即为图片所示的晶圆,由纯硅(Si)构成.一般分为6英寸.8英寸.12英寸规格不 ...