uva 1595

本文介绍了一种通过枚举所有点及其对称点来验证点集轴对称性的算法。该方法首先记录所有点,然后检查每个点的对称点是否存在于记录中。若存在,则继续检查;若不存在,则判断点集非轴对称。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原题

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

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

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring> 
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <deque> 
#include <map>
#include <cassert>
#include <iomanip>
#include <list>
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<d2.x;
	}
	return d1.y<d2.y;
}

int N ;
map<Dot,bool> record;

void FindMid(float & midx){
	int cnt = 0;
	map<Dot,bool>::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<N; i++){
			cin >> d.x >> d.y;
			record[d] = true;
		}
		bool flag = true;
		int cnt = 0;
		float midx;
		map<Dot,bool>::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;
} 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值