• 题意:求一个只由\(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;
    }

最新文章

  1. 李洪强iOS面试题之-iOS选择题
  2. 基于GTID Replication主从数据不一致操作
  3. InstallShield2008脚本安装制作方法Setup
  4. xfire找不到services.xml
  5. Nginx 变量漫谈(五)
  6. 解决Ubuntu DNS解析慢、上网速度慢
  7. 使用SVN clang: error: linker command failed with exit code 1 (use -v to see invocation)
  8. IOS开发-UI学习-UISlider(滑动条)的使用
  9. .NET方法无限传参数技术
  10. VC使用双缓冲制作绘图控件
  11. Android动画曲线库AndroidEasingFunctions
  12. linux的PAM认证和shadow文件中密码的加密方式
  13. confluence中org.apache.tomcat.util.net.NioEndpoint$Acceptor.run Socket accept failed的解决方法
  14. C# 线程间互相通信 AutoResetEvent和ManualResetEvent
  15. Ubuntu 下安装LEMP环境 实战
  16. 雷林鹏分享:jQuery EasyUI 扩展
  17. Java多线程之syncrhoized内置互斥锁的用法详解
  18. Intersection(Check)
  19. Service Mesh服务网格新生代——Istio
  20. Java发送HTTP POST请求示例

热门文章

  1. HDU6375双端队列
  2. 十五:SQL注入之oracle,Mangodb注入
  3. 【Linux】iptables配置文件中的一些疑问
  4. Jmeter二次开发——自定义函数
  5. 2.4V升5V芯片,8uA功耗,低功耗升压电路图
  6. 细数JS中实用且强大的操作符&amp;运算符
  7. kvm虚拟机管理(创建、连接)
  8. (06)-Python3之--判断、循环
  9. C#高级编程第11版 - 第九章 索引
  10. MySQL调优性能监控之show profile