栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 2373 Dividing the Path

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 2373 Dividing the Path

#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<cmath>#include<iostream>#include<sstream>#include<queue>#include<deque>#include<iomanip>using namespace std;typedef long long LL;typedef pair<int, int> pii;#define lson l , m , rt<<1#define rson m+1 , r , rt<<1|1#define keyTree (ch[ch[root][1]][0])const int maxn = 1001111;const int mask = 32767;const int INF = (mask << 15) | mask;int q[maxn], front, rear;int dp[maxn];bool can[maxn];struct node {int l, r;node() {}node(int l, int r) :l(l), r(r) {}} f[1111];void solve(int N, int L, int A, int B) {int i, j;for (i = 0; i < N; ++i) {if (f[i].r - f[i].l > B) {puts("-1");return;}}memset(can, true, sizeof(can));for (i = 0; i < N; ++i) {for (j = f[i].l + 1; j < f[i].r; ++j)can[j] = false;}front = rear = 0;dp[0] = 0;for (i = 2; i <= L; i += 2) {dp[i] = INF;j = i - A;if (j < 0)continue;if (can[j] && dp[j] < INF) {while (front < rear && dp[q[rear - 1]] >= dp[j])--rear;q[rear++] = j;} if (can[i]) {while (front < rear && i - q[front] > B)++front;if (front < rear)dp[i] = dp[q[front]] + 1;}}if (dp[L] == INF)puts("-1");elseprintf("%dn", dp[L]);}int main() {int N, L, A, B, i, l, r;scanf("%d%d%d%d", &N, &L, &A, &B);for (i = 0; i < N; ++i) {scanf("%d%d", &l, &r);f[i] = node(l, r);}solve(N, L, A << 1, B << 1);return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/378052.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号