URAL - 2105 Alice and Bob are on Bikes 整体处理、相遇问题

F - Alice and Bob are on Bikes

  URAL - 2105


Alice and Bob, after played enough and completely figured out the game with colored strip, decided to ride bikes around the fountain on a circular path of length  L. Alice rides with a speed  v  A, Bob — with a speed  v  B, and they have started in different directions. At the initial moment the kids were in the same point. When they “meet” (i.e., at some moment they are in the same point as in the previous were not), they joyfully exclaim (“Oh, Bob!” or “Oh, Alice!” respectively). But sometimes along the way, the kids stop to feed the squirrels. Find, how many times Alice and Bob “have met”.
Input
The first line contains integers  LTv  A, and  v  B that are the length of the path, the riding time and the speed of Alice and Bob, respectively (1 ≤  L ≤ 10  9; 1 ≤  T≤ 10  6; 1 ≤  v  Av  B ≤ 10  3).
The next line contains a single integer  n, that is the number of intervals in which children were feeding squirrels  (0 ≤  n ≤ 10  5)  . The next  n lines describe those intervals. Each description consists of three integers:  type  i  t  i  d  i, meaning who was feeding (1 for Alice and 2 for Bob), at what moment the feeding started and how much time it lasted, respectively  (0 ≤  t  id  i ≤  Tt  i +  d  i ≤  T)  .
It is guaranteed that for one kid any two intervals intersect in no more than one point. The intervals are given in order of non-decreasing  t  i.
Output
Output the number of “meetings” of Alice and Bob.
Example
input output
10 10 2 1
3
1 1 1
1 2 2
2 2 1


Source URAL - 2105
My Solution
题意:ab从同一个位置开始相向的沿着一个圈跑,ab各自会停下来一段时间,问0~t这个过程中他们总共相遇多少次。 整体处理、相遇问题
写了很久模拟发现可以一次性处理,中间过程可以相互抵消掉很多东西,写了模拟就懂,Y ^_^ Y。 只要找出 a总运动路程长度,b总运动路程长度,ans = (a + b) / l; 复杂度 O(n)
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;
const int maxn = 1e6 + 8;


int main()
{
    #ifdef LOCAL
    freopen("f.txt", "r", stdin);
    //freopen("f.out", "w", stdout);
    int T = 4;
    while(T--){
    #endif // LOCAL
    ios::sync_with_stdio(false); cin.tie(0);

    LL l, t, va, vb, n, pi, ti, di, ans = 0, a = 0, b = 0, rt = 0, dt;
    cin >> l >> t >> va >> vb;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> pi >> ti >> di;
        dt = ti - rt;
        a += va * dt;
        b += vb * dt;
        if(pi == 1) {b += vb * di;}
        else { a += va * di;}
        rt = ti + di;
    }
    dt = t - rt;
    a += va * dt;
    b += vb * dt;

    cout << (a+b) / l << endl;

    #ifdef LOCAL
    cout << endl;
    }
    #endif // LOCAL
    return 0;
}



Thank you!                                                                                                                                                ------from ProLights

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值