先排序后二分。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; #define MAXN 1005 typedef struct {
int x, y;
} node_st; node_st nodes[MAXN];
int n; bool comp(node_st a, node_st b) {
if (a.x == b.x)
return a.y < b.y;
else
return a.x < b.x;
} bool find(int x, int y) {
int l=, r=n-, mid; while (l <= r) {
mid = (l+r)>>;
if (nodes[mid].x==x && nodes[mid].y==y)
return true;
if (nodes[mid].x > x)
r = mid - ;
else if (nodes[mid].x < x)
l = mid + ;
else if (nodes[mid].y > y)
r = mid - ;
else
l = mid + ;
}
return false;
} int main() {
int t, ans;
int i, j; scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (i=; i<n; ++i)
scanf("%d%d", &nodes[i].x, &nodes[i].y);
sort(nodes, nodes+n, comp);
for (ans=,i=; i<n; ++i) {
for (j=i+; j<n; ++j) {
if ((nodes[i].x-nodes[j].x)==(nodes[i].y-nodes[j].y) && find(nodes[i].x, nodes[j].y) && find(nodes[j].x, nodes[i].y))
++ans;
}
}
printf("%d\n", ans);
} return ;
}

【HDOJ】2428 Stars的更多相关文章

  1. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  2. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  3. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

  4. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...

  5. 【HDOJ】【2829】Lawrence

    DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...

  6. 【HDOJ】【3415】Max Sum of Max-K-sub-sequence

    DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...

  7. 【HDOJ】【3530】Subsequence

    DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...

  8. 【HDOJ】【3068】最长回文

    Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...

  9. 【HDOJ】【1512】Monkey King

    数据结构/可并堆 啊……换换脑子就看了看数据结构……看了一下左偏树和斜堆,鉴于左偏树不像斜堆可能退化就写了个左偏树. 左偏树介绍:http://www.cnblogs.com/crazyac/arti ...

随机推荐

  1. change buffer

    https://yq.aliyun.com/articles/222 change buffer: insert buffer delete buffer purge buffer 1.innodb_ ...

  2. 模拟dispatch_once

    dispatch_once   dispatch_once可以保证一段代码只被执行一次,因此出现之后使用最多的场景就是实现单例.本文来模拟实现dispatch_once的功能. 模拟dispatch_ ...

  3. laravel扩展包开发步骤总结

    1. 创建包 php artisan workbench vendor/package --resources     注:  vendor:开发商名   package:包名   2.修改下包里co ...

  4. list-style无颜色问题解决,list-style-type无颜色解决

    list-style无颜色问题解决,list-style-type无颜色解决 >>>>>>>>>>>>>>>& ...

  5. Unity3D GUI学习之GUILayout控件及使用

    GUILayout也可以定义一些控件,并且它们会自动垂直对其: GUILayout.Button("开始游戏"); GUILayout.Button("结束游戏" ...

  6. 06MySQL数据库入门

    1.数据库的概念 数据库是保存数据的仓库,可以方便的把数据放进去,并且把数据根据各种需求取出来. 数据库管理系统(Database Management System,DBMS)是对数据库进行管理(增 ...

  7. javascript的框架演化

    说起javascript不同的人或许有不同的看法,一些资深后台程序员在刚开始的时候根本没有把它当作是一门编程语言,但是随着后面js框架的出现,以及面向对象的程序设计,还有原型,闭包的不断使用,后台程序 ...

  8. hdoj 2601(判断N=i*j+i+j)

    Problem E Time Limit : 6000/3000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...

  9. mahout的安装、配置及运行java程序

    一.下载安装包: http://mahout.apache.org/general/downloads.html 二.解压: 将下载的安装包解压到需要的目录下 三.配置环境变量: export MAH ...

  10. 【POJ2761】【区间第k大】Feed the dogs(吐槽)

    Description Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to feed the dogs ...