题目链接

  • 题意:

    给n个点,求能组成的正方形的个数。

    四边均平行与坐标轴

  • 大神的分析:



    经典题

    我们考虑每一种x坐标,显然仅仅有<= sqrt{N}个x坐标出现了> sqrt{N}次,我们称这些为大的,其它为小的。

    我们先考虑大的x和其它x之间的答案,先O(sqrt{N})枚举一个大的坐标,然后for其它的每一个点,这样能够依据x坐标的差算出正方形的边长,hash检查一下就能知道这个正方形是否存在。

    之后考虑小的x和小的x之间的答案,注意到我们能够对每一个横坐标直接平方for,这样仅仅有(sqrt{N})^2 + (sqrt{N})^2 + ... + (sqrt{N})^2 = N^1.5的枚举量,之后也能够hash检查。

    O(N^1.5)

const int MAXN = 100001;

vector<int> vt[MAXN];
bool match(int ind, int val)
{
if (ind >= MAXN) return false;
return binary_search(all(vt[ind]), val);
} int main()
{
// freopen("in.txt", "r", stdin);
int n, a, b, bound;
while (~RI(n))
{
REP(i, MAXN) vt[i].clear();
bound = (int)sqrt(n * 1.0); REP(i, n)
{
RII(a, b);
vt[a].push_back(b);
}
REP(i, MAXN)
{
sort(all(vt[i]));
}
LL ans = 0;
REP(i, MAXN)
{
if (vt[i].size() > bound)
{
FF(j, i + 1, MAXN)
{
int dis = j - i;
REP(k, vt[j].size())
{
int val = vt[j][k];
if (match(j, val + dis) && match(i, val) && match(i, val + dis))
ans++;
}
}
}
else
{
REP(j, vt[i].size()) FF(k, j + 1, vt[i].size())
{
int dis = vt[i][k] - vt[i][j];
if (match(i + dis, vt[i][k]) && match(i + dis, vt[i][j]))
ans++;
}
}
}
cout << ans << endl;
}
return 0;
}

Codeforces Round #243 (Div. 1)——Sereja and Squares的更多相关文章

  1. Codeforces Round #243 (Div. 2)——Sereja and Swaps

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012476429/article/details/24665103 题目链接 题意: 给定一个整数 ...

  2. Codeforces Round #243 (Div. 2)——Sereja and Table

    看这个问题之前,能够先看看这个论文<一类算法复合的方法>,说白了就是分类讨论,可是这个思想非常重要 题目链接 题意: 首先给出联通块的定义:对于相邻(上下和左右)的同样的数字视为一个联通块 ...

  3. Codeforces Round #243 (Div. 1)——Sereja and Two Sequences

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012476429/article/details/24798219 题目链接 题意:给两个长度分别 ...

  4. Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读

    http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...

  5. Codeforces Round #243 (Div. 1)A. Sereja and Swaps 暴力

    A. Sereja and Swaps time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. Codeforces Round #243 (Div. 2) C. Sereja and Swaps

    由于n比较小,直接暴力解决 #include <iostream> #include <vector> #include <algorithm> #include ...

  7. Codeforces Round #243 (Div. 2) B. Sereja and Mirroring

    #include <iostream> #include <vector> #include <algorithm> using namespace std; in ...

  8. Codeforces Round #243 (Div. 2) A. Sereja and Mugs

    #include <iostream> #include <vector> #include <algorithm> #include <numeric> ...

  9. Codeforces Round #243 (Div. 2) C. Sereja and Swaps(优先队列 暴力)

    题目 题意:求任意连续序列的最大值,这个连续序列可以和其他的 值交换k次,求最大值 思路:暴力枚举所有的连续序列.没做对是因为 首先没有认真读题,没看清交换,然后,以为是dp或者贪心 用了一下贪心,各 ...

随机推荐

  1. iOS-CALayer && CAAnimation

    一.CALayer 1.CALayer CALayer属于QuartzCore.framework框架,从Xcode5起我们不必要手动导入这个库. CALayer我们可以简单理解为一个层.当我们绘制的 ...

  2. How to resolve mysql problem when you get code 2003(10061) and 1130

    When I use Navicate to connect to mysql on Ubuntu, I got message 2003(10061) firstly. To resovle thi ...

  3. 关于在IE下面promise兼容的解决办法

    下载es6-promise就可以解决这个问题 import ES6Promise from "es6-promise" if(!window.Promise) { console. ...

  4. Springboot 版本+ jdk 版本 + Maven 版本的匹配

    Spring boot 版本 Spring Framework jdk 版本 maven 版本 1.2.0 版本之前 6 3.0 1.2.0 4.1.3+ 6 3.2+ 1.2.1 4.1.3+ 7 ...

  5. uva 11732 (trie树)

    题意:求N个字符串两两比较,共比较了多少次? #include<iostream> #include<cstring> #include<cstdio> using ...

  6. 【Visual Studio】Windows program compatibility mode is on, turn it off……

    [问题描述]Windows 10上安装 Visual Studio Ultimate 2013,出现下面错误: [解决方案]将.iso文件解压到硬盘再安装.

  7. cpu乱序执行

    http://blog.163.com/zhaojie_ding/blog/static/1729728952007925111324379/?suggestedreading 处理器的乱序和并发执行 ...

  8. C#知识点总结:Monitor和Lock以及区别

    Monitor对象 1.Monitor.Enter(object)方法是获取锁,Monitor.Exit(object)方法是释放锁,这就是Monitor最常用的两个方法,当然在使用过程中为了避免获取 ...

  9. String()和.toString()的区别

    一.相同点:都可以转为字符串类型: 二.不同点: 1..toString() :null.toString()和undefined.toString() 程序报错误; 2..toString(): . ...

  10. SharpSSH

    SharpSSH sharpssh is a pure .NET implementation of the SSH2 client protocol suite. It provides an AP ...