这道题其实就是个水题,可惜我忘了一种传说中叫双指针的东西,太弱了,呜呜。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cstring>
 5 #include <vector>
 6 #include <map>
 7 using namespace std;
 8 int n;
 9 long long a[5010],b[5010];
10 int num[5010];
11 template<class T> inline void readint(T& x) {
12       char c;
13       int mul = 1;
14       while((c = getchar()) != EOF){
15          if(c == '-')mul = -1;
16          if(c >= '0' && c <= '9'){
17               x = c-'0';
18               break;
19          }
20       }
21       if(c == EOF){x = EOF;return;}
22       while(c = getchar()){
23           if(c >= '0' && c <= '9'){
24               x = (x<<1)+(x<<3)+(c-'0');
25           }else break;
26       }
27       x *= mul;
28 }
29 int main(){
30     //freopen("in.txt","r",stdin);
31     while(~scanf("%d",&n)){
32         memset(num,0,sizeof num);
33         for(int i=0;i<n;i++) readint(a[i]),b[i]=a[i];
34         sort(a,a+n);
35         sort(b,b+n);
36         int ct=unique(b,b+n)-b;
37         for(int i=0;i<n;i++){
38            int x=lower_bound(b,b+ct,a[i])-b;
39            num[x]++;
40         }
41         long long ans=0;
42         for(int i=0;i<ct;i++){
43            int j=i+1;
44            int x=lower_bound(b,b+ct,2*b[i])-b;
45            if(x<ct&&b[x]==2*b[i]){
46               ans+=num[x]*(long long)num[i]*(num[i]-1)/2;
47            }
48            int k=lower_bound(b,b+ct,b[i]-b[j])-b;
49            for(;j<ct;j++){
50               while(k<ct&&b[i]+b[j]>b[k]) k++;
51               if(k>=ct) continue;
52               if(b[i]+b[j]==b[k]){
53                  ans+=(long long)num[i]*num[j]*num[k];
54               }
55            }
56         }
57         printf("%lld\n",ans);
58     }
59     return 0;
60 }

uva11386

转载于:https://www.cnblogs.com/wonderzy/p/3458409.html

uva11386 Triples相关推荐

  1. Codechef:Path Triples On Tree

    Path Triples On Tree 题意是求树上都不相交或者都相交的路径三元组数量. 发现blog里没什么树形dp题,也没有cc题,所以来丢一道cc上的树形dp题. 比较暴力,比较恶心 #inc ...

  2. D. Pythagorean Triples(1487D)(打表找规律 + 二分)

    D. Pythagorean Triples(1487D)(打表找规律 + 二分) 题目来源:D. Pythagorean Triples 题意: 给定一个 n,求满足以下条件的数对 (a, b, c ...

  3. hdu2017青岛网络赛Pythagoras(Tree of primitive Pythagorean triples)

    题面: Given a list of integers a0,a1,a2,⋯,a2k−1. Pythagoras triples over 109 are all solutions of x2+y ...

  4. D. Pythagorean Triples

    题目来源 一.题目 A Pythagorean triple is a triple of integer numbers (a,b,c) such that it is possible to fo ...

  5. C. Pythagorean Triples

    链接:https://codeforces.com/problemset/problem/707/C Katya studies in a fifth grade. Recently her clas ...

  6. 浙江大学软件学院2020年保研真题Distance of Triples (25 分)

    时间限制:300 ms 内存限制:64 MB The distance of triples (三元组) (a,b,c) is defined as D(a,b,c)=∣a−b∣+∣b−c∣+∣c−a ...

  7. leetcode 1925. Count Square Sum Triples(python)

    描述 A square triple (a,b,c) is a triple where a, b, and c are integers and a^2 + b^2 = c^2. Given an ...

  8. Linking two modules of different target triples:

    HokoBlur BoxBlur.rs文件编译报错 解决办法 buildToolsVersion 修改为对api版本的 "28.0.3" 即可解决报错 compileSdkVers ...

  9. 【ARC 123B】Increasing Triples(贪心)

    Increasing Triples 题目链接:ARC 123B 题目大意 给你三个长度为 n 的数组 ai,bi,ci. 你可以把这三个数组里面的数任意换位置(只能一个数组内换). 然后要你最大化满 ...

最新文章

  1. 动态查看JVM内存的工具
  2. 软件设计模式之单例模式
  3. fatal: git-write-tree: error building trees
  4. 第15周学习进度情况
  5. html-前端调用MD5对密码进行加密
  6. 电路基础学习笔记2:串并联电路
  7. 简述计算机硬件,简述计算机硬件的组成部分
  8. layui列表筛选列_基于layui实现高级搜索(筛选)功能
  9. Deep Light Enhancement without Paired Supervision (非配对数据监督学习用于低曝光图像增强)
  10. php 二维数组根据参数分组
  11. 百度AI身份证识别接口,iOS上传base64图片报错216201问题解决办法总结
  12. dns服务器未影响无法上网,dns服务器未响应导致无法上网怎么办
  13. NAT之SNAT和DNAT
  14. Python获取所有股票代码以及股票历史成交数据分析(二)
  15. 印刷方式——标识丝印工艺
  16. 把复杂的事物及逻辑尽量简单化
  17. DateTime常用方法,不积硅步无以至千里
  18. 对圆柱面的曲面积分_计算对面积的曲面积分zds 圆柱面x^2+y^2=1介于平面z=0 和z=3之间的部分...
  19. Hologres慢Query日志查看与分析
  20. 国家级、省级认定(备案)科技企业孵化器、众创空间奖励申请指南

热门文章

  1. 人工智能导论——概念篇
  2. ECCV2020超分辨率方向论文整理笔记
  3. 互联网公司那些价值观-阿里巴巴
  4. three.js创建简单的凹凸贴图
  5. Mathematica最简教程
  6. 微信JSSDK使用签名算法
  7. 有3n个花盆,红色、蓝色和黄色的各n个。开始时排列的顺序是混乱的,如黄、红、蓝、黄、黄、蓝、黄、红、红……
  8. 低功耗蓝牙开发权威指南--第三部分 主机 (第9-12章)
  9. Python编写一个函数,计算一个整数各个数字之和
  10. 计算机文件夹操作教案,文件文件和文件夹教案