zoukankan      html  css  js  c++  java
  • F. Binary String Reconstruction

    F. Binary String Reconstruction

    原题链接:传送门

    题目大意

    给定我们三个数字a , b , c

    a表示两个相邻的字符和为0的情况:00

    b表示两个相邻的字符和为1的情况:01 , 10

    c表示两个相邻的字符和为2的情况: 11

    现在让你构造一个二进制串,要求二进制串中的a , b , c三种类别的出现次数等于给定的 a b c

    例如:

    a = 1 b = 3 c = 5
    
    对应结果:
    1110011110
    

    分析

    根据print any of them 可以推断出这题大概率是一个构造题,

    对于a和c的情况来说,如果要构造的尽可能简单一定是要他们保证自己具有一连串连续的0或者1

    即对于以上样例,我们可以知道其一定具有a + 1 个连续的 0 和 c + 1 个连续的1

    那么我们只需要考虑b怎么安置在这样的字串之中

    AC 代码

    C++ code

    void slove()
    {
    	int a , b , c;
    	cin >> a >> b >> c;
    	if(b == 0)
    	{
    		if(a != 0)cout << string(a + 1 , '0') << endl;
    		else cout << string(c + 1 , '1') << endl;
    		return;
    	}
    	string ans;
    	for(int i = 0;i < b + 1;i ++)
    	{
    		if(i & 1)ans += "0";
    		else ans += "1";
    	}
    	ans.insert(1 , string(a , '0'));
    	ans.insert(0 , string(c , '1'));
    	cout << ans << endl;
    }
    
  • 相关阅读:
    实用C语言技巧
    ASP.NET的适配器设计模式(Adapter)
    MongoDB的管理
    WinForm实现类似QQ停靠,显示隐藏过程添加特效效果
    dreamhappy博客索引
    Namenode的介绍
    asp.net
    学习
    采用Mono进行移动开发图书推荐
    VS2010+C#写的3D
  • 原文地址:https://www.cnblogs.com/wlw-x/p/13586063.html
Copyright © 2011-2022 走看看