UVA-1595 Symmetry

本文解析了一道C++程序设计竞赛题目,通过使用标准模板库(set)和算法,判断一组数及其配对是否满足特定条件。涉及输入输出、集合操作、平均值计算及配对查找。
 1 #include <stdio.h>
 2 #include <iostream>
 3 #include <algorithm>
 4 #include <set>
 5 
 6 using namespace std;
 7 
 8 int main ()
 9 {
10     int N;
11     cin >> N;
12     while(N --)
13     {
14         int M;
15         cin >> M;
16         int tmp_M = M;
17         set<pair<int,int>> s;
18         double m = 0;
19         while(tmp_M --)
20         {
21             int a,b;
22             cin >> a >> b;
23             m += a;
24             s.insert(make_pair(a,b));
25         }
26     //    cout << m << endl;
27         m /= M;
28         
29         int flag = 1;
30         for(auto Ptr = s.begin();Ptr!=s.end();Ptr++)
31         {
32             int a = 2*m-Ptr->first;
33             int b = Ptr->second;
34             if(!s.count(make_pair(a,b)))
35             {
36                 flag =  0;
37                 break;
38             }
39         }
40         if(flag)
41             cout << "YES" << endl;
42         else
43             cout << "NO" << endl;
44     }
45     return 0;
46 }

 

转载于:https://www.cnblogs.com/Asurudo/p/9723854.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值