UVA1595不知道怎么错系列
先挂着以后来debug 受不了了(-
#include <iostream>
const int maxd = 10003;//最大绝对值10000
const int maxsize = 1003;
int m[2*maxd][2 * maxd];//
int memory[2 * maxsize];
int main()
{
int T, n;
scanf("%d", &T);
while (T--)
{
//memset(m, 0, sizeof(m));
scanf("%d", &n);
int a, b,sum=0,k=0;
for (int i = 0;i < n;i++)
{
scanf("%d%d", &a, &b);
sum += a;
memory[k++] = a, memory[k++] = b;
}
double mid = sum *1.0 / n;//别人的做法是sum不变,存储x的时候直接乘以n
for (int i = 0;i < k;i += 2)
{
int x = memory[i], y = memory[i + 1];
if (x > mid)m[(int)(x-mid+0.5)][y+10000]++;
//只有点成对才能导致结果为零,此处只需处理x!=sum的情况。
else if (x < mid)m[(int)(mid-x+0.5)][y+10000]--;
}
int flag = 0;
for(int i=0;i<k;i+=2)
{ int x = memory[i], y = memory[i + 1];
if (x > mid && m[(int)(x-mid+0.5)][y+10000] != 0) { flag = 1;break; }
if(x<mid&&m[(int)(mid - x + 0.5)][y + 10000]!=0) { flag = 1;break; }
}
if (!flag)printf("YES\n");
else printf("NO\n");
}
return 0;
}
//附上模仿别人的思路
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
typedef pair<int, int> point;
set<point> Set;
#define local
int main()
{
int T, n;
scanf("%d", &T);
while (T--)
{
scanf("%d", &n);
int a, b;
point p;
int sum = 0;//记录所有点的横坐标之和
for (int i = 0;i < n;i++)
{
scanf("%d%d", &a, &b);
p = point(n*a, b);//n*a
sum += a;//这个sum用得美妙,nice
Set.insert(p);
}
for (set<point>::iterator it = Set.begin();it != Set.end();it++)
printf("(%d,%d)\n", it->first, it->second);
int flag = 0;
for (set<point>::iterator it = Set.begin();it != Set.end();it++)
{
p = point(2 * sum - it->first, it->second);
if (find(Set.begin(), Set.end(), p) == Set.end()) { flag = 1;break; }
}
if (!flag)printf("YES\n");
else printf("NO\n");
}
return 0;
}