UVa 1595 解題報告
運用 map 將隨機的行數轉換為按照第一次輸入的順序進行轉換,不會影響對稱性,而且方便儲存。
#include <bits/stdc++.h>
using namespace std;
double findsym(vector <int>v, int cnt)
{
int tot = 0;
for (int i = 0; i < cnt; ++i)
tot += v[i];
if(tot != 0)return tot / cnt;
else return 0;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
cin >> T;
while(T--){
int n;
cin >> n;
map<int ,int>line;
vector <int>col[1005];
for (int i = 1; i <= n; ++i)
{
int x,y;
cin >> x >> y;
if(line[y]==0)
line[y] = i;
col[line[y]].push_back(x);
/*int t;
t = col[line[y]].size();
cout << t << endl;*/
}
double sym = 100000;
int ok = 1;
for (int i = 1; i <= n; ++i)
{
int y = col[i].size(),t;
//cout << y <<endl;
if(sym < 100000.0001 && sym > 99999.9999 && y > 0)
sym = findsym(col[i], y);
else if(sym < 90000 && y >0){
t = findsym(col[i], y);
if((t - sym) > 0.001 || (sym - t) > 0.001){
ok = 0;
break;
}
}
}
if(ok)cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
原題如下:
The gure shown on the left is left-right symmetric as it is possible to fold the sheet of paper along a
vertical line, drawn as a dashed line, and to cut the gure into two identical halves. The gure on the
right is not left-right symmetric as it is impossible to nd such a vertical line.
Write a program that determines whether a gure, drawn with dots, is left-right symmetric or not.
The dots are all distinct.
Input
The input consists of T test cases. The number of test cases T is given in the rst line of the input le.
The rst line of each test case contains an integer N, where N (1 N 1; 000) is the number of dots
in a gure. Each of the following N lines contains the x-coordinate and y-coordinate of a dot. Both
x-coordinates and y-coordinates are integers between