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, ...
随机推荐
- MySQL-基础操作之增删改查
1.增 (1)创建数据库dks create database dks; (2)创建名为t1的表,并指定引擎和字符集: ) not null,ages int) engine=innodb defau ...
- Halcon学习笔记之支持向量机(二)
例程:classify_halogen_bulbs.hdev 在Halcon中模式匹配最成熟最常用的方式该署支持向量机了,在本例程中展示了使用支持向量机对卤素灯的质量检测方法.通过这个案例,相信大家可 ...
- strcpy自实现
为了避免strcpy源串覆盖问题(P220),自实现strcpy. #include <stdio.h> #include <string.h> #include <as ...
- 数据库操作通用函数,增强可重复利用性能C#,asp.net.sql2005
using System;using System.Data;using System.Data.SqlClient; namespace com.hua..li{ /// <summary&g ...
- VS2015 右侧导航插件地址
右侧导航插件: https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.ProductivityPowe ...
- android 国际化 横屏(land) 竖屏(port)margin外边距和padding内边距
android 国际化 横屏(land) 竖屏(port) 边距又分为内边距和外边距,即margin和padding.
- 关于MVC4.0版本以上的RegisterBundles用法
public class BundleConfig { //新建了一个项目文件,打开App_Start下的BundleConfig看看, public static void RegisterBund ...
- C# 连接 access2010数据库
//定义一个新的OleDb连接 System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(); // ...
- vegas pro 15解决导入的视频和音频有噪声问题,亲测可行
中文步骤: 按住Shift->点击选项->首选项,松开Shift 点击右上角"内部"选项卡,在最下面的搜索栏输入SO4 找到第二项Enable So4 Compound ...
- python3:语法变动 及新特性
python3.0 对python2.x 升级后重大语法变动,幸好留下2.7.6及后续2版本,保持一些语法兼容. 原始地址:http://hi.baidu.com/jxq61/item/3a24883 ...