• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Warm up 16 Hitting the Targets

Hitting the Targets
Time Limit: 10000ms, Special Time Limit:25000ms, Memory Limit:65536KB
Total submit users: 38, Accepted users: 38
Problem 12782 : No special judgement

Problem description

又是一道感人的输入方式的傻逼题啊!

A fundamental operation in computational geometry is determining whether two objects touch. For example, in a ame that involves shooting, we want to determine if a player’s shot hits a target. A shot is a two dimensional point, nd a target is a two dimensional enclosed area. A shot hits a target if it is inside the target. The boundary of a target inside the target. Since it is possible for targets to overlap, we want to identify how many targets a shot hits.
The figure above illustrates the targets (large unfilled rectangles and circles) and shots (filled circles) of the sample input. The origin (0, 0) is indicated by a small unfilled circle near the center.
Input
Input starts with an integer 1 ≤ m ≤ 30 indicating the number of targets. Each of the next m lines begins with the word rectangle or circle and then a description of the target boundary. A rectangular target’s boundary is given as four integers x1 y1 x2 y2, where x1 < x2 and y1 < y2. The points (x1, y1) and (x2, y2) are the bottom-left and top-right corners of the rectangle, respectively. A circular target’s boundary is given as three integers x y r. The center of the circle is at (x, y) and the 0 < r ≤ 1000 is the radius of the circle. After the target descriptions is an integer 1 ≤ n ≤ 100 indicating the number of shots that follow. The next n lines each contain two integers x y, indicating the coordinates of a shot. All x and y coordinates for targets and shots are in the range [−1000, 1000].
Output
For each of the n shots, print the total number of targets the shot hits.
Sample Input
Sample Input 1
3
rectangle 1 1 10 5
circle 5 0 8
rectangle -5 3 5 8
5
1 1
4 5
10 10
-10 -1
4 -3
Sample Output
Sample Output 1
2
3
0
0
1
Problem Source
HNU Contest 
Submit   Discuss   Judge Status  Problems  Ranklist 
 1 #pragma comment(linker, "/STACK:1024000000,1024000000")
 2 #include <map>
 3 #include <queue>
 4 #include <vector>
 5 #include <string>
 6 #include <cmath>
 7 #include <cstdio>
 8 #include <cstring>
 9 #include <cstdlib>
10 #include <iostream>
11 #include <algorithm>
12 using namespace std;
13 #define maxn 1305
14 #define ll long long
15 #define mod 1000000007
16 #define INF 0x7fffffff
17 #define eps 1e-8
18 int n, m;
19 ll gcd(ll n, ll m){ return m ? gcd(m, n%m) : n; }
20 char s[maxn][maxn];
21 struct rec{int x1, x2, y1, y2;}re[maxn];
22 struct cir{int x, y, r;}ci[maxn];
23 int main(){
24     /*int t;
25     scanf("%d", &t);
26     while (t--){
27     scanf("%I64d", &n);
28 
29     }*/
30     //ll x, y, x1, x2, y1, y2, s1, s2;
31     while (~scanf("%d", &n)){
32         for (int i = 0; i < n; i++){
33             scanf("%s", s[i]);
34             if (s[i][0] == 'r')scanf("%d%d%d%d", &re[i].x1, &re[i].y1, &re[i].x2, &re[i].y2);
35             if (s[i][0] == 'c')scanf("%d%d%d", &ci[i].x, &ci[i].y, &ci[i].r);
36         }
37         scanf("%d", &m);
38         while (m--){
39             int x, y;
40             scanf("%d%d", &x, &y);
41             int t = 0;
42             for (int i = 0; i < n; i++){
43                 if (s[i][0] == 'r')if (x >= re[i].x1&&x <= re[i].x2&&y >= re[i].y1&&y <= re[i].y2)t++;
44                 else {
45                     double a, b, dx, dy, dr;
46                     a = x; b = y; dx = ci[i].x, dy = ci[i].y; dr = ci[i].r;
47                     if (sqrt((dx - x)*(dx - x) + (dy - y)*(dy - y)) <= dr)t++;
48                 }
49             }
50             printf("%d\n", t);
51         }
52     }
53     return 0;
54 }
View Code
posted @ 2013-11-04 03:12  HaibaraAi  阅读(231)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3