码迷,mamicode.com
首页 > 其他好文 > 详细

水题 Gym 100553K Knockout Racing

时间:2015-07-12 08:25:44      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:

 

题目传送门

 1 /*
 2     题意:有若干个点在一个区间内来回移动,1m/s。
 3     水题:n^2的复杂度能解决,注意时间可能大于一个周期,要取模
 4 */
 5 #include <cstdio>
 6 #include <algorithm>
 7 #include <cstring>
 8 #include <cmath>
 9 using namespace std;
10 
11 typedef long long ll;
12 const int MAXN = 1e3 + 10;
13 const int INF = 0x3f3f3f3f;
14 ll x[MAXN], y[MAXN];
15 struct Question
16 {
17     ll x, y, t;
18 }q[MAXN];
19 int ans[MAXN];
20 
21 int main(void)        //Gym 100553K Knockout Racing
22 {
23 //    freopen ("K.in", "r", stdin);
24     freopen ("knockout.in", "r", stdin);
25     freopen ("knockout.out", "w", stdout);
26 
27     int n, m;
28     while (scanf ("%d%d", &n, &m) == 2)
29     {
30         for (int i=1; i<=n; ++i)    scanf ("%I64d%I64d", &x[i], &y[i]);
31         for (int i=1; i<=m; ++i)    scanf ("%I64d%I64d%I64d", &q[i].x, &q[i].y, &q[i].t);
32         for (int i=1; i<=m; ++i)
33         {
34             int cnt = 0;
35             for (int j=1; j<=n; ++j)
36             {
37                 ll d = q[i].t % ((y[j] - x[j]) * 2);
38                 ll pos = x[j];
39                 if (pos + d <= y[j])    pos += d;
40                 else    pos = y[j] - (d - (y[j] - x[j]));
41                 if (q[i].x <= pos && pos <= q[i].y)    cnt++;
42             }
43             ans[i] = cnt;
44         }
45 
46         for (int i=1; i<=m; ++i)    printf ("%d\n", ans[i]);
47     }
48 
49     return 0;
50 }

 

水题 Gym 100553K Knockout Racing

标签:

原文地址:http://www.cnblogs.com/Running-Time/p/4640471.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!