• 【想法题】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
    ",flag?"Possible":"Impossible");
        return 0;
    }
  • 相关阅读:
    static作用(修饰函数、局部变量、全局变量)(转)
    地弹
    开漏(open drain)和开集(open colletor)
    过冲、振铃,非单调性
    串扰(crosstalk)
    数字通信基本概念
    电源和地
    分布式系统与集总系统
    传输线及其特性阻抗
    MSP430G2553 Launchpad 硬件I2C驱动
  • 原文地址:https://www.cnblogs.com/NeilThang/p/9356621.html
Copyright © 2020-2023  润新知