zoukankan      html  css  js  c++  java
  • Codeforces Round #643 (Div. 2) D. Game With Array(构造)

    Petya and Vasya are competing with each other in a new interesting game as they always do.

    At the beginning of the game Petya has to come up with an array of NN positive integers. Sum of all elements in his array should be equal to SS. Then Petya has to select an integer KK such that 0KS0≤K≤S.

    In order to win, Vasya has to find a non-empty subarray in Petya's array such that the sum of all selected elements equals to either KK or SKS−K. Otherwise Vasya loses.

    You are given integers NN and SS. You should determine if Petya can win, considering Vasya plays optimally. If Petya can win, help him to do that.

    Input

    The first line contains two integers NN and SS (1NS1061≤N≤S≤106) — the required length of the array and the required sum of its elements.

    Output

    If Petya can win, print "YES" (without quotes) in the first line. Then print Petya's array in the second line. The array should contain NN positive integers with sum equal to SS. In the third line print KK. If there are many correct answers, you can print any of them.

    If Petya can't win, print "NO" (without quotes).

    You can print each letter in any register (lowercase or uppercase).

    Examples
    Input
    Copy
    1 4
    
    Output
    Copy
    YES
    4
    2
    Input
    Copy
    3 4
    
    Output
    Copy
    NO
    Input
    Copy
    3 8
    
    Output
    Copy
    YES
    2 1 5
    4
    看了有一会才搞懂题意Petya和Vasya看反了 注意 只要Vasya有可能选出一个不能满足条件的K的话就判Petya赢!
    首先找出所有不可能的情况:当S/N==1的时候一定是NO,因为每个数都是正数,这样一定会出现1,因此对手只要选K=1则必输。
    如果S/N>1,直接构造S/N S/N S/N ... S/N+S%N 这样只要对手选K=1则必赢。
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n,s;
        cin>>n>>s;
        if(s/n>1)
        {
            cout<<"YES"<<endl;
            int i;
            for(i=1;i<=n-1;i++)cout<<s/n<<' ';
            cout<<s%n+s/n<<endl;
            cout<<1<<endl;
        }
        else cout<<"NO"<<endl;
    }
  • 相关阅读:
    AR路由器web界面每IP限速配置方法
    传输层:TCP 协议
    从需求的角度去理解Linux系列:总线、设备和驱动
    京东的个性化推荐系统
    数据挖掘-MovieLens数据集_电影推荐_亲和性分析_Aprioro算法
    Linux时间子系统之七:定时器的应用--msleep(),hrtimer_nanosleep()
    Linux SPI总线和设备驱动架构之四:SPI数据传输的队列化
    拦截器及 Spring MVC 整合
    表现层 JSP 页面实现
    Controller 层实现
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12902814.html
Copyright © 2011-2022 走看看