Symmetry(对称轴)UVA 1595
来源:互联网 发布:人工智能顶级会议论文 编辑:程序博客网 时间:2024/04/30 03:40
解题思路:本题的突破点在于通过最左边和最右边的点寻找对称轴,我的想法是利用set集合排序(由于用了结构体,故要重写<运算符),此时set集合中为从小到大,因为最右边x相同的点可能有多个(同一条轴上,但是最小的点是固定的),所有通过迭代器(last)向前遍历,直到y相同的点求得对称轴;接下来就好办了,使用迭代器遍历set集合中所有元素(因为是对称的,所以只需要找到n的一半对数就可以了(用count记数))。
- #include<cstdio>
- #include<set>
- using namespace std;
- struct note{
- int x,y;
- bool operator <(const note &n) const {
- return x<n.x || x==n.x&&y<n.y; //set集合中用了结构体必须重写<运算符
- }
- };
- set<note> set1;
- int main(){
- int T;
- scanf("%d",&T);
- while(T--){
- int n;
- scanf("%d",&n);
- note temp;
- for(int i=0;i<n;i++)
- {
- scanf("%d%d",&temp.x,&temp.y);
- set1.insert(temp);
- }
- int flag=1;
- set<note>::iterator first=set1.begin(),last=set1.end();
- last--;
- double sym=0;
- while(true){ //此循环用于寻找对称轴
- if((*last).y != (*first).y)last--;
- else {
- sym=((*first).x+(*last).x)/(double)2;
- break;}
- }
- int count1=0;
- for(;first!=set1.end();first++){
- note nt=*first;
- nt.x=(int)(2*sym)-nt.x;
- if(set1.count(nt))count1++;
- else {flag=0;
- break;}
- if(count1>= n/2+1)break;
- }
- if(flag)printf("YES\n");
- else printf("NO\n");
- set1.clear();
- }
- return 0;
- }
0 0
- Symmetry(对称轴)UVA 1595
- UVA 1595 Symmetry(对称轴)
- 5-6 UVA 1595 Symmetry对称轴
- 对称轴(Symmetry)
- 习题5-6 对称轴(Symmetry, UVa1595)
- Symmetry UVa 1595(水题)
- UVA 1595 找对称轴(set)
- UVa 1595-对称轴
- UVa 1595 - Symmetry(对比查找)
- UVA 1595 Symmetry(sort的运用)
- UVa 1595 Symmetry
- UVA - 1595 Symmetry
- UVa 1595 - Symmetry
- UVa 1595 Symmetry(暴力)
- UVa: 1595 - Symmetry
- Uva 1595 Symmetry
- UVa: 1595 - Symmetry
- UVA - 1595 Symmetry
- maven安装与配置
- 博弈论
- PHP window2003服务和2008服务器上传个别文件访问报错
- DVWA - Command Injection (low, medium, high)
- "Table 'mysql.plugin' doesn't exist"引发de血案
- Symmetry(对称轴)UVA 1595
- 为自己挖一口井
- 微信小程序 获取session_key和openid
- 容器组件的输入输出业务逻辑
- sjzb_01_配置参数
- 深入浅出Git权限校验
- 微信小程序_家具在线-演示如何使用下拉选项
- 图像识别初步
- 命令