UVALive 5984

时间:2024-09-28 09:35:44

题目链接:Save the Students!

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
using namespace std; bool vis[][]; // 所有数据保证在1到50.那么坐标在-50到100之间。所以。哈希到50到200之间。开始开的200*200的。WA。 double dis(double x1, double y1, double x2, double y2) // 两点间距离。
{
// cout << x1 << "==" << y1 << "==" << x2<< "==" << y2 << "==" << endl;
double xx = (x2-x1)*(x2-x1);
double yy = (y2-y1)*(y2-y1);
double ans = xx+yy+0.0;
return ans;
} int circle(int a, int b, int r) //是否在圆内。
{
int cnt = ;
for (int i=a-r; i<=a+r; ++i)
{
for (int j=b-r; j<=b+r; ++j)
{
if (!vis[i+][j+])
{
if (dis(i, j, a, b) <= r*r)
{
cnt++;
vis[i+][j+] = ;
}
}
}
}
return cnt;
} double area(int x1, int y1, int x2, int y2, int x3, int y3) // 三角形面积。
{
double temp = (x2-x1)*(y3-y1) - (x3-x1)*(y2-y1);
temp /= 2.0;
if (temp < ) temp = -temp;
return temp;
} int triangle(int x1, int y1, int x2, int y2, int x3, int y3) //是否在三角形内。
{
int cnt = ;
int minx = min(x1, min(x2, x3));
int maxx = max(x1, max(x2, x3));
int miny = min(y1, min(y2, y3));
int maxy = max(y1, max(y2, y3)); for (int i=minx; i<=maxx; ++i)
{
for (int j=miny; j<=maxy; ++j)
{
if (!vis[i+][j+])
{
double s1 = area(i, j, x1, y1, x2, y2);
double s2 = area(i, j, x1, y1, x3, y3);
double s3 = area(i, j, x2, y2, x3, y3);
double s = area(x1, y1, x2, y2, x3, y3);
if (s1 + s2 + s3 == s)
{
cnt++;
vis[i+][j+] = ;
}
}
}
}
return cnt;
} int square(int x1, int y1, int l) //正方形直接判断是不是已经被覆盖了。就可以。开始用了一个巨蠢的用距离判断点是不是在正方形内。。呵呵。。。。
{
int cnt = ;
for (int i=x1; i<=x1+l; ++i)
{
for (int j=y1; j<=y1+l; ++j)
{
if (!vis[i+][j+])
{
cnt++;
vis[i+][j+] = ;
}
}
}
return cnt;
} int main()
{
int t, n;
int x1, x2, x3, x4, x5, x6;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
memset(vis, , sizeof(vis));
int ans = ;
for (int i=; i<n; ++i)
{
char temp;
getchar();
scanf("%c", &temp);
if (temp == 'C')
{
scanf("%d%d%d", &x1, &x2, &x3);
ans += circle(x1, x2, x3);
}
else if (temp == 'S')
{
scanf("%d%d%d", &x1, &x2, &x3);
ans += square(x1, x2, x3);
}
else if (temp == 'T')
{
scanf("%d%d%d%d%d%d", &x1, &x2, &x3, &x4, &x5, &x6);
ans += triangle(x1, x2, x3, x4, x5, x6);
}
}
printf("%d\n", ans);
}
return ;
}