Gym - 100920H 2010-2011 OpenCup IX Onsite, II Yandex Summer School H.Squares 暴力
题意:有10w个点,问你选4个点,能组成平行于坐标轴的正方形有多少个
题解:不知道正解,我的做法就是暴力的基础上优化一点,每次按x排好序,每次枚举的2个点都是x相同的
这样算是个优化?但并不能过,因为可能一列全是x相同的,于是又判了一次对于这个点,x相同的多还是y相同的多
具体实现用了个set没想到就过了
#include<bits/stdc++.h>
using namespace std;
#define N 2000006
set<int>x[N],y[N];
int n,a[N],b[N],ans=;
int main()
{
scanf("%d",&n);
for (int i=;i<=n;i++)
{
scanf("%d%d",&a[i],&b[i]);
a[i]+=1e6;b[i]+=1e6;
x[a[i]].insert(b[i]);
y[b[i]].insert(a[i]);
}
for (int i=;i<=n;i++)
{
if (x[a[i]].size()<y[b[i]].size())
{
set<int>::iterator it=x[a[i]].upper_bound(b[i]);
while (it!=x[a[i]].end())
{
int l=*it-b[i];
if (a[i]+l<N)
if (x[a[i]+l].find(b[i]+l)!=x[a[i]+l].end() && x[a[i]+l].find(b[i])!=x[a[i]+l].end()) ans++;
it++;
}
}else
{
set<int>::iterator it=y[b[i]].upper_bound(a[i]);
while (it!=y[b[i]].end())
{
int l=*it-a[i];
if (b[i]+l<N)
if (y[b[i]+l].find(a[i]+l)!=y[b[i]+l].end() && y[b[i]+l].find(a[i])!=y[b[i]+l].end()) ans++;
it++;
}
}
}
cout<<ans<<endl;
}
Gym - 100920H 2010-2011 OpenCup IX Onsite, II Yandex Summer School H.Squares 暴力的更多相关文章
- Gym - 100920E 2010-2011 OpenCup IX Onsite, II Yandex Summer School E.Paint 状压DP
题面 题意:给你n(20)个点,m(40条边),让你给每条边染一种颜色,白色0元,红色2元,蓝色1元,现在要保证每一条白边相邻的有一条红边,问至少花多少 题解:刚开始想的时候,好像觉得只用染红色和白色 ...
- VRay 2.0 SP1 2.10.01 for 3ds max 9/2008/2009/2010/2011/2012 32/64位 顶渲简体中文版+英文版[中国室内设计论坛-室内人]
VRay 2.0 SP1 2.10.01 for 3ds max 9/2008/2009/2010/2011/2012 32/64位 顶渲简体中文版+英文版[中国室内设计论坛-室内人] 对最新版本的V ...
- ACM ICPC 2010–2011, Northeastern European Regional Contest St Petersburg – Barnaul – Tashkent – Tbilisi, November 24, 2010
ACM ICPC 2010–2011, Northeastern European Regional Contest St Petersburg – Barnaul – Tashkent – Tbil ...
- 2010–2011, NEERC, Northern Subregional C.Commuting Functions
C.Commuting Functions 由于要求答案字典序最小,我们肯定希望从g(1)开始对函数g进行赋值,于是又公式f(g(x))=g(f(x)) 设f(x)=i 我们推导出 由于f是双射,当i ...
- u-boot 2011.09 使用自己的board 以及config.h
一个新的方案,用的UBOOT 可能和上一个方案是同一个,但是配置有可能不一样,今天记录一下通过修改配置文件使用新的 board 文件以及 config.h 进入 u-boot 2011.09 // 打 ...
- Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞
Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...
- Gym 101908C - Pizza Cutter - [树状数组]
题目链接:https://codeforces.com/gym/101908/problem/C 题意: 一块正方形披萨,有 $H$ 刀是横切的,$V$ 刀是竖切的,不存在大于等于三条直线交于一点.求 ...
- Gym 101972
F读错题wa了三个小时.自闭了,不然I题有可能能出的..已经想到组合数也敲完组合数板子了. A:这...**题吧,第一眼看的这个就秒了 #include<bits/stdc++.h> #d ...
- 78. Subsets(M) & 90. Subsets II(M) & 131. Palindrome Partitioning
78. Subsets Given a set of distinct integers, nums, return all possible subsets. Note: The solution ...
随机推荐
- buf.readDoubleBE()
buf.readDoubleBE(offset[, noAssert]) buf.readDoubleLE(offset[, noAssert]) offset {Number} 0 <= of ...
- buf.writeInt8()函数详解
buf.writeInt8(value, offset[, noAssert]) value {Number} 需要被写入到 Buffer 的字节 offset {Number} 0 <= of ...
- Java第九周总结
- python3 时间模块 random模块之两个小练习
话不多说,一个是算时间的,还有一个是生成验证码的 #!usr/bin/env/ python # -*- coding:utf-8 -*- # Author: XiaoFeng import time ...
- LINUX-DEB 包 (Debian, Ubuntu 以及类似系统)
dpkg -i package.deb 安装/更新一个 deb 包 dpkg -r package_name 从系统删除一个 deb 包 dpkg -l 显示系统中所有已经安装的 deb 包 dpkg ...
- python3虚拟环境应用
python3自带虚拟环境venv,大致操作只有三步 1. 创建虚拟环境 python3 -m venv venv(名称随意) 2. 激活虚拟环境 source venv/bin/activate 3 ...
- vue父组件向子组件传递参数
父组件中引用的子组件 <pics :is-pics="showpics" // 这是我们要传递的参数 :is-product="productMsg" : ...
- vuex----mutation和action的基本使用
我们要实现的很简单,就是点击+1的count加一,点击-1的时候count-1 一.mutation 在vue 中,只有mutation 才能改变state. mutation 类似事件,每一个mu ...
- 7-26 Windows消息队列
7-26 Windows消息队列(25 分) 消息队列是Windows系统的基础.对于每个进程,系统维护一个消息队列.如果在进程中有特定事件发生,如点击鼠标.文字改变等,系统将把这个消息加到队列当中. ...
- UVALive 7008 Tactical Multiple Defense System
Tactical Multiple Defense System Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld &a ...