给出平面上N(N<=1000)个点。问是否可以找到一条竖线,使得所有点左右对称,如图所示:

则左边的图形有对称轴,右边没有。
 
Sample Input 

3
5
-2 5
0 0
6 5
4 0
2 3
4
2 3
0 4
4 0
0 0
4
5 14
6 10
5 10
6 14

Sample Output

YES
NO
YES 写题永远都是wrong answer.....
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std; const int maxn = ; struct point{
double x, y; bool operator < (const point & rhs) const{
return x < rhs.x;
}
}p[maxn]; int main()
{
int T;
cin >> T;
while(T--){
int n;
double line; //line 为对称轴的位置
bool flag = true; cin >> n; for(int i = ;i < n; i++){
double x, y;
cin >> x >> y;
p[i].x = x;
p[i].y = y;
} sort(p,p+n); for(int i = ; i < n/; i++){
int k = ;
for(int j = n-; j>n/-;j--){
cout<<"** "<<j<<" "<<p[i].y<<" "<<p[j].y<<endl;
if(p[i].y == p[j].y){
p[j].y = -0.111;
k = ;
if(i == )line = ( p[i].x + p[n--i].x ) / 2.0;
else {
double l = ( p[i].x + p[j].x ) / 2.0;
cout<< p[i].x<<" - "<<p[j].x<<endl;
if(l != line){
cout << <<" "<< l<< " "<< line<<endl;
flag = false;
break;
}
}
cout<<"line "<<line<<endl;
break;
}
} if(k){
if(!flag)break;
}
else {
flag = false;
break;
} } if(flag && (n%)){
if(p[n/].x != line )flag = false;
cout<<<<" "<< p[n/].x<<" "<<line<<endl;
} if(flag) cout << "YES" << endl;
else cout << "NO" << endl; }
system("pause");
return ;
}

那就找错。。。

以上代码没有考虑到对称轴上有去多点的情况

将点排序后,先分偶数奇数个点两种情况,根据最中间的两个点或一个点计算出对称轴再进一步判断其他点是否符合

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std; const int maxn = ; struct point{
double x, y; bool operator < (const point & rhs) const{
return x < rhs.x;
}
}p[maxn]; int main()
{
int T;
cin >> T;
while(T--){
int n ,n0 ;
double line; //line 为对称轴的位置
bool flag = true; cin >> n; for(int i = ;i < n; i++){
double x, y;
cin >> x >> y;
p[i].x = x;
p[i].y = y;
} sort(p,p+n); if(n%){ //奇数个点
line = p[n/].x;
n0 = n/;
}
else { //偶数个点
line = (p[n/].x+p[n/-].x)/2.0;
n0 = n/-;
} for(int i = ; i <= n0; i++){
int k = ;
for(int j = n-; j>n/-;j--){
if(p[i].y == p[j].y){
p[j].y = -0.111;
k = ;
double l = ( p[i].x + p[j].x ) / 2.0; if(l != line){
flag = false;
break;
} break;
}
else{
if(p[i].x == line&&p[n-i-].x == line){
k = ;
break;
}
} } if(k){
if(!flag)break;
}
else {
flag = false;
break;
} } if(flag) cout << "YES" << endl;
else cout << "NO" << endl; }
//system("pause");
return ;
}

uva 1595 Symmetry“结构体”的更多相关文章

  1. uva 1595 - Symmetry

    思路:首先,如果这些点对称,那么它们的对称轴是x = m(m是所有点横坐标的平均值):   把这些点放到一个集合里,然后扫描每个点,计算出它关于x = m的对称点,看这个点是否在集合里面.   如果有 ...

  2. UVa 1595 Symmetry(set)

    We call a figure made of points is left-right symmetric as it is possible to fold the sheet of paper ...

  3. UVa 1595 Symmetry (set && math)

    题意:给出n个在直角坐标系上的点,问你能不能找出一条竖轴(即垂直于x的轴)使得所有的点根据这条轴对称,能则输出YES,否则输出NO 分析:首先需要找到对称轴的值,将所有n个点的x轴的值加起来然后去除以 ...

  4. Go结构体实现类似成员函数机制

    Go语言结构体成员能否是函数,从而实现类似类的成员函数的机制呢?答案是肯定的. package main import "fmt" type stru struct { testf ...

  5. C#基础回顾(二)—页面值传递、重载与重写、类与结构体、装箱与拆箱

    一.前言 -孤独的路上有梦想作伴,乘风破浪- 二.页面值传递 (1)C#各页面之间可以进行数据的交换和传递,页面之间可根据获取的数据,进行各自的操作(跳转.计算等操作).为了实现多种方式的数据传递,C ...

  6. go语言结构体

    定义: 是一种聚合的数据类型,是由零个或多个任意类型的值聚合成的实体. 成员: 每个值称为结构体的成员. 示例: 用结构体的经典案例处理公司的员工信息,每个员工信息包含一个唯一的员工编号.员工的名字. ...

  7. C语言中的结构体

    用户自己建立自己的结构体类型 1.  定义和使用结构体变量 (1).结构体的定义 C语言允许用户自己建立由不同类型数据组成的组合型的数据结构,它称为结构体. (2).声明一个结构体类型的一般形式为: ...

  8. C++_系列自学课程_第_12_课_结构体

    #include <iostream> #include <string> using namespace std; struct CDAccount { double bal ...

  9. java socket传送一个结构体给用C++编写的服务器解析的问题

    另一端是Java写客户端程序,两者之间需要通信.c++/c接收和发送的都是结构体,而Java是直接发送的字节流或者byte 数组.解决方法:c++/c socket 在发送结构体的时候其实发送的也是字 ...

随机推荐

  1. 2、 Spark Streaming方式从socket中获取数据进行简单单词统计

    Spark 1.5.2 Spark Streaming 学习笔记和编程练习 Overview 概述 Spark Streaming is an extension of the core Spark ...

  2. poj3264 线段树

    Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 44121   Accepted: 20715 ...

  3. l连接远程桌面

    参考:http://www.windows7en.com/Win7/17168.html 重要命令:mstsc

  4. :before与:after伪类的应用

    1.小三角样式

  5. php中的时区设置

    date_default_timezone_set('PRC'); 设置为中国时区

  6. WinPython安装问题(pyzmq问题导致)

    最近yvivid安装WinPython-32bit-3.4.4.1, 安装后,运行spyder运行时出现如下错误, Traceback (most recent call last): File &q ...

  7. 5W1H分析法

    "5W1H分析法"也叫"六何分析法",它是一种分析方法也可以说是一种创造技法.是对选定的项目.工序和操作,都要从原因(Why).对象(What).地点(Wher ...

  8. Oracle asm介绍和安装linux+oracle10g+asm过程

    Oracle asm介绍和安装linux5.2+oracle10g+asm过程   1)ASM(自动存储管理)的来由:   ASM是Oracle 10g R2中为了简化Oracle数据库的管理而推出来 ...

  9. WebApi 自定义过滤器实现支持AJAX跨域的请求

    我想关于此类话题的文章,大家一搜铺天盖地都是,我写此文的目的,只是对自己学习过程的记录,能对需要的朋友有所帮助,也百感荣幸!!!废话不多说,直接上代码! 客户端:很简单的AJAX请求 <html ...

  10. smartassembly 使用指南

    原文 http://www.cnblogs.com/hsapphire/archive/2010/09/21/1832758.html smartassembly 提供了一种用于优化和混淆你的 .ne ...