• CF 1463C


     1 #include<bits/stdc++.h>
     2 #define ll long long
     3 using namespace std;
     4 const int N = 1e5 + 10;
     5 struct node
     6 {
     7     ll t, x;
     8 }a[N];
     9 
    10 int main(){
    11     ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    12     int t; cin >> t;
    13     while(t--)
    14     {
    15         ll n; cin >> n;
    16         for(int i = 1 ; i <= n ; i++){
    17             cin >> a[i].t >> a[i].x;
    18         }
    19         ll res = 0, pos = 0;
    20         ll id = 1, t = 0;
    21         a[n + 1].t = 1000000000000000;
    22         
    23         while(id <= n){
    24             t = a[id].t;//当前时间 
    25             ll del = abs(pos - a[id].x);//运动到id位置需要的时间/位置差 
    26             if(del == 0){//不需要移动 
    27                 res++;
    28                 id++;
    29                 continue;
    30             }
    31             ll tag = 0;//要运动的方向 
    32             if(a[id].x > pos){
    33                 tag = 1;//
    34             }else if(a[id].x < pos){
    35                 tag = -1;//
    36             }
    37             while(id <= n && del && t + del > a[id].t){
    38                 ll dist = abs(pos - a[id].x);
    39                 if(dist <= del){
    40                     if((tag == 1 && a[id].x >= pos) || (tag == -1 && a[id].x <= pos)){
    41                         if(a[id + 1].t >= t + dist && a[id].t <= t + dist){
    42                             res++;
    43                         }
    44                     }
    45                 }
    46                 id++;
    47             }
    48             t += del;
    49             pos += del * tag;
    50         }
    51         cout << res << endl;
    52     }
    53     
    54     
    55     return 0;
    56 }
  • 相关阅读:
    uvm_misc——杂货铺(miscellaneous)
    23种设计模式及其应用场景
    Hadoop TextInputFormat源码分析
    java字符串替换函数高效实现
    hadoop HA 之 QJM
    中文分词词性对照表
    计算两个字符串编辑距离
    java 图片处理
    zookeeper数据迁移
    正则表达式
  • 原文地址:https://www.cnblogs.com/ecustlegendn324/p/14263255.html
Copyright © 2020-2023  润新知