Codeforces Round #673 (Div. 2) B. Two Arrays(数学)
题目链接:https://codeforces.com/contest/1417/problem/B
题意
定义 $f(a)$ 为数组 $a$ 中满足:
- $i < j$
- $a_i + a_j = T$
的二元组 $(i,j)$ 的个数。
试将一个大小为 $n$ 的数组 $a$ 划分为 $b,c$ 两组,使得 $f(b) + f(c)$ 最小。
题解
两数之和为 $T$ 有两种情况:
- 一个数小于 $T$,一个数大于 $T$,此时以 $\frac{T}{2}$ 为分界线分到两组即可
- 两个数都等于 $\frac{T}{2}$,此时将等于 $\frac{T}{2}$ 的数轮流分到两组即可
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, T;
cin >> n >> T;
int curMid = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (T % 2 == 0 and x == T / 2) {
cout << (curMid++ & 1);
} else if (2 * x < T) {
cout << 0;
} else {
cout << 1;
}
cout << " \n"[i == n - 1];
}
}
return 0;
}
Codeforces Round #673 (Div. 2) B. Two Arrays(数学)的更多相关文章
- Codeforces Round #673 (Div. 2) B. Two Arrays (贪心)
题意:给你一组数\(a\)和一个数\(T\),将这组数分为两组\(c\)和\(d\),定义\(f(x)\)为数组\(x\)中任意两个不同元素的和为\(T\)的个数,问为了使\(min(f(c)+f(d ...
- 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) A. Copy-paste(贪心)
题目链接:https://codeforces.com/contest/1417/problem/A 题意 给出一个大小为 $n$ 的数组 $a$,每次操作可以选择两个数,然后将一个数加到另一个数上, ...
- 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 #180 (Div. 2) C. Parity Game 数学
C. Parity Game 题目连接: http://www.codeforces.com/contest/298/problem/C Description You are fishing wit ...
- Codeforces Round #188 (Div. 2) C. Perfect Pair 数学
B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/p ...
随机推荐
- 【Azure Developer】使用Postman获取Azure AD中注册应用程序的授权Token,及为Azure REST API设置Authorization
Azure Active Directory (Azure AD) is Microsoft's cloud-based identity and access management service, ...
- Selenium WebDriver 定位之Xpath定位
Selenium 定位之Xpath定位: 1.绝对路径定位:以/开头从根节点一直找到当前节点,不推荐使用决定路径定位方式 2.相对路径定位:使用"//"表示相对路径定位,格式:// ...
- Go中由WaitGroup引发对内存对齐思考
转载请声明出处哦~,本篇文章发布于luozhiyun的博客:https://www.luozhiyun.com 本文使用的go的源码时14.4 WaitGroup使用大家都会,但是其中是怎么实现的我们 ...
- ctfhub技能树—信息泄露—备份文件下载—网站源码
打开靶机 查看网页内容 使用dirsearch进行扫描 命令如下 python3 dirsearch.py -u http://challenge-91f1f5e6a791ab02.sandbox.c ...
- 基于Dockfile构建JAVA环境网站镜像
查看本地目录 [root@docker tomcat]# ls apache-tomcat-8.5.16.tar.gz Dockerfile jdk-8u91-linux-x64.tar.gz ...
- 超精讲-逐例分析CS:LAB2-Bomb!(上)
0. 环境要求 关于环境已经在lab1里配置过了这里要记得安装gdb 安装命令 sudo yum install gdb 实验的下载地址 http://csapp.cs.cmu.edu/3e/labs ...
- JDBC代码的优化
JDBC代码简化以及PreparedStatement和Statement接口 抽取 JDBC的Bug sql语句可以拼接导致登录功能中如果用户名或者密码中出现'or'2'='2则一定可以登录的bug ...
- 命名秘籍周获近五千星——GitHub 热点速览 v.21.04
作者:HelloGitHub-小鱼干 命名一直是编程界的难点,这次 naming-cheatsheet 就能帮上你的忙.按照它的 SID(Short..Intuitive.Descriptive)原则 ...
- linux串口编程
按照对linux系统的理解,串口编程的顺序无非就是open,read,write,close,而串口有波特率.数据位等重要参数需要设置,因此还应该用到设置函数,那么接下来就带着这几个问题去学习linu ...
- 超精讲-逐例分析 CSAPP:实验2-Bomb!(下)
好了话不多说我们书接上文继续来做第二个实验下面是前半部分实验的连接 5. 第五关 首先感觉应该是个递归问题 /* Round and 'round in memory we go, where we ...