一开始以为死于精度……调了半天发现死于long long……

一、二分法:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
bool cmp(const int &a,const int &b){return a>b;}
int n,a[100001],b[100001];
long long ans;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%d",&a[i]);
sort(a+1,a+n+1,cmp);
memcpy(b,a,(n+1)*sizeof(int));
for(int i=1;i<=n;++i) b[i]*=10;
for(int i=1;i<=n;++i) ans+=(long long)(upper_bound(b+i+1,b+n+1,a[i]*9,cmp)-b-i-1);
printf("%lld\n",ans);
return 0;
}

二、尺取法:

#include<cstdio>
#include<algorithm>
using namespace std;
bool cmp(const int &a,const int &b){return a>b;}
int n,a[100001];
long long ans;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%d",&a[i]);
sort(a+1,a+n+1,cmp);
int head=1,tail=1;
while(1)
{
while(a[tail]*10>=a[head]*9 && tail<=n) ++tail;
if(head==n) break;
ans+=(long long)(tail-head-1);
++head;
}
printf("%lld\n",ans);
return 0;
}

【二分法】【尺取法】bzoj2348 [Baltic 2011]Plagiarism的更多相关文章

  1. BZOJ2348: [Baltic 2011]Plagiarism

    2348: [Baltic 2011]Plagiarism Time Limit: 1 Sec  Memory Limit: 256 MBSubmit: 304  Solved: 141[Submit ...

  2. HDU 4123 (2011 Asia FZU contest)(树形DP + 维护最长子序列)(bfs + 尺取法)

    题意:告诉一张带权图,不存在环,存下每个点能够到的最大的距离,就是一个长度为n的序列,然后求出最大值-最小值不大于Q的最长子序列的长度. 做法1:两步,第一步是根据图计算出这个序列,大姐头用了树形DP ...

  3. USACO 2011 November Cow Lineup /// map set 尺取法 oj25279

    题目大意: 输入n 接下来n行描述n头牛的编号num和品种id 得到包含所有id的最短段 输出最短段的编号差 Sample Input 625 726 115 122 320 130 1 Sample ...

  4. POJ 3061 (二分+前缀和or尺取法)

    题目链接: http://poj.org/problem?id=3061 题目大意:找到最短的序列长度,使得序列元素和大于S. 解题思路: 两种思路. 一种是二分+前缀和.复杂度O(nlogn).有点 ...

  5. Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)

    题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...

  6. 51Nod 1686 第K大区间(离散化+尺取法)

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1686 题意: 思路: 第K大值,所以可以考虑二分法,然后用尺取法去扫描, ...

  7. 题解报告:poj 3061 Subsequence(前缀+二分or尺取法)

    Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...

  8. POJ 3061 Subsequence 二分或者尺取法

    http://poj.org/problem?id=3061 题目大意: 给定长度为n的整列整数a[0],a[1],--a[n-1],以及整数S,求出总和不小于S的连续子序列的长度的最小值. 思路: ...

  9. PAT 甲级 1044 Shopping in Mars (25 分)(滑动窗口,尺取法,也可二分)

    1044 Shopping in Mars (25 分)   Shopping in Mars is quite a different experience. The Mars people pay ...

随机推荐

  1. shell脚本应用

    解析乱的日志文件到临时文件中,然后用awk  1004  cd /usr/local  1005  ll  1006  cd pttmsg/  1007  ll  1008  cd msgbin-2/ ...

  2. HDU 1203 01背包

    I NEED A OFFER! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  3. inflate

    LayoutInflater是用 来找res/layout/下的xml布局文件,并且实例化 https://www.cnblogs.com/savagemorgan/p/3865831.html

  4. JSR330的注解和spring的原生注解的比较

    下面的图比较了JSR330和spring的原生注解.其实在大多数场合下他们之间可以互相代替.有可能spring写注解时参考了JSR330的注解:

  5. Spring--环境配置

    目录 1.1 Spring jar包下载 1.2 Hello World 参考资料 1.1 Spring jar包下载 (1)进入官网http://repo.spring.io(或者 http://m ...

  6. hive的体系架构及安装

    1,什么是Hive? Hive是能够用类SQL的方式操作HDFS里面数据一个数据仓库的框架,这个类SQL我们称之为HQL(Hive Query Language) 2,什么是数据仓库? 存放数据的地方 ...

  7. 在DirectX11下用Stencil Buffer绘制可视化Depth Complexity

    这是一道在<Introduction to 3D Game Programming with DirectX 11>上的练习题. 要求把某个像素点上的Depth Complexity(深度 ...

  8. 2017年上海金马五校程序设计竞赛:Problem E : Find Palindrome (字符串处理)

    Description Given a string S, which consists of lowercase characters, you need to find the longest p ...

  9. Selenium菜鸟手册

    转自: http://www.iselenium.com/read.php?tid=458 首先声明我还是一只很菜的菜鸟,学习Selenium一个来月而已,发这个帖子是想利用我这块板砖引出真正的玉来, ...

  10. C++ 迭代器容器学习

    set的一个用法 . difference找差集 union合并set intersection找到交集 #include<iostream> #include<string> ...