• Knot Puzzle——AT


    题目描述

    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.

    题意,将相邻的两端绳子打上结拴在一起,问给出某长度能否将某个结打开,题目较水

    #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
    #pragma GCC optimize("Ofast")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize (2)
    #pragma G++ optimize (2)
    #include <bits/stdc++.h>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <set>
    #include <stack>
    #include <string>
    #include <vector>
    using namespace std;
    #define wuyt main
    typedef long long ll;
    #define HEAP(...) priority_queue<__VA_ARGS__ >
    #define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
    template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
    template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
    ///#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
    ///char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
    ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
    if(c == '-')Nig = -1,c = getchar();
    while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
    return Nig*x;}
    #define read read()
    const ll mod=1e9+7;
    const ll inf=0x3f3f3f3f;
    const int maxn=1e6+9;
    ll cnt=0;
    ///int zhan[maxn];
    int num[maxn];
    int top;
    int main()
    {
        ll n=read,l=read;
        vector<ll>vet(n);
        for(int i=0;i<n;i++) vet[i]=read;
        for(int i=0;i<n-1;i++)
        {
            if(vet[i]+vet[i+1]>=l){
                printf("Possible
    ");
                return 0;
            }
        }
        printf("Impossible
    ");
        return 0;
    }
    
    
  • 相关阅读:
    PHP查询手机号归属地
    MSVC版本号对应关系
    IT界名人录
    QT5 Win7 项目封装发行版(C++)
    ANSI编码
    微信小程序 for循环说明
    virtualbox 虚拟机 安装win7系统 无法联网
    go 实现两个goroutine交替执行打印数字和字母
    go 学习之反射
    go 学习之数据类型
  • 原文地址:https://www.cnblogs.com/PushyTao/p/13144165.html
Copyright © 2020-2023  润新知