zoukankan      html  css  js  c++  java
  • F

    https://vjudge.net/contest/389195#problem/F

    It is preferrable to read the pdf statment.

    Cuber QQ has signed up for a gambling game, that challenges him to predict the stock price of Quber CC Limited, for the next following nn days. He shall make his prediction by filling a table with nn intervals, the ii-th of which is the predicted interval [li,ri][li,ri] at the ii-th day. If all nn prices lie in the corresponding interval, Cuber QQ will win 1 million dollars. Otherwise, he will not earn a single penny.

    As is well known, the stock price has a fluctuation limit. For simplicity, we assume the limit up and the limit down are both kk, which is an integer. That means, if the stock price at the ii-th day is xx, the price at the i+1i+1-th day is at most x+kx+k and at least xkx−k.

    Cuber QQ wants to know whether it is possible to manipulate the stock price, without breaking the limitation above of course, so that he can have the 11 million dollars. Since his table has already been submitted, he cannot modify his predicted intervals any more. It has to be done secretly behind the scenes, and smartly cover it up so that no one will notice.

    InputThe input starts with an integer TT (1T1051≤T≤105), denoting the number of test cases.

    For each test case, the first line contains two space-separated integers nn and kk (2n1052≤n≤105, 0k1090≤k≤109), where nn is the number of days and kk is the fluctuation limit.

    The ii-th line of the next nn lines contains two space-separated integers lili and riri (0liri1090≤li≤ri≤109), which is Cuber QQ's predicted interval in the ii-th day. A prediction is believed to be correct if the stock price ii-th day lies between lili and riri, inclusive.

    It is guaranteed that the sum of all nn does not exceed 106106.
    OutputFor each test case, first output a single line YES or NO, that states whether Cuber QQ will win the 1 million price.

    If YES, in the next line, output a possible price series, a1,a2,,ana1,a2,…,an, where liairili≤ai≤ri (1in1≤i≤n) and |aiai+1|k|ai−ai+1|≤k (1in11≤i≤n−1). The integers should be separated with space.
    Sample Input

    2
    3 1
    1 6
    2 5
    3 6
    2 3
    1 5
    10 50

    Sample Output

    YES
    2 3 3
    NO

    Sponsor

    题意:每次能在一个能够变换的区间变化,找区间

    思路:

      正反两边扫描, 把左边的约束带到右边,反过来满足后面的方法决定前面的改变.

      同时满足正反两面变化的区间,最后剩下的为可行域(选最低的

    代码:

    #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 maxm=100+10;
    const int N=1e6+10;
    const int mod=1e9+7;
    
    ll L[maxn] = {0};
    ll R[maxn] = {0};
    int main()
    {
    	ll l[maxn] = {0};
    	ll r[maxn] = {0};
    	ll n = 0 , k = 0;
    	bool flag = 1;
    	
        int T = 0;
        cin >> T;
        while(T--)
        {
            flag = 1;
            cin >> n >> k;
            for(int i = 0;i<n;i++)
            {
                cin >> L[i] >> R[i];
            }
            l[0] = L[0];
            r[0] = R[0];
            
            
            for(int i = 1;i<n;i++)
            {
                r[i] = min(R[i] , r[i-1] + k);
                l[i] = max(L[i] , l[i-1] - k);
                if(r[i] < l[i])
                {
                	flag = 0;
    			}
            }
            for(int i = 1;i<n;i++)
            {
                r[n-1-i] = min(r[n-1-i] , r[n-i] + k);
                l[n-1-i] = max(l[n-1-i] , l[n-i] - k);
                if(r[i] < l[i])
    			{
                	flag = 0;
    			}
            }
            
            if(flag)
            {
                cout << "YES" <<endl;
                for(int i = 0;i<n;i++)
                {
              		cout << r[i];
                	if(i < n-1)
                	{
                		cout<<" ";
    				}
    			}
                cout <<endl;
            }
            else
            {
            	cout << "NO" <<endl;
    		}
        }
        return 0;
    }
    
    /*
    2
    3 1
    1 6
    2 5
    3 6
    2 3
    1 5
    10 50
    */
    

      

  • 相关阅读:
    [如何构建自己的轮式移动机器人系统·从入门到放弃]机器人底层篇
    Readme.txt
    [MATLAB&SIMULINK] 如何提取并处理Simscape Power System 中powergui的谐波分析数据
    记录2016年12月11日
    [深度强化学习] blog翻译使用Keras与Gym仿真环境进行深度Q学习(DQL)
    使用PARL与Gym仿真环境进行深度Q学习(DQL)
    Telerik控件使用Expression_DarkTheme后引发Combobx下拉问题
    [Win系统][临时方案]系统任务管理器不能使用临时性解决方案
    [Visual Studio]重置开发环境
    WPF中使用DataGrid后,里面的Button的Command不响应的问题
  • 原文地址:https://www.cnblogs.com/SutsuharaYuki/p/13520338.html
Copyright © 2011-2022 走看看