Uva 3226 Symmetry
题目给出一些点的坐标(横坐标,纵坐标),没有重叠的点,求是否存在一条竖线(平行于y轴的线),使线两边的点左右对称。
我的思路:对于相同的纵坐标的点,即y值相同的点,可以将x的总和计算出,然后除以点的数目,即可得到对称轴的x坐标。所以,对于不同的y值,可以算出这个y值对应的点的对称轴的x坐标,只要观察这些x坐标的值是否相等即可。如果相同,则存在一条竖线满足题意。如果出现不相同,则不存在符合题意的竖线。
注意点:计算后的x的值可能为小数,故需要用double保存。
/*
UvaOJ 1595
Emerald
Mon 4 May 2015
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <map> using namespace std; int main() {
int T;
cin >> T;
while( T -- ) {
int N;
cin >> N;
map < int,int > yToXsum; // key : the value of y, value : the total value of x in y axis
map < int,int > yTimes; // key : the value of y, value : the times that y appears
map < int, int >::iterator it;
int x, y;
while( N -- ) {
scanf( "%d%d", &x, &y );
if( yToXsum.count( y ) ) {
yToXsum[y] += x;
} else {
yToXsum[y] = x;
}
if( yTimes.count( y ) ) {
yTimes[ y ] ++;
} else {
yTimes[ y ] = 1;
}
}
double ave; // the average of the x
it = yTimes.begin();
ave = 1.0 * yToXsum [ it->first ] / it->second;
for( it ++; it!=yTimes.end(); it ++ ) {
if( ave != 1.0 * yToXsum [ it->first ] / it->second ) {
break;
}
}
if( it == yTimes.end() ) {
printf( "YES\n" );
} else {
printf( "NO\n" );
}
}
return 0;
}
Uva 3226 Symmetry的更多相关文章
- uva 1595 - Symmetry
思路:首先,如果这些点对称,那么它们的对称轴是x = m(m是所有点横坐标的平均值): 把这些点放到一个集合里,然后扫描每个点,计算出它关于x = m的对称点,看这个点是否在集合里面. 如果有 ...
- uva 1595 Symmetry“结构体”
给出平面上N(N<=1000)个点.问是否可以找到一条竖线,使得所有点左右对称,如图所示: 则左边的图形有对称轴,右边没有. Sample Input 3 5 -2 5 0 0 6 5 4 ...
- UVa 1595 Symmetry(set)
We call a figure made of points is left-right symmetric as it is possible to fold the sheet of paper ...
- UVa 1595 Symmetry (set && math)
题意:给出n个在直角坐标系上的点,问你能不能找出一条竖轴(即垂直于x的轴)使得所有的点根据这条轴对称,能则输出YES,否则输出NO 分析:首先需要找到对称轴的值,将所有n个点的x轴的值加起来然后去除以 ...
- UVa 1595 (水题) Symmetry
颓废的一个下午,一直在切水题,(ˉ▽ ̄-) 首先如果这些点是对称的话,那么它们的对称轴就是x = m,m是横坐标的平均值. 把这些点放到一个集合里,然后扫描每个点,计算出它关于x = m的对称点,看这 ...
- UVA 10585 Center of symmetry
题意:给出一个点集,问这个集合有没有中心点使点集对称,这个点可以是点集中的点也可以不是点集的点. 解法:一开始我枚举每两个点连线的中点……结果T了orz当时也不知道怎么想的…… 将点按横坐标排序,如果 ...
- 【UVA】1595 Symmetry(模拟)
题目 题目 分析 理清思路,上模拟. 代码 #include <bits/stdc++.h> using namespace std; const int maxn=100 ...
- Symmetry UVA - 1595
The figure shown on the left is left-right symmetric as it is possible to fold the sheet of paper ...
- UVa第五章STL应用 习题((解题报告))具体!
例题5--9 数据库 Database UVa 1592 #include<iostream> #include<stdio.h> #include<string.h&g ...
随机推荐
- 提前防止Non-PIE错误,检测app是否包含PIE标志
//Howard 2013-07-19 //如何检测app是否包含PIE标志? 答:使用xCode自带的otool工具. otool程序在Xcode.app/Contents/Developer/us ...
- chrome 、 火狐等浏览器对空格符 解析不同,页面显示不一致
最近初学web,从头开始,菜鸟级别,遇到的小问题记录下来. 网上资料说 空格在ie.firefox.chrome浏览器上显示的效果不太一样,主要是前面的空格宽度不同,这可能是因为不同的浏览器会有不同的 ...
- CentOS下成功挂载xxxxxDVDx.iso并使用yum安装软件
CentOS下成功挂载xxxxxDVDx.iso并使用yum安装软件 **不断尝试,终能到达彼岸** 测试环境为Win7 32位,VirtualBOx4.2.16+CentOS6.5,可分别到virt ...
- fitnesse 中各类fit fixture的python实现
虽然网上都说slim效率很高,无奈找不到支持python的方法,继续用pyfit 1 Column Fixture 特点:行表格展现形式,一条测试用例对应一行数据 Wiki !define COMMA ...
- XML中SystemID和PublicID的区别
http://hi.baidu.com/binboot007/item/1533f91d52113d7c7b5f259c http://supportweb.cs.bham.ac.uk/documen ...
- python利用utf-8编码判断中文英文字符(转)
下面这个小工具包含了判断unicode是否是汉字.数字.英文或者其他字符,全角符号转半角符号,unicode字符串归一化等工作. #!/usr/bin/env python # -*- coding: ...
- Winter(bfs&&dfs)
1084 - Winter PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Winter is ...
- 使用C#对MongoDB中的数据进行查询,改动等操作
首先,使用的是官方提供的C#訪问组件https://github.com/mongodb/mongo-csharp-driver 然后.编译后引用MongoDB.Bson.dll及MongoDB.Dr ...
- View从Action中获得数据和html helper function(转载)
@model MvcApplication1.Models.M_Person @using MvcApplication1.Models; @{ ViewBag.Title = "GetDa ...
- jQuery+Ajax+Jsp做二级级联
终于弄懂了这个级联,我去!必须得在博客记下来. 1, JS代码: $(document).ready(function(){ $("#select1").change(functi ...