[HNOI2005]汤姆的游戏

嘟嘟嘟

 

直接O(n ^ 2)暴力判断就行了。

对于圆,判断该点和圆心的距离是否小于半径。

然而为啥我这么写编译不过:

1 scanf("%lf%lf%lf%lf", &a[++cnt1].xl, &a[cnt1].yl, &a[cnt1].xr, &a[cnt1].yr);

++cnt1必须拎出来写?!……

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<algorithm>
 4 #include<cmath>
 5 #include<cstring>
 6 #include<cstdlib>
 7 #include<vector>
 8 #include<queue>
 9 #include<stack>
10 #include<cctype>
11 using namespace std;
12 #define enter puts("")
13 #define space putchar(' ')
14 #define Mem(a) memset(a, 0, sizeof(a))
15 typedef long long ll;
16 typedef double db;
17 const int INF = 0x3f3f3f3f;
18 const db eps = 1e-8;
19 const int maxn = 3e5 + 5;
20 const int maxm = 5e4 + 5;
21 inline ll read()
22 {
23     ll ans = 0;
24     char ch = getchar(), last = ' ';
25     while(!isdigit(ch)) last = ch, ch = getchar();
26     while(isdigit(ch)) ans = (ans << 3) + (ans << 1) + ch - '0', ch = getchar();
27     if(last == '-') ans = -ans;
28     return ans;
29 }
30 inline void write(ll x)
31 { 
32     if(x < 0) putchar('-'), x = -x;
33     if(x >= 10) write(x / 10);
34     putchar(x % 10 + '0');
35 }
36 
37 int n, m;
38 struct Rec
39 {
40     db xl, yl, xr, yr;
41 }a[maxn];
42 struct Cir
43 {
44     db x, y, r;
45 }b[maxn];
46 int cnt1 = 0, cnt2 = 0;
47 
48 int ans[maxm];
49 void judge(const db& x, const db& y, const int& id)
50 {
51     for(int i = 1; i <= cnt1; ++i)
52     {
53         if(a[i].yl <= a[i].yr)
54         {
55             if(a[i].xl < x && a[i].xr > x && a[i].yl < y && a[i].yr > y) ans[id]++;
56         }
57         else if(a[i].xl < x && a[i].xr > x && a[i].yr < y && a[i].yl > y) ans[id]++;
58     }
59     for(int i = 1; i <= cnt2; ++i)
60         if((x - b[i].x) * (x - b[i].x) + (y - b[i].y) * (y - b[i].y) < b[i].r * b[i].r) ans[id]++;
61 }
62 
63 int main()
64 {
65     n = read(); m = read();
66     for(int i = 1; i <= n; ++i)
67     {
68         char c[2]; scanf("%s", c);
69         if(c[0] == 'r') 
70         {
71             cnt1++;
72             scanf("%lf%lf%lf%lf", &a[cnt1].xl, &a[cnt1].yl, &a[cnt1].xr, &a[cnt1].yr);
73             if(a[cnt1].xl > a[cnt1].xr) swap(a[cnt1].xl, a[cnt1].xr), swap(a[cnt1].yl, a[cnt1].yr);
74         }
75         else cnt2++, scanf("%lf%lf%lf", &b[cnt2].x, &b[cnt2].y, &b[cnt2].r);
76     }
77     for(int i = 1; i <= m; ++i)
78     {
79         db x, y; scanf("%lf%lf", &x, &y);
80         judge(x, y, i);
81     }
82     for(int i = 1; i <= m; ++i) write(ans[i]), enter;
83     return 0;
84 }
View Code

 

posted @ 2018-08-24 16:16  mrclr  阅读(128)  评论(0编辑  收藏  举报