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;
}
}
相關文章
- HDU 4667 Building Fence(求凸包的周長)UI
- Fence RepairAI
- ACM Color the fenceACM
- win10 fence如何刪除_win10 fence刪除詳細步驟Win10
- Arduino BuildingUI
- Team BuildingUI
- A - Fence CodeForces - 1422A
- fence_ipmilan 的一個缺陷MILA
- team building planUI
- POJ 3253 Fence Repair 優先佇列AI佇列
- Codeforces 448C. Painting FenceAI
- Codeforces 448C Painting Fence:分治AI
- Building a Dynamic Oracle ETL ProcedureUIOracle
- Building Custom ComponentsUI
- CF448C Painting Fence(遞迴+貪心)AI遞迴
- Building a RESTful API in a Rails ApplicationUIRESTAPIAIAPP
- Notes for building gimp-printUI
- SGU 532. Building Foundation 暴力UI
- POJ 3253Fence Repair(哈夫曼&優先佇列)AI佇列
- AKM專案逸事之Team BuildingUI
- Building the main Guest Additions module [FAILED]UIAI
- Android TV-Building Layouts for TVAndroidUI
- android tv-Building TV GamesAndroidUIGAM
- Building OpenNI using a cross-compilerUIROSCompile
- Building a Pub/Sub Message Bus with WCF and MSMQUIMQ
- 那裡有Building Parsers in Java下載?UIJava
- CF1316E Team BuildingUI
- Android 12(S) 影像顯示系統 - GraphicBuffer同步機制 - FenceAndroid
- 飛利浦案例研究: Building Connectivity with Kotlin MultiplatformUIKotlinPlatform
- 構建微服務(Building Microservices)-PDF 文件微服務UIROS
- Building the Data Warehouse - Fourth Edithin - 讀書筆記UI筆記
- Building a Movie Recommendation Service with Apache Spark & Flask - Part 1UIApacheSparkFlask
- Building a Movie Recommendation Service with Apache Spark & Flask - Part 2UIApacheSparkFlask
- Implementing App Restrictions,Building a Device Policy ControllerAPPRESTUIdevController
- Building an Automatically Scaling Web ApplicationUIWebAPP
- POJ 3253-Fence Repair(哈夫曼樹-最小值優先佇列)AI佇列
- 深度學習問題記錄:Building your Deep Neural深度學習UI
- [翻譯]Building WhatsApp Ui with Flutter Part 2 : The Chat ListUIAPPFlutter