zoukankan      html  css  js  c++  java
  • 水题 Gym 100553K Knockout Racing

    题目传送门

     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
    ", ans[i]);
    47     }
    48 
    49     return 0;
    50 }
    编译人生,运行世界!
  • 相关阅读:
    Pascal's Triangle II
    Pascal's Triangle
    Path Sum II
    Path Sum
    plusOne
    Divide Two Integers
    64. ZigZag Conversion
    63. Swap Nodes in Pairs && Rotate List && Remove Nth Node From End of List
    62. Divide Two Integers
    61. Unique Paths && Unique Paths II
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4640471.html
Copyright © 2011-2022 走看看