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;
    }
    

      

  • 相关阅读:
    排序算法说明
    easyExcel 读写excel表格
    POI 读写excel表格
    JVM虚拟机详解
    SSM相关的配置文件模板
    SSM 统一异常处理
    ssm框架实现发送邮件
    springboot发送邮件
    SpringBoot Ajax请求Json数据
    协程(Coroutine)(二)
  • 原文地址:https://www.cnblogs.com/lesning/p/14154420.html
Copyright © 2011-2022 走看看