UVa 1595 解题报告

来源:互联网 发布:q20 软件 编辑:程序博客网 时间:2024/05/21 06:53

运用 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