CONTINUE...?

DreamGrid has  classmates numbered from  to . Some of them are boys and the others are girls. Each classmate has some gems, and more specifically, the -th classmate has  gems.

DreamGrid would like to divide the classmates into four groups , ,  and  such that:

  • Each classmate belongs to exactly one group.

  • Both  and  consist only of girls. Both  and  consist only of boys.

  • The total number of gems in  and  is equal to the total number of gems in  and .

Your task is to help DreamGrid group his classmates so that the above conditions are satisfied. Note that you are allowed to leave some groups empty.

Input

There are multiple test cases. The first line of input is an integer  indicating the number of test cases. For each test case:

The first line contains an integer  () -- the number of classmates.

The second line contains a string  () consisting of 0 and 1. Let  be the -th character in the string . If , the -th classmate is a boy; If , the -th classmate is a girl.

It is guaranteed that the sum of all  does not exceed .

Output

For each test case, output a string consists only of {1, 2, 3, 4}. The -th character in the string denotes the group which the -th classmate belongs to. If there are multiple valid answers, you can print any of them; If there is no valid answer, output "-1" (without quotes) instead.

Sample Input

5
1
1
2
10
3
101
4
0000
7
1101001

Sample Output

-1
-1
314
1221
3413214
有些关键信息无非复制。。。没办法大家理解一下
本题题意即为把[1,n]的数放入4个集合中,满足G1+G3=G2+G4,并且有一个01序列与序列1 2 3 4 ....n相匹配,其中0表示此位所代表的值只能放入G1或G2而1代表值放入G3或者G4中。如果存在这样的序列输出
1到N序列中每个元素对应装入G的下标。
其实简化一下,本题题意就是把1到N数表示为 某些数相加等于另外某些数
我们可以写一下
3:1+2=3;
4:1+4=2+3;
5:无法写出
6:无法写出
7:1+3+4+6=2+5+7
8:1+8+2+7=3+6+4+5
为什么5 6无非写出呢?我们发现里面有奇数个奇数,而这样必然会让一边为奇数一边为偶数肯定不行,因此(N%4<=2 && N%4!=0)输出-1;
我们再分N%=2和N%2=1
当N%2==0的时候只可能是N%4==0的情况。。。因为我们淘汰了N%4==2的情况,这样N只需要前后匹配即可
当N%2==1的时候,我又找了一波规律如何奇数个组合
我发现
7:1+3+4+6=2+5+7
11:1+3+5+6+8+10=2+4+7+9+11==33(不信可以算算)
于是我发现。。。貌似len/2之前的奇数位和len/2之后的偶数位相加,等于len/2之前的偶数位加len/2的奇数位
于是我们就能解决把1到N的数组合并且相加成等式的问题了,最后只需要把01分组即可
AC代码
 #include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
int t,n,len;
char a[];
int b[];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
getchar();
scanf("%s",&a);
len=strlen(a);
if ((n%)<= && n%!=)
{
printf("-1\n");
}
else
{
if(n%==)
{
for(int i=; i<len/; i++)
{
if (a[i]=='')printf("");
else printf("");
}
for (int i=len/; i<len-len/; i++)
{
if (a[i]=='')printf("");
else printf("");
}
for (int i=len-len/; i<len; i++)
{
if (a[i]=='')printf("");
else printf("");
}
printf("\n");
}
else
{
for(int i=; i<len/; i++)
{
if (a[i]=='')
{
if ((i+)%==)printf("");
else printf("");
}
if (a[i]=='')
{
if ((i+)%==)printf("");
else printf("");
}
}
for(int i=len/; i<len; i++)
{
if (a[i]=='')
{
if ((i+)%==)printf("");
else printf("");
}
if (a[i]=='')
{
if ((i+)%==)printf("");
else printf("");
}
}
printf("\n");
}
}
}
return ;
}
												

CONTINUE...?模拟分情况的更多相关文章

  1. HNU 12833 Omar’s Bug(分情况讨论)

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12833&courseid=268 解题报告:有个11个 ...

  2. UESTC 1034 AC Milan VS Juventus 分情况讨论

    AC Milan VS Juventus Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Oth ...

  3. HDU6444(子段和、分情况比较)

    要点 不难想到gcd一下然后枚举每个开头走一圈,并记录一下数值. 最终答案是分情况的:1.能走几圈走几圈然后加上最后剩余的最大子段和:2.也可能是最后一圈后面的拖后腿了,所以最后一圈没走完就停,即长度 ...

  4. bzoj2756: [SCOI2012]奇怪的游戏(网络流+分情况)

    2756: [SCOI2012]奇怪的游戏 题目:传送门 题解: 发现做不出来的大难题一点一个网络流 %大佬 首先黑白染色(原来是套路...)染色之后就可以保证每次操作都一定会使黑白各一个各自的值加1 ...

  5. bzoj 1067 分情况讨论

    这道题考察人的严谨,各种情况分类讨论. #include <cstdio> #include <algorithm> #include <map> #define ...

  6. CODE FESTIVAL 2017 qual A--C - Palindromic Matrix(模拟所有情况,注意细节)

    个人心得:其实本来这题是有规律的不过当时已经将整个模拟过程都构思出来了,就打算试试,将每个字符和总和用优先队列 装起来,然后枚举每个点,同时进行位置标志,此时需要多少个点的时候拿出最大的和出来,若不满 ...

  7. chales抓包,模拟异常情况

    抓包能做什么? 1 .可以抓取客户端和server的请求和返回,可以借助判断是客户端问题是server问题 2.可以模拟各种异常情况用来测试异常情况 3.无接口文档情况下测试接口 怎么修改你抓到的请求 ...

  8. 2018.11.07 NOIP模拟 分糖果(贪心)

    传送门 考虑 n = 2 时的情况:假定两个人分别为(a, b),(c, d),则当且仅当min(a,d) ≤ min(b,c)时,把(a, b)放在前面更优,否则把(c, d)放在前面更优 然后把n ...

  9. Valid Number——分情况讨论最经典的题(没细看)——这题必须静下心来好好看看

    Validate if a given string is numeric. Some examples: "0" => true " 0.1 " =&g ...

随机推荐

  1. Linux系统网络文件配置

    /etc  一.修改配置文档(需要重启网络配置,永远生效) 1.修改IP地址[MariaDB@db1]$ vi /etc/sysconfig/network-scripts/ifcfg-eth0DEV ...

  2. Unity Remote 无法连接

    前言 Unity Remote支持把手机的以下数据返回到Unity Editor中: 触摸输入 加速计 陀螺仪 摄像头 GPS 我的操作环境: Unity 5.3.6f1 在windows 下 And ...

  3. python函数的用法

    python函数的用法 目录: 1.定义.使用函数 1.函数定义:def 2.函数调用:例:myprint() 3.函数可以当作一个值赋值给一个变量 例:a=myprint()    a() 4.写r ...

  4. shell read变量的读入

    shell变量的输入: shell变量除了可以直接赋值或脚本传参外,还可以使用read命令从标准输入获取,read为bash内置命令,可以通过help read查看帮助. 语法格式: read [参数 ...

  5. Unity基础6 Shadow Map 阴影实现

    这篇实现来的有点墨迹,前前后后折腾零碎的时间折腾了半个月才才实现一个基本的shadow map流程,只能说是对原理理解更深刻一些,但离实际应用估计还需要做很多优化.这篇文章大致分析下shadow ma ...

  6. (转)Spring Boot(十一):Spring Boot 中 MongoDB 的使用

    http://www.ityouknow.com/springboot/2017/05/08/spring-boot-mongodb.html MongoDB 是最早热门非关系数据库的之一,使用也比较 ...

  7. C#多线程编程のSemaphore(信号量,负责协调各个线程)

    Semaphore负责协调线程,可以限制对某一资源访问的线程数量 这里对SemaphoreSlim类的用法做一个简单的例子: namespace WpfApplication6 { /// <s ...

  8. [小米 Online Judge]找出单独出现的数字

    描述: 给出N个数字.其中仅有一个数字出现过一次,其他数字均出现过两次,找出这个出现且只出现过一次的数字.要求时间和空间复杂度最小. 输入: 输入多个数字,每个数字以空格分开,回车结束 输出: 输出内 ...

  9. Nginx代理与负载均衡

    序言 Nginx的代理功能与负载均衡功能是最常被用到的,关于nginx的基本语法常识与配置已在上篇文章中有说明,这篇就开门见山,先描述一些关于代理功能的配置,再说明负载均衡详细. Nginx代理服务的 ...

  10. 性能优化——Android图片压缩与优化的几种方式

    图片优化压缩方式大概可以分为以下几类:更换图片格式,质量压缩,采样率压缩,缩放压缩,调用jpeg压缩等1.设置图片格式Android目前常用的图片格式有png,jpeg和webp,png:无损压缩图片 ...