F - Fluctuation Limit
https://vjudge.net/contest/389195#problem/F
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 x−kx−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 (1≤T≤1051≤T≤105), denoting the number of test cases.
For each test case, the first line contains two space-separated integers nn and kk (2≤n≤1052≤n≤105, 0≤k≤1090≤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 (0≤li≤ri≤1090≤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 li≤ai≤rili≤ai≤ri (1≤i≤n1≤i≤n) and |ai−ai+1|≤k|ai−ai+1|≤k (1≤i≤n−11≤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
*/
F - Fluctuation Limit的更多相关文章
- F - Fluctuation Limit HDU - 6860
题目链接:https://vjudge.net/problem/HDU-6860 题意:相邻两天的差值的绝对值不超过K. 思路:该题的关键在于前面的点会影响后面的点,后面的点会影响前面的点,我们要找到 ...
- hdu 6860 Fluctuation Limit 双向贪心
题意: 给你n个区间[li,ri],和一个整数k,你从每一个区间内选出来一个数,把从第i个区间内选出来数放在第i个位置,这样会构成一个长度为n的序列,你需要保证序列中任意两个相邻的数之差的绝对值要小于 ...
- NEFU 2016省赛演练一 F题 (高精度加法)
Function1 Problem:F Time Limit:1000ms Memory Limit:65535K Description You know that huicpc0838 has b ...
- 关于limit hashlimit资料整理
这几天正在捣鼓防火墙,用到了hashlimit模块.Google了一圈发现相关的文档无论英文还 是中文都很少, 所以我就把自己的折腾的心得记录下来吧. hashlimit是iptables的一个匹配模 ...
- 周赛F题 POJ 1458(最长公共子序列)
F - F Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Description ...
- Java中关于String的split(String regex, int limit) 方法
今天在对一个String对象进行拆分的时候,总是无法到达预计的结果.呈现数据的时候出现异常,后来debug之后才发现,错误出在String spilt上,于是开始好好研究下这东西,开始对api里的sp ...
- 「 HDU P4734 」 F(x)
# 题目大意 对于一个数 $x$,它的每一位数字分别是 $A_{n}A_{n-1}A_{n-2}\cdots A_{2}A_{1}$,定义其权重 $f(x)=\sum_{i=1}^{n}\left(A ...
- hpu第六次周赛Problem F
Problem F Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Sub ...
- 最全的linux命令大全,shell运维手册
shell实例手册 0 说明{ 手册制作: 雪松} 1 文件{ ls -rtl # 按时间倒叙列出所有目录和文件 ll -rt touch file ...
- ACM-东北大学程序设计竞赛-网络赛(2016.04.16)
Problem: A Time limit: 1s Mem limit: 64 MB AC/Submission: 0/0 Discuss Back Ranklist Stat ...
随机推荐
- Disruptor—2.并发编程相关简介
大纲 1.并发类容器 2.volatile关键字与内存分析 3.Atomic系列类与UnSafe类 4.JUC常用工具类 5.AQS各种锁与架构核心 6.线程池的最佳使用指南 1.并发类容器 (1)C ...
- JAVA基础-跳出循环的4种方式
摘要:介绍4种跳出循环的方式,尤其是其中的break 标签,有时候真的会成为工作中的秘密武器. 在实际编程中,有时需要在条件语句匹配的时候跳出循环.在 Java 语言里,由关键词 break 和 ...
- Hyperledger Fabric2.x基本概念之(一)交易和区块链
▲ 点击101链视界,关注不走丢 大家好,我是阿创,这是我的第30篇原创文章. 我比较爱看书,2021年全年我的阅读量大概是20+本书,涵盖法律.哲学.技术.人文. 但是阅读量一上来反而会觉得,单纯的 ...
- TUF系统概述
TUF基本介绍 TUF 是一个为软件更新系统设计的安全框架,最初由纽约大学的 Secure Systems Lab 提出.它的目标是解决传统软件更新过程中的各种安全问题(如中间人攻击.回滚攻击.密钥泄 ...
- 关于PHP 函数性能优化的技巧
本文由 ChatMoney团队出品 本文将详细介绍 PHP 函数性能优化的技巧.通过分析 PHP 函数的执行过程和性能瓶颈,提供一系列实用的优化方法,并结合代码示例,帮助读者提升 PHP 代码的执行效 ...
- LogStash输入插件详解
概述 官方文档:https://www.elastic.co/guide/en/logstash/7.17/input-plugins.html 输入插件使 Logstash 能够读取特定的事件源. ...
- springboot~入门第三篇~与mybatis整合~(未完)
第二部分仅仅是从控制器到页面的跳转,但是没数据库的整合是不行的. 进入正题: springboot启动是要默认加载数据源的,之前是从application.properties,现在开始在 src/ ...
- 安装程序无法自动安装virtual machine
安装VMware Tools 失败 发现在给过旧的系统安装 安装VMware Tools 的时候,会失败,比如 win7.win server2008等. 原因 官网的说明,在这里 看不懂的自行翻译: ...
- JavaScript 异步编程指南:async/await 与 Promise 该怎么选?
在 JavaScript 开发中,异步操作就像家常便饭 -- 从调用后端 API 到读取本地文件,几乎无处不在.但很多开发者都会困惑:到底该用 Promise 的链式调用,还是 async/await ...
- qsort 浅度解析
#include <stdio.h>#include <string.h>#include <stdlib.h>//标准库 qsort的标准库ch ...