CONTINUE...?
Time Limit: 1 Second Memory Limit: 65536 KB Special Judge
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

【题意】:https://www.cnblogs.com/bluefly-hrbust/p/8971769.html

本题题意就是把1到n数表示为,两组数之和相等,即能不能1->n划分成两部分(男女分组是干扰的)

1 2 3 4 5 6 7 8

偶数-->1+8+2+7 = 3+6+4+5

1 2 3 4 5 6 7

奇数-->1+3+4+6 = 2+5+7

偶数: n只需要前后匹配即可

奇数: n/2之前的奇数位和n/2之后的偶数位相加,等于n/2之前的偶数位加n/2的奇数位

【分析】:ACZone+

【出处】:CodeForces - 899C Dividing the numbers

【代码】:

#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
int t,n,len;
char a[100050];
int b[100050];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
getchar();
scanf("%s",&a);
len=strlen(a);
if ((n%4)<=2 && n%4!=0)
{
printf("-1\n");
}
else
{
if(n%2==0) //偶数
{
for(int i=0; i<n/4; i++)
{
if (a[i]=='1')printf("3");
else printf("1");
}
for (int i=n/4; i<n-n/4; i++)
{
if (a[i]=='1')printf("4");
else printf("2");
}
for (int i=n-n/4; i<n; i++)
{
if (a[i]=='1')printf("3");
else printf("1");
}
printf("\n");
}
else //奇数
{
for(int i=0; i<n/2; i++)
{
if (a[i]=='1')
{
if ((i+1)%2==1)printf("3");
else printf("4");
}
else
{
if ((i+1)%2==1)printf("1");
else printf("2");
}
}
for(int i=n/2; i<len; i++)
{
if (a[i]=='1')
{
if ((i+1)%2==1)printf("4");
else printf("3");
}
else
{
if ((i+1)%2==1)printf("2");
else printf("1");
}
}
printf("\n");
}
}
}
return 0;
}

CONTINUE...?【构造/分析】的更多相关文章

  1. 任意文件下载漏洞的接口URL构造分析与讨论

    文件下载接口的URL构造分析与讨论 某学院的文件下载接口 http://www.****.edu.cn/item/filedown.asp?id=76749&Ext=rar&fname ...

  2. popchain与对应poc的构造分析

    本文首发于:https://mp.weixin.qq.com/s?__biz=MjM5MTYxNjQxOA==&mid=2652850238&idx=1&sn=6f22d8ab ...

  3. 《编译原理》构造 LL(1) 分析表的步骤 - 例题解析

    <编译原理>构造 LL(1) 分析表的步骤 - 例题解析 易错点及扩展: 1.求每个产生式的 SELECT 集 2.注意区分是对谁 FIRST 集 FOLLOW 集 3.开始符号的 FOL ...

  4. 编译原理根据项目集规范族构造LR(0)分析表

    转载于https://blog.csdn.net/Johan_Joe_King/article/details/79058597?utm_medium=distribute.pc_relevant.n ...

  5. 基于虎书实现LALR(1)分析并生成GLSL编译器前端代码(C#)

    基于虎书实现LALR(1)分析并生成GLSL编译器前端代码(C#) 为了完美解析GLSL源码,获取其中的信息(都有哪些in/out/uniform等),我决定做个GLSL编译器的前端(以后简称编译器或 ...

  6. 【编译原理】语法分析LL(1)分析法的FIRST和FOLLOW集

    近来复习编译原理,语法分析中的自上而下LL(1)分析法,需要构造求出一个文法的FIRST和FOLLOW集,然后构造分析表,利用分析表+一个栈来做自上而下的语法分析(递归下降/预测分析),可是这个FIR ...

  7. 【集合框架】JDK1.8源码分析之ArrayList详解(一)

    [集合框架]JDK1.8源码分析之ArrayList详解(一) 一. 从ArrayList字表面推测 ArrayList类的命名是由Array和List单词组合而成,Array的中文意思是数组,Lis ...

  8. 面向对象软件构造 (Bertrand Meyer 著)

    Part A: The Issues 议题 第一章 软件品质 第二章 面向对象的标准 Part B: The Road To Object Orientation 通向面向对象之路 第三章 模块性 第 ...

  9. 编译原理--02 自顶向下、自底向上的LR分析复习(清华大学出版社第3版)

    前言 目录 01 文法和语言.词法分析复习 02 自顶向下.自底向上的LR分析复习 03 语法制导翻译和中间代码生成复习 04 符号表.运行时存储组织和代码优化复习 第4章 自顶向下的语法分析方法 确 ...

随机推荐

  1. 剑指Offer - 九度1371 - 最小的K个数

    剑指Offer - 九度1371 - 最小的K个数2013-11-23 15:45 题目描述: 输入n个整数,找出其中最小的K个数.例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是 ...

  2. thinkPHP 表单自动验证功能

    昨天晚上我们老大叫我弄表单自动验证功能,愁了半天借鉴了好多官网的知识,才出来,诶,总之分享一下我自己的成果吧! thinkphp 在Model基类为我们定义了自动验证的函数和正则表达式,我们只需要在对 ...

  3. Mysql与Oracle之间的数据类型转换

    MySQL Data Type Oracle Data Type BIGINT NUMBER(19, 0) BIT RAW BLOB BLOB, RAW CHAR CHAR DATE DATE DAT ...

  4. python 学习分享-rabbitmq

    一.RabbitMQ 消息队列介绍 RabbitMQ也是消息队列,那RabbitMQ和之前python的Queue有什么区别么? py 消息队列: 线程 queue(同一进程下线程之间进行交互) 进程 ...

  5. Python全栈工程师 (exercises)

    # 1:给定一个数,判断他是正数,负数,还是0 a = int(input("请输入一该个整数")) if a == 0: print(a, "是0") eli ...

  6. vue实现数据的增删改查

    在管理员的一些后台页面里,个人中心里的数据列表里,都会有对这些数据进行增删改查的操作.比如在管理员后台的用户列表里,我们可以录入新用户的信息,也可以对既有的用户信息进行修改.在vue中,我们更应该专注 ...

  7. android系统联系人分组特效实现(2)---字母表快速滚动

    要实现这种功能,只需要在   android系统联系人分组特效实现(1)---分组导航和挤压动画  的基础上再加上一个自定义控件即可完成. 1.新建项目,继续新建一个java类,BladeView,用 ...

  8. 【bzoj2238】Mst 最小生成树+树链剖分+线段树

    题目描述 给出一个N个点M条边的无向带权图,以及Q个询问,每次询问在图中删掉一条边后图的最小生成树.(各询问间独立,每次询问不对之后的询问产生影响,即被删掉的边在下一条询问中依然存在) 输入 第一行两 ...

  9. Codeforces Round #387 (Div. 2) 747E

    这题本身是个水题,但是写了半天 题意就是给出一个树的生成方式,让你还原这棵树,然后按深度输出结点 这个还原过程还是比较有趣的(没有用递归) PS:getline的新姿势get #include < ...

  10. H5单文件压缩插件

    单文件压缩上传 <input type="file" id="file"> 构造函数 function UpFileImg(options){ va ...