• 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;
    }
    
    
  • 相关阅读:
    rails 相关文件
    linux学习---vi进行多行的copy,cut
    设计
    互联网---现在正在变成过去
    testing
    TTl
    如何成为优秀的性能测试工程师
    linuX学习
    Programiz 中文系列教程·翻译完成
    Programiz C 语言教程·翻译完成
  • 原文地址:https://www.cnblogs.com/PushyTao/p/13144165.html
Copyright © 2020-2023  润新知