Codeforces Round #673 (Div. 2) B. Two Arrays (贪心)

题意:给你一组数\(a\)和一个数\(T\),将这组数分为两组\(c\)和\(d\),定义\(f(x)\)为数组\(x\)中任意两个不同元素的和为\(T\)的个数,问为了使\(min(f(c)+f(d))\),应该怎样对\(a\)分组.
题解:我们可以分成三种情况,假如一组数中所有元素都\(< \frac{T}{2}\),或者\(>\frac{T}{2}\),那么它们的\(f(x)\)都为\(0\),然而对于\(a[i]=\frac {T}{2}\)的情况,我们将其交叉放在两组即可.
代码:
int t;
int n;
ll T;
ll a[N]; int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>t;
while(t--){
cin>>n>>T;
for(int i=1;i<=n;++i){
cin>>a[i];
}
int col;
int cnt=0;
for(int i=1;i<=n;++i){
if(T%2==0 && a[i]*2==T){
cnt=1-cnt;
col=cnt;
}
else if(a[i]<=T/2){
col=0;
}
else col=1;
cout<<col<<" ";
}
cout<<'\n';
} return 0;
}
Codeforces Round #673 (Div. 2) B. Two Arrays (贪心)的更多相关文章
- Codeforces Round #673 (Div. 2) B. Two Arrays(数学)
题目链接:https://codeforces.com/contest/1417/problem/B 题意 定义 $f(a)$ 为数组 $a$ 中满足: $i < j$ $a_i + a_j = ...
- Codeforces Round #673 (Div. 2) A. Copy-paste(贪心)
题目链接:https://codeforces.com/contest/1417/problem/A 题意 给出一个大小为 $n$ 的数组 $a$,每次操作可以选择两个数,然后将一个数加到另一个数上, ...
- Codeforces Round #673 (Div. 2)
[Codeforces Round #673 (Div. 2) ] 题目链接# A. Copy-paste 思路: 贪心的策略.每次只加上最小的就可以了 #include<bits/stdc++ ...
- Codeforces Round #767 (Div. 2)——B. GCD Arrays
B. GCD Arrays 题源:https://codeforces.com/contest/1629/problem/B 题目大意 给出一段区间[l, r],可以进行操作(把任意两个数拿出来,把他 ...
- Codeforces Round #673 (Div. 2) C. k-Amazing Numbers(思维)
题目链接:https://codeforces.com/contest/1417/problem/C 题意 给出一个大小为 $n$ 的数组 $a$,计算当 $k$ 从 $1$ 到 $n$ 取值时在所有 ...
- Codeforces Round #673 (Div. 2) D. Make Them Equal(数论/构造)
题目链接:https://codeforces.com/contest/1417/problem/D 题意 给出一个大小为 $n$ 的正整数数组 $a$ ,每次操作如下: 选择 $i,j$ 和 $x$ ...
- Codeforces Round #673 (Div. 2) C. k-Amazing Numbers (DP,思维)
题意:有一组数,分别用长度从\([1,n]\)的区间去取子数组,要求取到的所有子数组中必须有共同的数,如果满足条件数组共同的数中最小的数,否则输出\(-1\). 题解:我们先从后面确定每两个相同数之间 ...
- Codeforces Round #258 (Div. 2) . Sort the Array 贪心
B. Sort the Array 题目连接: http://codeforces.com/contest/451/problem/B Description Being a programmer, ...
- Codeforces Round #180 (Div. 2) D. Fish Weight 贪心
D. Fish Weight 题目连接: http://www.codeforces.com/contest/298/problem/D Description It is known that th ...
随机推荐
- binlog-do-db
如果只是对一个数据库设置,其实没有效果的,其他数据还是会记录binlog的 binlog-ignore-db =database b binlog日志里面将不会记录database b的所有相关的操 ...
- Can't locate Time/HiRes.pm in @INC (@INC contains
Can't locate Time/HiRes.pm in @INC (@INC contains: /usr/local/lib/perl5 /usr/local/share/perl5 /usr/ ...
- mysql—make_set函数
使用格式:MAKE_SET(bits,str1,str2,-) 1 返回一个设定值(含子字符串分隔字符串","字符),在设置位的相应位的字符串.str1对应于位0,str2到第1位 ...
- ospf-lite runs over tcp / udp port 8899.
draft-thomas-reed-ospf-lite-01 - ospf-lite https://tools.ietf.org/html/draft-thomas-reed-ospf-lite-0 ...
- 思考gRPC :为什么是HTTP/2
Introducing gRPC Support with NGINX 1.13.10 - NGINX https://www.nginx.com/blog/nginx-1-13-10-grpc/ 思 ...
- 接口 Interfaces
Interfaces - zope.interface 5.0.2.dev0 documentation https://zopeinterface.readthedocs.io/en/latest/ ...
- How does Circus stack compare to a classical stack?
Frequently Asked Questions - Circus 0.15.0 documentation https://circus.readthedocs.io/en/latest/faq ...
- win api 窗口操作-窗口置顶与寻找与激活
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos https://docs.micr ...
- try-catch 异常捕获学习
#include <iostream> #include <string> #include <vector> #include <stdexcept> ...
- Java调用RestFul接口
使用Java调用RestFul接口,以POST请求为例,以下提供几种方法: 一.通过HttpURLConnection调用 1 public String postRequest(String url ...