CodeForces - 1300D Aerodynamic(几何+思维)

题目链接:点击查看

题目大意:给出一个凸多边形,将凸多边形通过平移,使平移后的凸多边形可以将原点包含在内(在边或点上也算),所有满足条件的凸多边形所形成的新图形,一定是一个凸多边形,问新图形和原图形是否为相似图形

题目分析:这个题光读题可能不太好读明白,但是看了样例给出的图示后大概就能明白题意了,其实题目做起来比较简单,将给出的样例在纸上稍微画画就可以大胆猜测了,满足相似的充分必要条件是点数为偶数,且为中心对称图形,证明的话可以参照这个up主的视频,我感觉讲的很到位了:

https://www.bilibili.com/video/av87962198?p=4

鉴于几何问题光靠语言描述可能太抽象了,所以去看一下视频绝对是比较高效的学习方法

代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
using namespace std;
   
typedef long long LL;
  
typedef unsigned long long ull;
   
const int inf=0x3f3f3f3f;
   
const int N=1e5+100;
 
const double eps = 1e-8;
 
int sgn(double x){
	if(fabs(x) < eps)return 0;
	if(x < 0)return -1;
	else return 1;
}
 
struct Point{
	double x,y;
	Point(){}
	Point(double _x,double _y){
		x = _x;
		y = _y;
	}
	void input(){
		scanf("%lf%lf",&x,&y);
	}
	bool operator == (Point b)const{
		return sgn(x-b.x) == 0 && sgn(y-b.y) == 0;
	}
	Point operator +(const Point &b)const{
		return Point(x+b.x,y+b.y);
	}
	Point operator /(const double &k)const{
		return Point(x/k,y/k);
	}
}point[N];
 
bool check(int n)
{
	n/=2;
	Point mark=(point[1]+point[n+1])/2;
	for(int i=2;i<=n;i++)
		if(!(mark==(point[i]+point[i+n])/2))
			return false;
	return true;
}
 
int main()
{
//#ifndef ONLINE_JUDGE
//  freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
//#endif
//  ios::sync_with_stdio(false);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		point[i].input();
	if(n&1)
		return 0*printf("NO");
	if(check(n))
		puts("YES");
	else
		puts("NO");
	
	
 
      
      
      
      
      
      
      
      
      
    return 0;
}
发布了646 篇原创文章 · 获赞 20 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_45458915/article/details/104272643