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. iis 限制动态IP地址访问次数

    An IP Address Blocking HttpModule for ASP.NET in 9 minutes namespace YourModuleNameHere 10 { 11 publ ...

  2. 信号量的基本概念与使用semget,semop

    1.信号量的基本概念 信号量是一个计数器,常用于处理进程或线程的同步问题,特别是对临界资源的同步访问. 临界资源可以简单的理解为在某一时刻只能由一个进程或线程进行操作的资源,这里的资源 可以是一段代码 ...

  3. SAP事物代码

    事物代码是SAP进入特定功能的快捷命令,如事物代码VA01能快速进入创建销售订单的页面,要浏览当前页面的事物代码,在状态栏右下角可以查看 快速导航事物代码 这类事物代码将功能相似的事物代码组合在一起, ...

  4. vue v-nav指令属性列表

    v-nav指令属性列表 属性名 属性描述 类型 必选 默认 title 导航栏标题 String No 空字符串 showBackButton 是否显示(左边的)返回按钮 Boolean No fal ...

  5. 如何使用JVisualVM进行性能分析

    地址:https://visualvm.dev.java.net/ 连接 1.本地机器的程序直接可以监听到 2.远程机器的程序需要加上JVM参数 -Dcom.sun.management.jmxrem ...

  6. 获取当前页面的URL信息

    以前在做网站的时候,经常会遇到当前页的分类高亮显示,以便让用户了解当前处于哪个页面.之前一直是在每个不同页面写方法.工程量大,也不便于修改.一直在想有什么简便的方法实现.后来在网上查到可以用获取当前U ...

  7. Linux的基础命令

    -shutdown –h now(root用户才有效)     立即关机 -shutdown –r now(root用户才有效)     立即重新启动计算机 -reboot               ...

  8. UVA116-Unidirectional TSP(动态规划基础)

    Problem UVA116-Unidirectional TSP Accept: 7167  Submit: 56893Time Limit: 3000 mSec Problem Descripti ...

  9. 强化学习(三)—— 时序差分法(SARSA和Q-Learning)

    1.时序差分法基本概念 虽然蒙特卡洛方法可以在不知道状态转移概率矩阵的前提下,灵活地求解强化学习问题,但是蒙特卡洛方法需要所有的采样序列都是完整的状态序列.如果我们没有完整的状态序列就无法用蒙特卡洛方 ...

  10. 路飞学城-Python开发集训-第2章

    学习心得: 这章对编码的讲解超级赞,现在对于编码终于有一点认知了,但还没有大彻大悟,还需要更加细心的琢磨一下Alex博客和视频,以前真的是被编码折磨死了,因为编码的问题而浪费的时间很多很多,现在终于感 ...