1469C Building a Fence
思路:每一次求取一個範圍,然後判斷之後的小方格是否滿足範圍。對於最後和第一個方格已經取定,需要特殊判斷,細節見程式碼。
Code:
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<memory.h>
#include<cmath>
#define pii pair<int,int>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
int Mod = 1e9 + 7;
int h[Max];
int main()
{
int t;cin >> t;
while (t--)
{
int n, k;cin >> n >> k;
for (int i = 1;i <= n;i++)cin >> h[i];
int l = h[1], r = h[1];
int f = 1;
for (int i = 2;i <= n-1;i++)
{
if (h[i] >= h[i - 1])
{
if (h[i] >= r + k) { f = 0;break; }
l = h[i], r = min(h[i] + k-1, r + k - 1);
}
else
{
if (h[i] + k+k-1 <= l) { f = 0;break; }
r = h[i] + k - 1, l = max(h[i], l - k + 1);
}
}
if (h[n] + k <= l || h[n] >= r + k)f = 0;
if (f)cout << "YES" << endl;
else cout << "NO" << endl;
}
}
相關文章
- A - Fence CodeForces - 1422A
- Arduino BuildingUI
- win10 fence如何刪除_win10 fence刪除詳細步驟Win10
- Building an Automatically Scaling Web ApplicationUIWebAPP
- Building OpenNI using a cross-compilerUIROSCompile
- CF1316E Team BuildingUI
- [leetcode] 1642. Furthest Building You Can ReachLeetCodeUI
- A lightweight, ultra-fast tool for building observability pipelinesASTUI
- Android 12(S) 影像顯示系統 - GraphicBuffer同步機制 - FenceAndroid
- 飛利浦案例研究: Building Connectivity with Kotlin MultiplatformUIKotlinPlatform
- [翻譯]Building WhatsApp Ui with Flutter Part 2 : The Chat ListUIAPPFlutter
- 深度學習問題記錄:Building your Deep Neural深度學習UI
- Qt開發,報錯:Error while building/deploying project untitled (kit: ....)QTErrorWhileUIProject
- 呼叫https介面時報錯:PKIX path building failed 的問題HTTPUIAI
- Pay close attention to your download code——Visual Studio trick to run code when buildingUI
- Error building Player: Win32Exception: ApplicationName=‘xxxxxxxxxxxxxxxxxx//sdk\tools\zipalign.exe' ...ErrorUIWin32ExceptionAPP
- 詳解GPFS檔案系統架構、組網和Building Block架構UIBloC
- AAR 檔案錯誤:Direct local .aar file dependencies are not supported when building an AAR.UI
- eclipse新建maven專案:'Building' has encountered a problem. Errors occurred during the build.EclipseMavenUIError
- msyql 5.7.21 [ 35%] Building CXX object sql/CMakeFiles/sql.dir/item_row.cc.oUIObjectSQL
- 成功解決building ‘snappy._snappy‘ extension error: Microsoft Visual C++ 14.0 is required. Get it with “BUIAPPErrorROSC++
- [How HTTPS works Part 1 — Building Blocks] HTTPS 的工作方式第 1 部分-基本構造塊HTTPUIBloC
- 《深度學習——Andrew Ng》第五課第一週程式設計作業_1_Building a RNN Step by Step深度學習程式設計UIRNN
- F8開發者大會即將來臨,神祕的Building8或將展示AR產品UI
- 01神經網路和深度學習-Building your Deep Neural Network: Step by Step-第四周程式設計作業1神經網路深度學習UI程式設計