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
除了闷头专研技术之外,程序员还需要不断地写作进行技术积累,写博客是其中最重要的方式之一.商业博客平台不少,但是更符合程序员背景的方案,是自己开发一个博客平台或者使用开源的博客平台. 开源的博客平台多如 ...
随机推荐
- 利用oracle session context 向oracle传值
有时候,我们在执行数据库请求时,需要向数据库传一些应用程序的上下文信息,比如当前应用的用户.举个场景,我们要通过触发器记录对某些关键表的修改日志,日志包括修改的表,字段,字段的值,修改的时间,当然非常 ...
- C# 获取外网IP和运营商和城市
/// <summary> /// 获取客户端外网IP,省份,城市,运营商 /// 2012年12月18日 15:07 /// </summary> public class ...
- HDU - 5492 Find a path(方差公式+dp)
Find a path Frog fell into a maze. This maze is a rectangle containing NN rows and MM columns. Each ...
- Linux 之问题集锦(一)
1. 打开目录时,怎么只显示一个窗口 计算机 -- 编辑 -- 首选项 -- 行为 -- 总是总浏览器窗口中打开 2. linux中添加PATH时出现 Found a swap file by the ...
- Spring Data JPA stackoverflow
1.禁止使用lombok 的@Data 注释 使用@Data注释后,默认会重写父类的toString()方法,hashcode()等方法,在往map里存的时候,会根据equals和hashcode方法 ...
- [51nod] 1267 4个数和为0 暴力+二分
给出N个整数,你来判断一下是否能够选出4个数,他们的和为0,可以则输出"Yes",否则输出"No". Input 第1行,1个数N,N为数组的长度(4 < ...
- CentOS 安装配置vncserver
yum 安装tiger vncserver yum install tigervnc-server 安装后输入 vncserver 设置密码 3.配置用户 vim /etc/sysconfig/vnc ...
- 关于通过angularJs将页面中的html table 导出生成excel
直接上代码: <button class="btn btn-link" ng-click="exportToExcel('#table1')"> & ...
- 2014-11-1 NOIP模拟赛1
冲刺NOIP2014复赛模拟题第六套第二试 题目名称 日历游戏 最大公约数 密码 英文代号 calendar gcd pasuwado 输入文件名 calendar.in gcd.in pasuw ...
- MySQL学习基础之一 — 数据库查询
廖大神的练手神器:在线SQL: https://www.liaoxuefeng.com/wiki/1177760294764384/1179611432985088 运行MySQL等实际的数据库软件, ...