zoukankan      html  css  js  c++  java
  • CF1463C Busy Robot

    https://codeforc.es/contest/1463/problem/C

    这是昨晚的cf题,我很难过没能ac,是因为当时的精神状态不好

    这个模拟其实不难写,定义两个东西,当前位置pos和目标位置ans就好了,多睡觉吧,睡醒了才聪明啊

    ans小于pos就退步,ans大于pos就进步,写了再说,先写了再说

    #include<iostream>
    #include<cstring>
    #include<queue>
    using namespace std;
    typedef long long ll;
    const int maxn = 2e5+111;
    pair<ll,ll>ins[maxn],chal[maxn];
    
    int main(){
    	int t;
    	cin>>t;
    	while(t--){
    		int n;
    		cin>>n;
    		for(int i=0;i<n;i++){
    			cin>>ins[i].first;
    			cin>>ins[i].second;
    		}
    		ins[n] = make_pair(2e17,2e16);
    		ll pos = 0,ans = 0;
    		
    		ans = ins[0].second;
    		chal[0] = make_pair(0,ans);
    		
    		
    		for(int i=1;i<=n;i++){
    			ll x = ins[i].first;
    			ll y = ins[i].second;
    			ll len = ins[i].first - ins[i-1].first;
    			
    			if(ans > pos){
    				pos += len;
    				if(pos >= ans) {
    					pos = ans;
    					ans = y;
    				}
    			}
    			else{
    				pos -= len;
    				if(pos <= ans){
    					pos = ans;
    					ans = y;
    				}
    			}
    			chal[i] = make_pair(pos,ans);
    		}
    	
    		ll ddd = 0;
    		
    		for(int i=0;i<n;i++){
    			ll y = ins[i].second;
    			if(chal[i].first <= y && y <= chal[i+1].first){
    				ddd++;
    			}
    			else if(chal[i+1].first <= y && y <= chal[i].first){
    				ddd++;
    			}
    		}
    		
    		cout<<ddd<<endl<<endl;
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    python之路——进程
    python之路——操作系统的发展史
    python之路——网络编程
    模块学习之re模块
    day11迭代器、生成器
    day10闭包、函数装饰器
    vnc安装和配置
    单例模式
    代理设计模式
    工厂模式例子
  • 原文地址:https://www.cnblogs.com/lesning/p/14154420.html
Copyright © 2011-2022 走看看