uva

来源:互联网 发布:瑞星防火墙软件 编辑:程序博客网 时间:2024/06/10 06:18

很水的一道题 , 只是忘记 set 数组忘记清空,wa 了

题目清楚,找一条竖线,判断是否对称,输入的时候就找到对称轴的 x 坐标,当然 为了防止除法出错,可以对每点坐标进行 *2 处理

#include<iostream>#include<cstdio>#include<set>#include<map>using namespace std;typedef pair<int, int> point;set<point> a;int n, t;void init() {    t = 0;    a.clear();    int x, y;    scanf("%d", &n);    for(int i = 0; i < n; ++i) {        scanf("%d%d", &x, &y);        t += x;        a.insert(point(x*n,y));    }    t *= 2; }void solve() {    for(set<point>::iterator i = a.begin(); i != a.end(); ++i) {        point p = *i;        //cout << p.first << "==" << p.second << endl;        if(a.find(point(t-p.first, p.second )) == a.end() ) {            cout << "NO" << endl;            return;        }    }    cout << "YES" << endl;}int main() {    int T;    scanf("%d", &T);    while(T--) {        init();        solve();    }    return 0;}


1 0
原创粉丝点击