poj1859The Perfect Symmetry

链接

按x或y排序,假如有对称点的话,头尾相对。

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<stdlib.h>
 6 #include<vector>
 7 #include<cmath>
 8 #include<queue>
 9 #include<set>
10 using namespace std;
11 #define N 100000
12 #define LL long long
13 #define INF 0xfffffff
14 const double eps = 1e-8;
15 const double pi = acos(-1.0);
16 const double inf = ~0u>>2;
17 struct Point
18 {
19     double x,y;
20     Point(double x=0,double y=0):x(x),y(y) {}
21 }p[N];
22 typedef Point pointt;
23 pointt operator + (Point a,Point b)
24 {
25     return Point(a.x+b.x,a.y+b.y);
26 }
27 pointt operator - (Point a,Point b)
28 {
29     return Point(a.x-b.x,a.y-b.y);
30 }
31 int dcmp(double x)
32 {
33     if(fabs(x)<eps) return 0;
34     else return x<0?-1:1;
35 }
36 bool cmp(Point a,Point b)
37 {
38     if(dcmp(a.x-b.x)==0)
39     return a.y<b.y;
40     return a.x<b.x;
41 }
42 int main()
43 {
44     int n,i,j;
45     while(scanf("%d",&n)&&n)
46     {
47         for(i = 1; i <= n ;i++)
48         scanf("%lf%lf",&p[i].x,&p[i].y);
49         sort(p+1,p+n+1,cmp);
50         double tx = (p[1].x+p[n].x)/2,ty = (p[1].y+p[n].y)/2;
51         int flag =1 ;
52         for(i = 2 ; i <= n; i++)
53         {
54             double x = (p[i].x+p[n-i+1].x)/2;
55             double y = (p[i].y+p[n-i+1].y)/2;
56             if(dcmp(x-tx)!=0||dcmp(y-ty)!=0)
57             {
58                 flag = 0;
59                 break;
60             }
61         }
62         if(flag)
63         printf("V.I.P. should stay at (%.1f,%.1f).\n",tx,ty);
64         else
65         printf("This is a dangerous situation!\n");
66     }
67     return 0;
68 }

poj1859The Perfect Symmetry

时间: 2024-10-29 03:17:52

poj1859The Perfect Symmetry的相关文章

POJ 1859 The Perfect Symmetry &amp;&amp; POJ2526 Center of symmetry(思维题)

博客原文地址:http://blog.csdn.net/xuechelingxiao/article/details/40680981 POJ 1859 : The Perfect Symmetry 题目大意: 给你n个点的座标,你的任务是判断是否存在一个中心,使得这些点中心对称.一个点集有中心对称点的条件是,存在一个点s,对于每一个点p,都存在另一个点q使得p - s = s - q . 解题思路: 既然要找中间的点,那么对于中间的点,肯定会有两边对称的点,那么说,点集排序之后,先找到排序后的

[leetcode] 367. Valid Perfect Square

Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library function such as sqrt. Example 1: Input: 16 Returns: True Example 2: Input: 14 Returns: False 使用二分查找寻找input

Poj-1274-The Perfect Stall-匈牙利算法

The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19174   Accepted: 8696 Description Farmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering pr

基于Perfect用Swift语言编写Slack聊天机器人

基于Perfect用Swift语言编写Slack聊天机器人 本项目是专门为Slack聊天机器人定制的模板服务器. 完整的源代码下载在Github https://github.com/PerfectServers/SlackBot 在本项目模板中,一个聊天机器人可以加入授权频道,读取频道内所有用户发送的"曲奇"并记录在案,而且可以直接答复用户的有关曲奇饼干的问题. 预备知识 在您决定编译.测试或者部署您自己的基于Perfect软件框架体系的聊天机器人之前,以下基础知识??不可或缺??:

7.Perfect Number

Description: We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself. Now, given an integer n, write a function that returns true when it is a perfect number and false when it is not. 解题思

Lintcode Perfect Squares

Given a positive integer n, find the least number of perfect square numbers (for example,1, 4, 9, 16, ...) which sum to n. Given n = 12, return 3 because 12 = 4 + 4 + 4Given n = 13, return 2 because 13 = 4 + 9 刷这道题目发现网上有四种解法 http://www.cnblogs.com/gr

[LeetCode] Perfect Squares

Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n. For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n = 13, return 2 because 13 = 4 + 9. Credits: Special thanks

Pat(Advanced Level)Practice--1085(Perfect Sequence)

Pat1085代码 题目描述: Given a sequence of positive integers and another positive integer p. The sequence is said to be a "perfect sequence" if M <= m * p where M and m are the maximum and minimum numbers in the sequence, respectively. Now given a s

POJ1274:The Perfect Stall(二分图最大匹配 匈牙利算法)

The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17895   Accepted: 8143 Description Farmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering pr