分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

洛谷 P1227 [JSOI2008]完美的对称

发布时间:2023-09-06 01:23责任编辑:熊小新关键词:暂无标签

传送门

题目大意:求一些点集的公共对称中心

题解:对称中心是可以确定的,再判断。

代码:

#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#define N 20009using namespace std;int n;struct W{ ???double x,y;}w[N];bool cmp(W a,W b){ ???if(a.x==b.x)return a.y<b.y; ???return a.x<b.x;}int main(){ ???scanf("%d",&n); ???for(int i=1;i<=n;i++){ ???????scanf("%lf%lf",&w[i].x,&w[i].y); ???} ???sort(w+1,w+n+1,cmp); ???double xx=(w[1].x+w[n].x)/2.0; ???double yy=(w[1].y+w[n].y)/2.0; ???for(int i=2;i<=n;i++){ ???????if(n-i+1<=i)break; ???????double tx=(w[i].x+w[n-i+1].x)/2.0; ???????double ty=(w[i].y+w[n-i+1].y)/2.0; ???????if(tx!=xx||ty!=yy){ ???????????printf("This is a dangerous situation!\n"); ???????????return 0; ???????} ???} ???printf("V.I.P. should stay at (%.1lf,%.1lf).",xx,yy); ???return 0;}
View Code

洛谷 P1227 [JSOI2008]完美的对称

原文地址:http://www.cnblogs.com/zzyh/p/7788199.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved