uva 1595

原题

经典的题, 验证点集的轴对称性

方法就是,  将所有点记录,枚举每个点的对称点看是否存在,不存在则NO

#include 
#include 
#include 
#include 
#include 
#include  
#include 
#include 
#include 
#include 
#include 
#include  
#include 
#include 
#include 
#include 
using namespace std;
const int MAXN = 1000;
typedef long long LL;
typedef long long Type;
/*
uva 1595
	1. 不是中心对称 
	2. 中点横坐标即最左边的点和最右边的点连线的中点 
	3. 多尝试DEBUG BY STEP, 仔细找出与人工计算出的数据不同的计算结果
	4. 对时间要求不高的题目可以先尝试最简单的枚举, 先不优化 
 用一正一反两个迭代器相向迭代是否可行 : 否 (排序不对称) 
*/

#define SOLUTION1

struct Dot{
	int x;
	int y;
	Dot(){
		x = y = 0;
	}
	Dot(int _x,int _y){
		x = _x;
		y = _y;
	}
	
};

bool operator<(const Dot & d1, const Dot & d2){
	if( d1.x!=d2.x ){
		return d1.x record;

void FindMid(float & midx){
	int cnt = 0;
	map::iterator it = record.begin(), it2 = record.end();
	it2--; 
	midx = (it->first.x + it2->first.x)/2.0;
	
	return ;
}

int main(){
//	freopen("input2.txt","r",stdin);
	int T;
	cin >> T;
	while( T-- ){
		cin >> N;
		if ( N<=0 ) continue;
		record.clear();
		Dot d;
		for(int i=0; i> d.x >> d.y;
			record[d] = true;
		}
		bool flag = true;
		int cnt = 0;
		float midx;
		map::iterator it = record.begin();
		FindMid(midx);
//		cout << "mid = " << mid << ", midx = " << midx << ", midy = " << midy << endl;
		while( it!=record.end() ){
//			cout << it->first.x << " " << it->first.y << endl;
			d.x = it->first.x + (midx-(double)it->first.x)*2.0;
			d.y = it->first.y;
			if( !record[d] ){
				flag = false;
				break;
			}
			record[d] = false;
			it++;
		}
		if( flag ){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		} 
	}
	
	return 0;
} 



你可能感兴趣的:(OJ)