The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - J CONTINUE...?
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 原题地址:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5759
题意:
老师分宝石,一个由0和1组成的字符串数组,每个字符都是一个学生每个学生s[i]都有i个宝石,其中1是男生,0是女生
有G1G2G3G4四个分组其中G1G2只能女生,G2G3只能男生。要求G1G3一组,G2G4一组,让他们两组的宝石个数相同 思路:
一个数组能否被分成两堆第一步是取决于他们的和是否为偶数,如果是奇数是不可能分成两堆的。
题目有说可以让有的组数为0所以男生女生这个要求就只是一个干扰项;
具体:首先我们判断长度为偶数的情况
例如:
8
11111111
这个数据
首先他们的值是
1 2 3 4 5 6 7 8
我们让第一个”1“为第A组,第二个”2“为第B组 这样第A组的值减去第B组的值为(1-2)=-1;
然后我们让第三个”3“为第B组,第四个”4“为第A组,这样第A组减去第B组的值为(4-3)=1;
正好抵消为0就这样依次 A B B A A B B A就能保证他们的合为0; 然后我们看奇数长度的情况
例如:题目的最后一组数据
7
1101001
他们的值是
1 2 3 4 5 6 7
首先我们从第二个开始
第二个在A组,第三个在B组 这时候A-B=(2-3)=-1;
第四个在B组,第五个在A组 这时候A-B=(5-4)=1; 这时前面四个正好抵消
然后第六个在A组,第四个在B组,这时候A-B=(6-7)=-1;
这时候正好可以把前面被忽略的1加进来放在不够的A组上这时候正好抵消; 代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int one;
int two;
int three;
int four;
int mark[];
bool yes(ll n){
if(((n*(n+))/)%==)return false;
return true;
}
int main()
{
//std::ios::sync_with_stdio(false);
ll n;
int t;
cin>>t;
string s;
while(t--){
cin>>n;
cin>>s;
if(!yes(n)){//判断是否合为偶数
cout<<-<<endl;
continue;
}
if(n%==){///长度为偶数的情况
for(int i=;i<n;i++){
if(i%==||i%==){
if(s[i]=='')cout<<"";
else cout<<"";
}
else if(i%==||i%==){
if(s[i]=='')cout<<"";
else cout<<"";
}
}
}
else{///长度为奇数的情况
if(s[]=='')cout<<"";
else cout<<"";
for(int i=;i<n;i++){
if((i-)%==||(i-)%==){
if(s[i]=='')cout<<"";
else cout<<"";
}
else if((i-)%==||(i-)%==){
if(s[i]=='')cout<<"";
else cout<<"";
}
}
}
cout<<endl;
}
return ;
}
The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - J CONTINUE...?的更多相关文章
- The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - L Doki Doki Literature Club
Doki Doki Literature Club Time Limit: 1 Second Memory Limit: 65536 KB Doki Doki Literature Club ...
- 2018浙江省赛(ACM) The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple
我是铁牌选手 这次比赛非常得爆炸,可以说体验极差,是这辈子自己最脑残的事情之一. 天时,地利,人和一样没有,而且自己早早地就想好了甩锅的套路. 按理说不开K就不会这么惨了啊,而且自己也是毒,不知道段错 ...
- The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - M Lucky 7
Lucky 7 Time Limit: 1 Second Memory Limit: 65536 KB BaoBao has just found a positive integer se ...
- The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - B King of Karaoke
King of Karaoke Time Limit: 1 Second Memory Limit: 65536 KB It's Karaoke time! DreamGrid is per ...
- The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple -A Peak
Peak Time Limit: 1 Second Memory Limit: 65536 KB A sequence of integers is called a peak, if ...
- ZOJ 4033 CONTINUE...?(The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple)
#include <iostream> #include <algorithm> using namespace std; ; int a[maxn]; int main(){ ...
- The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - F 贪心+二分
Heap Partition Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge A sequence S = { ...
- The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - C 暴力 STL
What Kind of Friends Are You? Time Limit: 1 Second Memory Limit: 65536 KB Japari Park is a larg ...
- ZOJ 3962 E.Seven Segment Display / The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple E.数位dp
Seven Segment Display Time Limit: 1 Second Memory Limit: 65536 KB A seven segment display, or s ...
随机推荐
- [洛谷P1120]小木棍 [数据加强版]
题目大意:有一些同样长的木棍,被切割成几段(长$\leqslant$50).给出每段小木棍的长度,找出原始木棍的最小可能长度. 题解:dfs C++ Code: #include<cstdio& ...
- [Leetcode] Swap nodes in pairs 成对交换结点
Given a linked list, swap every two adjacent nodes and return its head. For example,Given1->2-> ...
- Codeforces 937.B Vile Grasshoppers
B. Vile Grasshoppers time limit per test 1 second memory limit per test 256 megabytes input standard ...
- [hdu 2298] 物理推导+二分答案
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2298 #include<bits/stdc++.h> using namespace st ...
- 毕业答辩的PPT攻略
关于内容: 1.一般概括性内容:课题标题.答辩人.课题执行时间.课题指导教师.课题的归属.致谢等. 2.课题研究内容:研究目的.方案设计(流程图).运行过程.研究结果.创新性.应用价值.有关课题延续 ...
- PRINT_TABLE 列以行形式显示
在sqlplus,如果列比较多,往往会显示不够清晰,这时如果能把查询语句行转列就明了多了,在网上看到print_table存储过程:里面所设置的日期格式,可根据自己习惯修改 CREATE OR REP ...
- Android 实现对图片 Exif 的修改(Android 自带的方法)
很多时候我们都要对我们的图片信息进行一些处理,比如向图片中写入经纬度,拍摄时间,设备信息,作者等等. 这个时候我们就要对我们的图片Exif进行写入信息的操作,当然,我们想知道图片的Exif信息,也可以 ...
- Java并发(10)- 简单聊聊JDK中的七大阻塞队列
引言 JDK中除了上文提到的各种并发容器,还提供了丰富的阻塞队列.阻塞队列统一实现了BlockingQueue接口,BlockingQueue接口在java.util包Queue接口的基础上提供了pu ...
- GET和POST本质上有什么区别,这才是标准答案
不知道各位读者在面试的时候,有没有被问过这个问题:"请说一下GET和POST两者的本质区别".基本上做过WEB开发的,对这个问题,都可以回答出一堆的区别. 比如: 最直接的区别,G ...
- Java并发编程--ThreadPoolExecutor
概述 为什么要使用线程池? 合理利用线程池能够带来三个好处.第一:降低资源消耗.通过重复利用已创建的线程降低线程创建和销毁造成的消耗.第二:提高响应速度.当任务到达时,任务可以不需要等到线程创建就能立 ...