原题链接: https://codeforces.com/contest/1417/problems
测试样例
input
2
6 7
1 2 3 4 5 6
3 6
3 3 3
output
1 0 0 1 1 0
1 0 0
题意: (理解题意很关键。) 给你一个数组和不幸值
,要求你将数组
分成数组
和数组
,使得
最小。
其中的值为数组
中
使得
的数量对数。(m为数组
的长度)
解题思路: 我们按题意去模拟构造即可,带有点贪心的味道。遍历一遍数组,对于每个元素
我们判断
有没有在我们要放置的目标数组。(目标数组由我们自己决定,这个意思其实就是符合就放该数组。)如果有,我们就进行判断放哪里是最优的,这个同样是可以通过
容器来获取判断的。 如果没有自然就放默认数组。记住:放了哪个数组,对应的
容器要记录+1。
AC代码
/*
*
*/
//POJ不支持
//i为循环变量,a为初始值,n为界限值,递增
//i为循环变量, a为初始值,n为界限值,递减。
using namespace std;
const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5+4;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//
int t;
int n,T;
int a[maxn];
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
while(cin>>t){
while(t--){
cin>>n>>T;
map<int,int> p1;
map<int,int> p2;
rep(i,1,n){
cin>>a[i];
}
rep(i,1,n){
if(p1[T-a[i]]>0){
if(p1[T-a[i]]>p2[T-a[i]]){
p2[a[i]]++;
a[i]=1;
}
else{
p1[a[i]]++;
a[i]=0;
}
}
else{
p1[a[i]]++;
a[i]=0;
}
}
rep(i,1,n){
cout<<a[i]<<" ";
}
cout<<endl;
}
}
return 0;
}