UVA1595_Symmetry
给出平面上n个点,问你能不能找到一个竖线让他们对称
这道题后面发现真的不难,又不止一种方法
我当时写的很挫,死脑筋的就找一个点的对称点存不存在,用结构体存点信息,在排序用find找,,然后不知道一堆wa
后面发现排序之后,如果位置i和n-i-1这两个点不对称就一定不存在!!!!
可以用反证法得知
//
// Created by Zeroxf on 2015-08-19-15.36
// Copyright: (c) 2015 Zeroxf. All rights reserved
//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<map>
#include<queue>
#include<vector>
using namespace std;
struct node{
int x,y;
node(int x,int y):x(x),y(y){}
bool operator < (const node& rhs)const{
return x < rhs.x||(x==rhs.x&&y<rhs.y);
}
bool operator != (const node& rhs)const{
return x != rhs.x || y != rhs.y;
}
};
vector<node> v;
const int maxn = 1e5;
long long t,n,sum,ok,mid;
int x,y;
int main(){
cin>>t;
while(t--){
cin>>n;
sum = 0; ok =true;v.clear();
for(int i = 0; i < n; i++){
scanf("%d%d",&x,&y);
sum += x;
v.push_back(node(x,y));
}
if((sum*2)%n != 0) ok = false;
else {
sort(v.begin(),v.end());
mid = sum *2 /n;
for(int i = 0;i < v.size(); i++){
node findv(mid-v[i].x,v[i].y);
int pos = lower_bound(v.begin(), v.end(), findv) - v.begin();
if(pos>=v.size()||v[pos]!=findv){
ok = false;break;
}
}
}
if(ok) cout<<"YES\n";
else cout<<"NO\n";
}
return 0;
}
UVA1595_Symmetry的更多相关文章
随机推荐
- Java业务代理模式~
业务代理模式用于解耦表示层和业务层. 它基本上用于减少表示层代码中的业务层代码的通信或远程查找功能.在业务层有以下实体. 客户端(Client) - 表示层代码可以是JSP,servlet或UI ja ...
- 静态链表 C++版
笔记静态链表的实现 #include "stdafx.h" #include<iostream> using namespace std; #define MAXSIZ ...
- 【题解】Beads
题目描述 Zxl有一次决定制造一条项链,她以非常便宜的价格买了一长条鲜艳的珊瑚珠子,她现在也有一个机器,能把这条珠子切成很多块(子串),每块有k(k>0)个珠子,如果这条珠子的长度不是k的倍数, ...
- CopyOnWriteArrayList(复制数组 去实现)
一.Vector和SynchronizedList 1.1回顾线程安全的Vector和SynchronizedList 我们知道ArrayList是用于替代Vector的,Vector是线程安全的容器 ...
- data-*存数据,拿出ul li中的数据
<ul class="questions"> <li> <div class="question">1.您的年龄是?< ...
- β版本apk下载地址及源代码github地址
β版本下载地址 源代码下载地址:https://github.com/U-Help/Version-1.0 安装包下载地址:百度网盘:(密码q3sy)https://pan.baidu.com/s ...
- shell函数的存储和显示
- 三、IIS通过目录方式部署以供外部调试
一.IIS 下面是通过 gif 为 因项目是bin生成后的,非运行方式的调试,所以断点调试无效,仅修改文件后,右击项目重新生成解决方案即可,好处:启动快,坏处:不可以断点调试查看变量和分步执行语句.
- 西里尔字 俄语 - Cyrillic
https://zh.wikipedia.org/wiki/%E8%A5%BF%E9%87%8C%E5%B0%94%E5%AD%97%E6%AF%8D 其他编码[编辑] 其他适用西里尔字母的字符编码系 ...
- 解析mysql慢日志
mysql慢日志太多,需要分析下具体有哪些慢日志 mysql可以直接记录所有慢日志,现在的问题是将日志文件sql进行去重 想了老半天该怎样将sql的查询字段去掉进行排序,没有get到重点.后来发现my ...