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 0≤K≤S0≤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 S−KS−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.
The first line contains two integers NN and SS (1≤N≤S≤1061≤N≤S≤106) — the required length of the array and the required sum of its elements.
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).
1 4
YES 4 2
3 4
NO
3 8
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; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!