美文网首页
Codeforces 1355D - Game With Arr

Codeforces 1355D - Game With Arr

作者: 费城的二鹏 | 来源:发表于2020-06-22 20:12 被阅读0次

    日常一道算法题。

    翻译

    数组游戏

    Petya 和 Vasya 两个人玩游戏

    一开始 Petya 需要构造一个长度为 N 的数组,他们的和是 S,并且挑选一个 K 给 Vasya。

    如果 Vasya 能构造一个非空的上面数组的子数组,使他们的和为 K,那么 Vasya 获胜,反之 Petya 获胜。

    输入格式

    输入两个整数 N S。

    输出格式

    输出 YES 数组 和 K,或者输出 NO

    分析

    构造的逻辑就是 N - 1 个 1 和 S - N + 1,然后挑选 N 为 K,判断 K 是否小于 S - N + 1 即可。

    代码(Python3)

    # https://codeforces.com/problemset/problem/1355/D
     
    import sys
    import os
    import heapq
    import math
     
    try:
        path = "./file/input.txt"
        if os.path.exists(path):
            sys.stdin = open(path, 'r')
        # sys.stdout = open(r"./file/output.txt", 'w')
    except:
        pass
     
    t = 1
     
    def printd(value):
        # print(value)
        pass
     
    def case():
        arr = list(map(int, input().split(" ")))
        n, s = arr[0], arr[1]
        right = s - n + 1
        left = n - 1
        k = left + 1
        if k < right:
            print("YES")
            result = [1] * left
            result.append(right)
            print(" ".join(str(i) for i in result)) 
            print(k)
        else:
            print("NO")
    
    for _ in range(t):
        case()
    

    更多代码尽在 https://github.com/Tconan99/Codeforces

    by 费城的二鹏 2020.06.18 长春

    相关文章

      网友评论

          本文标题:Codeforces 1355D - Game With Arr

          本文链接:https://www.haomeiwen.com/subject/sqkpxktx.html