Squares-暴力枚举或者二分
Time Limit:3500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
id=15030" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="display:inline-block; position:relative; padding:0px; margin-right:0.1em; vertical-align:middle; overflow:visible; text-decoration:none; font-family:Verdana,Arial,sans-serif; font-size:1em; border:1px solid rgb(211,211,211); color:rgb(85,85,85)">POJ
2002
Description
as a regular octagon also has this property.
So we all know what a square looks like, but can we find all possible squares that can be formed from a set of stars in a night sky? To make the problem easier, we will assume that the night sky is a 2-dimensional plane, and each star is specified by its x
and y coordinates.
Input
points are distinct and the magnitudes of the coordinates are less than 20000. The input is terminated when n = 0.
Output
Sample Input
4
1 0
0 1
1 1
0 0
9
0 0
1 0
2 0
0 2
1 2
2 2
0 1
1 1
2 1
4
-2 5
3 7
0 0
5 2
0
Sample Output
1
6
1
/*
Author: 2486
Memory: 24256 KB Time: 375 MS
Language: C++ Result: Accepted
*/
//此题目暴力暴力枚举
//通过已经确定好的两点,算出剩下的两点
//(有两种情况)
//一个在上面,一个以下
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=20000+5;
struct point{
int x,y;
}ps[1005];
int n,ans;
bool vis[maxn<<1][maxn<<1];
int main(){
while(~scanf("%d",&n),n){
ans=0;
for(int i=0;i<n;i++){
scanf("%d%d",&ps[i].x,&ps[i].y);
ps[i].x+=20000,ps[i].y+=20000;//在数组里面能够存储负数
vis[ps[i].x][ps[i].y]=true;//标记着这个点存在
}
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
if(i==j)continue;//分别代表着上下两种不同的正方形
int nx1=ps[i].x+ps[i].y-ps[j].y;
int ny1=ps[i].y+ps[j].x-ps[i].x;
int nx2=ps[j].x+ps[i].y-ps[j].y;
int ny2=ps[j].y+ps[j].x-ps[i].x;
if(vis[nx1][ny1]&&vis[nx2][ny2])ans++;
nx1=ps[i].x-(ps[i].y-ps[j].y);
ny1=ps[i].y-(ps[j].x-ps[i].x);
nx2=ps[j].x-(ps[i].y-ps[j].y);
ny2=ps[j].y-(ps[j].x-ps[i].x);
if(vis[nx1][ny1]&&vis[nx2][ny2])ans++;
}
}
for(int i=0;i<n;i++){
vis[ps[i].x][ps[i].y]=false;//必需要进行清零,不能用memset,由于数组有点大
}
printf("%d\n",ans/4);
}
return 0;
}
Squares-暴力枚举或者二分的更多相关文章
- CODE FESTIVAL 2017 qual A--B-fLIP(换种想法,暴力枚举)
个人心得:开始拿着题目还是有点懵逼的,以前做过相同的,不过那是按一个位置行列全都反之,当时也是没有深究.现在在打比赛不得不 重新构思,后面一想把所有的状态都找出来,因为每次确定了已经按下的行和列后,按 ...
- poj 1753 Flip Game(暴力枚举)
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 52279 Accepted: 22018 Des ...
- [Cqoi2015] 编号 【逆向思维,暴力枚举】
Online Judge:Luogu-P4222 Label:逆向思维,暴力枚举 题目描述 你需要给一批商品编号,其中每个编号都是一个7位16进制数(由0~9, a-f组成).为了防止在人工处理时不小 ...
- CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)
题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...
- 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)
/* 将给定的一个字符串分解成ABABA 或者 ABABCAB的形式! 思路:暴力枚举A, B, C串! */ 1 #include<iostream> #include<cstri ...
- HNU 12886 Cracking the Safe(暴力枚举)
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...
- 51nod 1116 K进制下的大数 (暴力枚举)
题目链接 题意:中文题. 题解:暴力枚举. #include <iostream> #include <cstring> using namespace std; ; ; ch ...
- Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举
题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...
- bzoj 1028 暴力枚举判断
昨天梦到这道题了,所以一定要A掉(其实梦到了3道,有两道记不清了) 暴力枚举等的是哪张牌,将是哪张牌,然后贪心的判断就行了. 对于一个状态判断是否为胡牌,1-n扫一遍,然后对于每个牌,先mod 3, ...
随机推荐
- Python-操作符和表达式
//: 除后向下取正 -3//2=-2 **: 幂 3**3 = 27 not: ! and: && or: || 除了以上几个之外,其余与C++相同 length = 3 widt ...
- CodeForces 680A&680B&680C&680D Round#356
昨天晚上实在是=_=困...(浪了一天)就没有去打Codeforces 中午醒来看看题,还不太难. A题:模拟(水题 3minAC) // by Sirius_Ren #include <cst ...
- POJ 2688 Cleaning Robot
题意: 给你一个n*m的图.你从'o'点出发,只能走路(图中的'.')不能穿墙(图中的'x'),去捡垃圾(图中的' * ')问最少走多少步能捡完所有垃圾,如有垃圾捡不了,输出-1. 思路: 有两个思路 ...
- struts2拦截器(四)
struts2拦截器原理: 当请求action时,struts2会查找配置文件,并根据配置实例化相对的 拦截器对象,然后串成一个列表,然后一个一个的调用列表中的拦截器. 比如:某些页面必须登录才可以访 ...
- nodejs脚手架express-generator
1.安装生成器 npm install express-generator -g 2. 创建名称为APP的应用: express my-project 3.安装依赖包 cd my-project np ...
- 使用NDK编译VTK
VTK提供了对安卓的CMAKE编译支持,其介绍文件在源代码根目录下的 "/cmake/android.toolchain.cmake". 对Wndows的编译自持描述为: 注意:但 ...
- 微服务常见安全认证方案Session token cookie跨域
HTTP 基本认证 HTTP Basic Authentication(HTTP 基本认证)是 HTTP 1.0 提出的一种认证机制,这个想必大家都很熟悉了,我不再赘述.HTTP 基本认证的过程如下: ...
- Git 从github克隆文件至本地
学习阶段,同一个项目,如何保障家与公司的代码同步的问题,可以使用git克隆来解决 在家将项目提交到了GitHub上,现在来到公司,需要将GitHub上的项目克隆到本地,那么对于公司的电脑来说,同样需要 ...
- 【转载】Intellij IDEA的Hibernate简单应用
转载自: https://www.cnblogs.com/yangyquin/p/5438248.html 1.创建数据库及其表 create database demo; use demo ...
- python 直接存入Excel表格
def write_excels(self, document): outwb = openpyxl.Workbook() outws = outwb.create_sheet(index=0) fo ...