【想法题】Knot Puzzle @AtCoder Grand Contest 002 C/upcexam5583
时间限制: 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.
样例输入
3 50
样例输出
Possible
提示
If the knot 1 is untied first, the knot 2 will become impossible to untie.
题目大意是给你n根绳子通过打结的方式首尾相接成一根绳子,要你解开这个绳子上所有的结,但你每次只能选一根长度大于L的绳子解开其上的一个结。
如果我们把用来组成长绳的n个绳子称作绳元
只要有两个相邻的绳元长度大于L,就可以以这两个绳元为中心从两端解开整根绳子。
#define IN_PC() freopen("C:\\Users\\hz\\Desktop\\in.txt","r",stdin)
#define OUT_PC() freopen("C:\\Users\\hz\\Desktop\\out.txt","w",stdout)
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int a[maxn];
int main()
{
// IN_PC();
// OUT_PC();
int n,L;
cin>>n>>L;
for(int i=0;i<n;i++){
scanf("%d",a+i);
}
int flag = 0;
for(int i=1;i<n;i++){
if(a[i-1]+a[i]>=L)flag = 1;
}
printf("%s\n",flag?"Possible":"Impossible");
return 0;
}
【想法题】Knot Puzzle @AtCoder Grand Contest 002 C/upcexam5583的更多相关文章
- AtCoder Grand Contest 002
AtCoder Grand Contest 002 A - Range Product 翻译 告诉你\(a,b\),求\(\prod_{i=a}^b i\)是正数还是负数还是零. 题解 什么鬼玩意. ...
- AtCoder Grand Contest 002 F:Leftmost Ball
题目传送门:https://agc002.contest.atcoder.jp/tasks/agc002_f 题目翻译 你有\(n*k\)个球,这些球一共有\(n\)种颜色,每种颜色有\(k\)个,然 ...
- Atcoder Grand Contest 002 F - Leftmost Ball(dp)
Atcoder 题面传送门 & 洛谷题面传送门 这道 Cu 的 AGC F 竟然被我自己想出来了!!!((( 首先考虑什么样的序列会被统计入答案.稍微手玩几组数据即可发现,一个颜色序列 \(c ...
- AtCoder Grand Contest 002 D - Stamp Rally
Description We have an undirected graph with N vertices and M edges. The vertices are numbered 1 thr ...
- [Atcoder Grand Contest 002] Tutorial
Link: AGC002 传送门 A: …… #include <bits/stdc++.h> using namespace std; int a,b; int main() { sca ...
- AtCoder Grand Contest 002 (AGC002) F - Leftmost Ball 动态规划 排列组合
原文链接https://www.cnblogs.com/zhouzhendong/p/AGC002F.html 题目传送门 - AGC002F 题意 给定 $n,k$ ,表示有 $n\times k$ ...
- AtCoder Grand Contest 002题解
传送门 \(A\) 咕咕 int main(){ cin>>a>>b; if(b<0)puts(((b-a+1)&1)?"Negative": ...
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
- AtCoder Grand Contest 005
AtCoder Grand Contest 005 A - STring 翻译 给定一个只包含\(ST\)的字符串,如果出现了连续的\(ST\),就把他删去,然后所有位置前移.问最后剩下的串长. 题解 ...
随机推荐
- [转] whistle--全新的跨平台web调试工具
whistle是基于Node实现的跨平台web调试代理工具,类似的工具有Windows平台上的Fiddler+Willow,基于Java实现的Charles,及公司同事基于Node实现的Livepoo ...
- javascript 对象(四)
一.对象概述 对象中包含一系列的属性,这些属性是无序的.每个属性都有一个字符串key和对应的value. var obj={x:1,y:2}; obj.x; obj.y; 1.为什么属性的key必须是 ...
- jquery正则表达式验证(手机号、身份证号、中文名称)
这篇文章主要介绍了jquery正则表达式验证,实现手机号.身份证号.中文名称验证,感兴趣的小伙伴们可以参考一下 本文实例需要验证的内容:中文姓名.手机号.身份证和地址,验证方法分享给大家供大家参考,具 ...
- 今天才知道原来我还没弄清楚js中全局变量和局部变量的定义...
查资料看到这段还不错,来源:原文:https://blog.csdn.net/czh500/article/details/80429133 粘过来记录一下... 1.使用var声明变量,在方法内部是 ...
- P1005 矩阵取数游戏 区间dp 高精度
题目描述 帅帅经常跟同学玩一个矩阵取数游戏:对于一个给定的n \times mn×m的矩阵,矩阵中的每个元素a_{i,j}ai,j均为非负整数.游戏规则如下: 每次取数时须从每行各取走一个元素,共n ...
- 019 python面相对象编程
一:self的意思 1.说明 self代表类的实例,而非类. 类的方法与普通的函数只有一个特别的区别——它们必须有一个额外的第一个参数名称, 按照惯例它的名称是 self. self 代表的是类的实例 ...
- SQL注入——SQL Injection
本文部分内容转自:https://www.cnblogs.com/rush/archive/2011/12/31/2309203.html http://www.diybl.com/course/7_ ...
- Linux下java开发环境配置总结
1 安装JDK,卸载以前的jdk,安装jdk1.8 : 参考:http://www.jb51.net/os/RedHat/73016.html 需要注意配置环境变量中的路径要和当前安装的jdk路径一致 ...
- html 水平竖直居中
line-height:容器高度 <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
- Spring中 PROPAGATION_REQUIRED 解释 事物是在一个方法里调用其他的方法,一起成功或者一起失败,是方法之间的关系,而不是某一个方法内部的问题。而且要以抛异常的方式来表明方法的失败,以此来导致事物起作用,大家全失败。
事务传播行为种类 Spring在TransactionDefinition接口中规定了7种类型的事务传播行为, 它们规定了事务方法和事务方法发生嵌套调用时事务如何进行传播: 事务传播行为类型 事务传播 ...