0
点赞
收藏
分享

微信扫一扫

B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)

mm_tang 2022-06-24 阅读 45

原题链接: ​​https://codeforces.com/contest/1417/problems​​

B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)_#define
测试样例

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

题意: (理解题意很关键。) 给你一个数组B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)_#define_02和不幸值B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)_数组_03,要求你将数组B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)_#define_02分成数组B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)_ios_05和数组B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)_ios_06,使得B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)_ios_07最小。
其中B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)_ios_08的值为数组B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)_ios_05B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)_ios_10使得B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)_ios_11的数量对数。(m为数组B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)_ios_05的长度)

解题思路: 我们按题意去模拟构造即可,带有点贪心的味道。遍历一遍数组B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)_#define_02对于每个元素B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)_数组_14我们判断B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)_#define_15有没有在我们要放置的目标数组。(目标数组由我们自己决定,这个意思其实就是符合就放该数组。)如果有,我们就进行判断放哪里是最优的,这个同样是可以通过B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)_ios_16容器来获取判断的。 如果没有自然就放默认数组。记住:放了哪个数组,对应的B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)_数组_17容器要记录+1。

AC代码

/*

*
*/
#include<bits/stdc++.h> //POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

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;
}


举报

相关推荐

0 条评论