Knot Puzzle 贪心

Knot Puzzle
时间限制: 2 Sec 内存限制: 256 MB

题目描述
We have N pieces of ropes, numbered 1 through N. The length of piece i is ai.

At first, for each i(1≤i≤N−1), piece i and piece i+1 are tied at the ends, forming one long rope with N−1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly:

Choose a (connected) rope with a total length of at least L, then untie one of its knots.
Is it possible to untie all of the N−1 knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.

Constraints
2≤N≤105
1≤L≤109
1≤ai≤109
All input values are integers.
输入
The input is given from Standard Input in the following format:

N L
a1 a2 … an
输出
If it is not possible to untie all of the N−1 knots, print Impossible.

If it is possible to untie all of the knots, print Possible.
样例输入 Copy
3 50
30 20 10
样例输出 Copy
Possible
提示
If the knot 1 is untied first, the knot 2 will become impossible to untie.

题目就是让你剪n-1个结点,每次选取的区间长度不能少于 l ,也就是说只要有两条相邻的线总长 >= l ,那么这个两条线之间的节点就可以放在最后剪,每次选取的区间都包含这两条线,这样就可以都剪完了。

比较水,想出来代码就很简单了。

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#define X first
#define Y second
using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

const int N=100010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;

int n,l;
int a[N],mx;

int main()
{
//	ios::sync_with_stdio(false);
//	cin.tie(0);
	
	scanf("%d%d",&n,&l);

	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	
	for(int i=2;i<=n;i++)
	{
		if(mx<a[i]+a[i-1])
			mx=a[i]+a[i-1];
	}
	
	if(mx>=l) puts("Possible");
	else puts("Impossible");


	return 0;
}




















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值