HDU 6055 Regular polygon (暴力)

题意,二维平面上给N个整数点,问能构成多少个不同的正多边形。

析:容易得知只有正四边形可以使得所有的顶点为整数点。所以只要枚举两个点,然后去查找另外两个点就好。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 500 + 10;
const LL mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
  return r > 0 && r <= n && c > 0 && c <= m;
}

map<P, int> mp;
P p[maxn];

P solve(const P &p1, const P &p2){
  int detx = p2.first - p1.first;
  int dety = p2.second - p1.second;
  return P(p1.first-dety, p1.second+detx);
}

int main(){
  while(scanf("%d", &n) == 1){
    mp.clear();
    for(int i = 0; i < n; ++i){
      scanf("%d %d", &p[i].first, &p[i].second);
      mp[p[i]] = true;
    }

    int ans = 0;
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < n; ++j){
        if(i == j)  continue;
        P p1 = solve(p[i], p[j]);
        if(!mp.count(p1))  continue;
        P p2 = solve(p1, p[i]);
        if(!mp.count(p2))  continue;
        ++ans;
      }
    }
    printf("%d\n", ans/4);
  }
  return 0;
}

  

时间: 2024-12-19 16:13:08

HDU 6055 Regular polygon (暴力)的相关文章

HDU 6055 - Regular polygon

/* HDU 6055 - Regular polygon [ 分析,枚举 ] 题意: 给出 x,y 都在 [-100, +100] 范围内的 N 个整点,问组成的正多边形的数目是多少 N <= 500 分析: 分析可知,整点组成的正多边形只能是正方形 故枚举两个点,验证剩下两个点的位置 坑点: 由于点的范围是 [-100, +100],故经过计算得出的点的范围可能是 [-300,+300],注意越界 编码时长:46分钟(-1) */ #include <bits/stdc++.h> u

【2017多校训练2+计算几何+板】HDU 6055 Regular polygon

http://acm.hdu.edu.cn/showproblem.php?pid=6055 [题意] 给定n个格点,问有多少个正多边形 [思路] 因为是格点,只可能是正方形 枚举正方形的对角线,因为有两条对角线,最后答案要/2 也可以枚举正方形的边,因为有四条边,答案要/4 看当前对角线确定的正方形是否存在,用几何知识求出目标点的坐标,然后二分查找目标点是否存在 [Accepted] 1 #include <cstdio> 2 #include <cstring> 3 #incl

【二分+计算几何】hdu 4033 Regular Polygon

[二分+计算几何]hdu 4033 Regular Polygon 题目链接:hdu 4033 Regular Polygon 题目大意 已知正多边形中的一个内点到所有顶点的距离,求多边形的边长. 二分问题一般都存在含有一个未知量的方程(等式关系),通过二分未知量的范围实现查找,这道题目的几何关系就是:知道一边,内角和(围着内点)等于360度.根据三角不等式确定边的二分范围,二分查找边使得内角之和为2π即可. 说一下思路 笔者根据第一条边和最后一条边确定二分边的范围,边确定由余弦定理能确定所有内

hdu 4033 Regular Polygon 计算几何 二分+余弦定理

题目链接 给一个n个顶点的正多边形, 给出多边形内部一个点到n个顶点的距离, 让你求出这个多边形的边长. 二分边长, 然后用余弦定理求出给出的相邻的两个边之间的夹角, 看所有的加起来是不是2Pi. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #includ

HDU 6055 17多校 Regular polygon(计算几何)

Problem Description On a two-dimensional plane, give you n integer points. Your task is to figure out how many different regular polygon these points can make. Input The input file consists of several test cases. Each case the first line is a numbers

hdu6055 Regular polygon 脑洞几何 给定n个坐标(x,y)。x,y都是整数,求有多少个正多边形。因为点都是整数点,所以只可能是正四边形。

/** 题目:hdu6055 Regular polygon 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6055 题意:给定n个坐标(x,y).x,y都是整数,求有多少个正多边形.因为点都是整数点,所以只可能是正四边形. 思路: (x1,y2)(x2,y2)=>(x,y) = (x2-x1,y2-y1) 向量(x,y)逆时针旋转90度:(-y,x):那么可以得到垂直(x,y)的向量,并通过(x2,y2)获得以(x2,y2)为起点的向量终点(x2+(

HDU 4499 Cannon (暴力搜索)

题意:在n*m的方格里有t个棋子,问最多能放多少个炮且每个炮不能互相攻击(炮吃炮) 炮吃炮:在同一行或同一列且中间有一颗棋子. #include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include <queue> #include <math.h> #define M 50 #define LL long long using

HDU 4902 线段树||暴力

给定一个序列,两种操作 1:把一段变成x. 2:把一段每个数字,如果他大于x,就变成他和x的gcd,求变换完后,最后的序列. 线段树解法:用lazy标记下即可,优化方法还是很巧妙的, Accepted 4902 515MS 3308K 1941 B C++ #include "stdio.h" #include "string.h" struct node { int l,r,x;// 在叶子节点代表值,树节点代表成端更新的lazy操作. }data[400010]

HDU 4831 Scenic Popularity 暴力模拟

Scenic Popularity Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 340    Accepted Submission(s): 110 Problem Description 临近节日,度度熊们最近计划到室外游玩公园,公园内部包括了很多的旅游景点区和休息区,由于旅游景点很热门,导致景点区和休息区都聚集了很多人.所以度度熊