CF1166C A Tale of Two Lands
思路:
搞了半天发现和绝对值无关。
http://codeforces.com/blog/entry/67081
实现:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[];
int main()
{
int n;
while (cin >> n)
{
ll ans = ;
for (int i = ; i < n; i++) { cin >> a[i]; a[i] = abs(a[i]); }
sort(a, a + n);
for (int i = ; i < n; i++)
{
ans += upper_bound(a + i + , a + n, * a[i]) - a - i - ;
}
cout << ans << endl;
}
return ;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[];
int main()
{
int n;
while (cin >> n)
{
ll ans = ;
for (int i = ; i < n; i++) { cin >> a[i]; a[i] = abs(a[i]); }
sort(a, a + n);
int l = , r = ;
while (l < n)
{
while (r < n && a[r] <= * a[l]) r++;
ans += r - l - ;
l++;
}
cout << ans << endl;
}
return ;
}
CF1166C A Tale of Two Lands的更多相关文章
- [CF1166C]A Tale of Two Lands题解
比赛的时候lowerbound用错了 现场WA on test4(好吧我承认我那份代码确实有除了lowerbound以外的问题) 于是只能手动二分 (我好菜啊QAQ 经过一波数学推算,我们发现,设序列 ...
- 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
链接:https://codeforces.com/contest/1166/problem/C 题意: The legend of the foundation of Vectorland talk ...
- <每日一题> Day7:CodeForces-1166C.A Tale of Two Lands (二分 + 排序)
原题链接 参考代码: #include <cstdio> #define mid ((l + r) / 2) #include <algorithm> using namesp ...
- CodeForces 1166C A Tale of Two Lands
题目链接:http://codeforces.com/problemset/problem/1166/C 题目大意 给定 n 个数,任选其中两个数 x,y,使得区间 [min(|x - y|, |x ...
- Codeforces Round #561 (Div. 2)
C. A Tale of Two Lands 题意: 给出 n 个数,问有多少点对(x,y)满足 |x-y| ≤ |x|,|y| ≤ |x+y|: (x,y) 和 (y,x) 表示一种答案: 题解: ...
- ural 1343. Fairy Tale
1343. Fairy Tale Time limit: 1.0 secondMemory limit: 64 MB 12 months to sing and dance in a ring the ...
- 简洁美观的Java博客系统Tale开源了,让每一个有故事的人更好的表达想法
Tale Tale的英文含义为故事,我相信每个坚持写Blog的人都是有故事的:中文你叫它 塌了 也无所谓 . Tale 使用了轻量级mvc框架 Blade 开发,默认主题使用了漂亮的 pinghsu, ...
- 如何快速部署国人开源的 Java 博客系统 Tale
除了闷头专研技术之外,程序员还需要不断地写作进行技术积累,写博客是其中最重要的方式之一.商业博客平台不少,但是更符合程序员背景的方案,是自己开发一个博客平台或者使用开源的博客平台. 开源的博客平台多如 ...
随机推荐
- Mesos的quorum配置引发的问题
Mesos安装完毕后,发现agent无法和master关联(通过WebUI的agent页面无法看到agent信息),查看日志显示: Elected as the leading master! sta ...
- C#如何立即回收内存
1.把对象赋值为null 2.立即调用GC.Collect(); 注意:这个也只是强制垃圾回收器去回收,但具体什么时候执行不确定. 代码: class Test { ~Test() { Consol ...
- 人工智能实践:linux 和 python 基础简介
linux下的目录 绝对路径:是以根目录(" / ")为起点的完整路径,以你所要到的目录为终点. 相对路径:是你当前的目录(" .")为起点的路径,以你所要到的 ...
- Oracle创建表,并添加默认值和备注
create table testemp( id varchar2(50) default sys_guid(),deptno varchar2(20) ,--部门编码 ename varchar2( ...
- 《精通Spring4.X企业应用开发实战》读后感第五章(方法注入)
- go开发环境搭建及开发工具简介
go语言包的下载地址:https://www.golangtc.com/download 这里以window10的操作系统环境为例 go的开发工具下载地址:https://www.golangtc.c ...
- Linux 之 .bashrc 文件作用
Linux 系统中很多 shell,包括bash,sh,zsh,dash 和 korn 等,不管哪种 shell 都会有一个 .bashrc 的隐藏文件,它就相当于 shell 的配置文件. 一般会有 ...
- Django 开发拓展 auth 模块,注册用户时发生 ValueError: The given username must be set
原因 使用局部钩子函数 _clean_fields() 对 username.email 字段进行验证时,未返回,具体请参考 _clean_fields() 函数源码. def clean_usern ...
- chrome调式工具
1.Elementshttps://segmentfault.com/a/1190000008316690 2. Consolehttps://segmentfault.com/a/119000000 ...
- Java基础--环境配置、简介
一.环境配置 1.傻瓜式安装JDK,若提示安装JRE,将其置于JDK同一安装目录即可. 2.配置JAVA_HOME, 指向JDK的安装目录.比如 JAVA_HOME = %JDK安装目录% 3.配置 ...