思路:

搞了半天发现和绝对值无关。

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的更多相关文章

  1. [CF1166C]A Tale of Two Lands题解

    比赛的时候lowerbound用错了 现场WA on test4(好吧我承认我那份代码确实有除了lowerbound以外的问题) 于是只能手动二分 (我好菜啊QAQ 经过一波数学推算,我们发现,设序列 ...

  2. 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 ...

  3. 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 ...

  4. <每日一题> Day7:CodeForces-1166C.A Tale of Two Lands (二分 + 排序)

    原题链接 参考代码: #include <cstdio> #define mid ((l + r) / 2) #include <algorithm> using namesp ...

  5. CodeForces 1166C A Tale of Two Lands

    题目链接:http://codeforces.com/problemset/problem/1166/C 题目大意 给定 n 个数,任选其中两个数 x,y,使得区间 [min(|x - y|, |x ...

  6. Codeforces Round #561 (Div. 2)

    C. A Tale of Two Lands 题意: 给出 n 个数,问有多少点对(x,y)满足 |x-y| ≤ |x|,|y| ≤ |x+y|: (x,y) 和 (y,x) 表示一种答案: 题解: ...

  7. 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 ...

  8. 简洁美观的Java博客系统Tale开源了,让每一个有故事的人更好的表达想法

    Tale Tale的英文含义为故事,我相信每个坚持写Blog的人都是有故事的:中文你叫它 塌了 也无所谓 . Tale 使用了轻量级mvc框架 Blade 开发,默认主题使用了漂亮的 pinghsu, ...

  9. 如何快速部署国人开源的 Java 博客系统 Tale

    除了闷头专研技术之外,程序员还需要不断地写作进行技术积累,写博客是其中最重要的方式之一.商业博客平台不少,但是更符合程序员背景的方案,是自己开发一个博客平台或者使用开源的博客平台. 开源的博客平台多如 ...

随机推荐

  1. PowerShell自动部署网站—(2)、安装.Net Framework

    #$PSScriptRoot = "D:\Website":$PSScriptRoot 用于获取执行脚本所在的目录,但是PowerShell 2.0 不支持,需要人为赋值成绝对路径 ...

  2. rt-thread的定时器管理源码分析

    1 前言 rt-thread可以采用软件定时器或硬件定时器来实现定时器管理的,所谓软件定时器是指由操作系统提供的一类系统接口,它构建在硬件定时器基础之上,使系统能够提供不受数目限制的定时器服务.而硬件 ...

  3. cocos2dx 3.0 用ClippingNode做游戏的新手引导

    转自:http://blog.csdn.net/star530/article/details/20851263 本篇介绍的是用ClippingNode 做游戏的新手引导,额,或者说是做新手引导的一种 ...

  4. Binary Tree Inorder Traversal-非递归实现中序遍历二叉树

    题目描述: 给定一颗二叉树,使用非递归方法实现二叉树的中序遍历 题目来源: http://oj.leetcode.com/problems/binary-tree-inorder-traversal/ ...

  5. linux命令配置IP详解

    在Linux系统中,TCP/IP网络是通过若干个文本文件进行配置的,有时需要编辑这些文件来完成联网工作. vi /etc/sysconfig/network-scripts/ifcfg-eth0 :进 ...

  6. linux下gsoap的初次使用 -- c风格加法实例

    摘自: http://blog.csdn.net/jinpw/article/details/3346844 https://www.cnblogs.com/dkblog/archive/2011/0 ...

  7. Git的使用 强制放弃本地所有修改,获取master中最新版本更新本地

    git fetch --all git reset --hard origin/master git fetch --all 的意思是,下载远程库的所有内容,但不与本地做任何合并 git reset ...

  8. Java8函数式接口之Predicate<T>

    作用: 这是一个功能接口,因此可以作为lambda表达式或方法引用的赋值目标. 实例: /** * Created by luo on 2017/5/3. */ public class Predic ...

  9. 【读后感1】SQL2008技术内幕- SQL逻辑查询处理

    引言观点 1. 编程语言日新月异,但是从没有人否定sql 在现代编程中的巨大作用和 持续的可利用性.SQL以对人类友好的阅读体验提供数据查询能力( 相比其他编程语言 ), 同时在各种数据库平台中,基础 ...

  10. [openjudge] 1455:An Easy Problem 贪心

    描述As we known, data stored in the computers is in binary form. The problem we discuss now is about t ...