zoukankan      html  css  js  c++  java
  • The Halting Problem Gym

    https://vjudge.net/problem/Gym-102680C/origin

    https://vjudge.net/contest/396206#problem/C 

    In the deterministic land of Babbalon, founded by Charles Babbage, of course, all cars have been replaced by fully-autonomous, Turing-complete driving machines. For safety reasons, the two driving machines will never be in the same intersection at the same time, and a machine will halt before an intersection if there is another machine in that intersection. Babbage, late to his afternoon meeting with Mrs. Lovelace, would like to know whether any of the driving machines will stop before going through an intersection.

    If nn driving machines each take ss seconds to pass through an intersection, each one arriving at time titi, will any machines have to stop before crossing the intersection?

    The times the driving machines will arrive at the intersection will not necessarily be inputted in chronological order. A machine will not halt if it reaches the intersection at the exact same that time another leaves it.

    Input

    The first line will contain a single integer TT, the number of test cases

    The first line of each test case will contain two integers, nn and ss, the number of driving machines and the number of seconds it takes any driving machine to get through the intersection.

    The following line contains nn integers, titi, the time in seconds that the iith car arrives at the intersection

    0T400≤T≤40

    0n,s1000≤n,s≤100

    0ti10000≤ti≤1000

    Output

    Output TT lines, each containing either "YES" if at least one driving machine will have to halt, or "NO" otherwise.

    Example

    Input
    2
    3 3
    1 4 10
    2 5
    4 0
    
    Output
    NO
    YES
    

    Note

    For the first test case, driving machines will arrive at times 1, 4, and 10, and take 3 seconds to get through. No machine will have to wait for its turn, so we output "NO".

    For the second test case, a driving machine that arrives at time 0 will occupy the intersection up to, but not including, time 5. When another driving machine arrives at time 4, it will have to wait, so we output "YES".

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<bitset>
    #include<cassert>
    #include<cctype>
    #include<cmath>
    #include<cstdlib>
    #include<ctime>
    #include<deque>
    #include<iomanip>
    #include<list>
    #include<map>
    #include<queue>
    #include<set>
    #include<stack>
    #include<vector>
    #include <vector>
    #include <iterator>
    #include <utility>
    #include <sstream>
    #include <limits>
    #include <numeric>
    #include <functional>
    using namespace std;
    #define gc getchar()
    #define mem(a) memset(a,0,sizeof(a))
    #define debug(x) cout<<"debug:"<<#x<<" = "<<x<<endl;
    
    #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    typedef long long ll;
    typedef unsigned long long ull;
    typedef long double ld;
    typedef pair<int,int> pii;
    typedef char ch;
    typedef double db;
    
    const double PI=acos(-1.0);
    const double eps=1e-6;
    const int inf=0x3f3f3f3f;
    //const int maxn=1e5+10;
    const int maxn = 5010;
    //const int maxm=100+10;
    const int N=1e6+10;
    const int mod=1e9+7;
    
    int aT[105];
    int main()
    {
    		
    		int T = 0;
    		cin >> T;
    		while(T--)
    		{
    			int n = 0;
    			int tTC = 0;
    			cin >> n >> tTC;
    			
    			for(int i = 0;i<n;i++)
    			{
    				cin >> aT[i];
    			}
    			sort(aT , aT+n);
    
    			int tell = 0;
    			for (int i = 0;i<n-1;i++)
    			{
    				if (aT[i+1] - aT[i] < tTC) {
    					tell = 1;
    					continue;
    				}
    			}
    			if(tell) cout << "YES" << endl;
    			else cout << "NO" << endl;
    		}
    
    }
    

      

  • 相关阅读:
    anime.js 学习笔记
    swiper 报错 ‘ Can't find variable: Dom7’
    团队管理(二)
    团队管理(一)
    针对数值型数据的相关记录
    react+echarts折柱图实现
    侧边广告之心跳动画
    浅谈尾调用和尾递归
    elementUI 日期选择器获取CRON值
    elementUI 日期选择器之禁止年份事件二
  • 原文地址:https://www.cnblogs.com/SutsuharaYuki/p/13813532.html
Copyright © 2011-2022 走看看