Codeforces Round #561 (Div. 2) C. A Tale of Two Lands
链接:https://codeforces.com/contest/1166/problem/C
题意:
The legend of the foundation of Vectorland talks of two integers xx and yy. Centuries ago, the array king placed two markers at points |x||x| and |y||y| on the number line and conquered all the land in between (including the endpoints), which he declared to be Arrayland. Many years later, the vector king placed markers at points |x−y||x−y| and |x+y||x+y| and conquered all the land in between (including the endpoints), which he declared to be Vectorland. He did so in such a way that the land of Arrayland was completely inside (including the endpoints) the land of Vectorland.
Here |z||z| denotes the absolute value of zz.
Now, Jose is stuck on a question of his history exam: "What are the values of xx and yy?" Jose doesn't know the answer, but he believes he has narrowed the possible answers down to nnintegers a1,a2,…,ana1,a2,…,an. Now, he wants to know the number of unordered pairs formed by two different elements from these nn integers such that the legend could be true if xx and yywere equal to these two values. Note that it is possible that Jose is wrong, and that no pairs could possibly make the legend true.
思路:
因为需要满足条件 min(|x-y|, |x+y|) <= |x| <= |y| <= max(|x-y|, |x+y|).
所以将x变成-x并不影响条件。所以将所有输入全部取绝对值。
再排序,二分查找。
代码:
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- const int MAXN = 2e5+10;
- int a[MAXN];
- int main()
- {
- int n;
- cin >> n;
- for (int i = 1;i <= n;i++)
- cin >> a[i], a[i] = abs(a[i]);
- sort(a+1, a+1+n);
- LL res = 0;
- for (int i = 1;i <= n;i++)
- res += (upper_bound(a+1, a+1+n, 2*a[i])-a)-i-1;
- cout << res << endl;
- return 0;
- }
Codeforces Round #561 (Div. 2) C. A Tale of Two Lands的更多相关文章
- Codeforces Round #561 (Div. 2) A Tale of Two Lands 【二分】
A Tale of Two Lands 题目链接(点击) The legend of the foundation of Vectorland talks of two integers xx and ...
- Codeforces Round #561 (Div. 2)
C. A Tale of Two Lands 题意: 给出 n 个数,问有多少点对(x,y)满足 |x-y| ≤ |x|,|y| ≤ |x+y|: (x,y) 和 (y,x) 表示一种答案: 题解: ...
- Codeforces Round #561 (Div. 2) B. All the Vowels Please
链接:https://codeforces.com/contest/1166/problem/B 题意: Tom loves vowels, and he likes long words with ...
- Codeforces Round #561 (Div. 2) A. Silent Classroom
链接:https://codeforces.com/contest/1166/problem/A 题意: There are nn students in the first grade of Nlo ...
- Codeforces Round 561(Div 2)题解
这是一场失败的比赛. 前三题应该是随便搞的. D有点想法,一直死磕D,一直WA.(赛后发现少减了个1……) 看E那么多人过了,猜了个结论交了真过了. 感觉这次升的不光彩……还是等GR3掉了洗掉这次把, ...
- Codeforces Round #561 (Div. 2) E. The LCMs Must be Large(数学)
传送门 题意: 有 n 个商店,第 i 个商店出售正整数 ai: Dora 买了 m 天的东西,第 i 天去了 si 个不同的个商店购买了 si 个数: Dora 的对手 Swiper 在第 i 天去 ...
- Codeforces Round #561 (Div. 2) A. Silent Classroom(贪心)
A. Silent Classroom time limit per test1 second memory limit per test256 megabytes inputstandard inp ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- tensorflow knn mnist
# MNIST Digit Prediction with k-Nearest Neighbors #----------------------------------------------- # ...
- Spring笔记05(Spring JDBC三种数据源和ORM框架的映射)
1.ORM框架的映射 01.JDBC连接数据库以前的方式代码,并给对象赋值 @Test /** * 以前的方式jdbc */ public void TestJdbc(){ /** * 连接数据库的四 ...
- Seal Report_20160923
Seal Report算是报表工具中比较好用的一个,它提供了一个完整的从其他任何数据库产生报表的架构.该产品主要关注于容易安装和报表设计,一旦安装好,报表很快就可以建立并且发布.该组件完全开源,使用C ...
- 浏览器,tab页显示隐藏的事件监听--页面可见性
//监听浏览器tab切换,以便在tab切换之后,页面隐藏的时候,把弹幕停止 document.addEventListener('webkitvisibilitychange', function() ...
- Java 核心读书笔记 第11章
1. 异常 用户希望在出现错误时,程序能够采用一些理智的行为. 如果由于出现错误而使得某些操作无法完成,程序应该: 返回到一种安全状态,并能够进行一些其他的命令: 或者:允许用于保存所有操作的结果, ...
- Jasper:SAOP API 函数
ylbtech-Jasper:SAOP API 函数 1.设备API返回顶部 1. 设备 设备 API 可以访问详细的设备(SIM 卡)信息,包括当前会话.您也可以更改属性值. API 调用 描述 A ...
- Angular 2 ViewChild & ViewChildren
一.ViewChild ViewChild 是属性装饰器,用来从模板视图中获取匹配的元素.视图查询在 ngAfterViewInit 钩子函数调用前完成,因此在 ngAfterViewInit 钩子函 ...
- 详解select()函数---
以后看 http://hi.baidu.com/bimufo/item/139700e4d880cba1c00d755c
- UVa 10801 Lift Hopping (Dijkstra)
题意:有一栋100层的大楼(标号为0~99),里面有n个电梯(不超过5个),以及要到达的层数(aid),然后是每个电梯走一层所需的时间, 再n行就是对应每个电梯可以到达的层数,数量不定.然后每装换一次 ...
- 微软 Remote App
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://wangchunhai.blog.51cto.com/225186/201073 ...