Petya and Inequiations 题解
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
- a12 + a22 + ... + an2 ≥ x
- a1 + a2 + ... + an ≤ y
Input
The first line contains three space-separated integers n, x and y (1 ≤ n ≤ 105, 1 ≤ x ≤ 1012, 1 ≤ y ≤ 106).
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is recommended to use cin, cout streams or the %I64d specificator.
Output
Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
Example
5 15 15
4 4 1 1 2
2 3 2
-1
1 99 11
11
思路:
令a1 + a2 + ... + an= y,那么现在想办法如何拆分y使得a12 + a22 + ... + an2取得最大值,当其中n-1个数都取1,剩下一个数取y-(n-1)时a12 + a22 + ... + an2取得最大值。因此,令a1 + a2 + ... + an= y时,若a12 + a22 + ... + an2大于等于x,那么存在解,且此时的a1,…,an是其中的一组解,否则不存在解。
代码:
#include <iostream>using namespace std;int main()
{int64_t n,y;int64_t x;while(cin>>n>>x>>y){if(y>=n){int64_t temp=y-(n-1);if(temp*temp+(n-1)>=x){cout<<temp<<endl;for(int i=0;i<n-1;i++)cout<<1<<endl;}elsecout<<-1<<endl;}elsecout<<-1<<endl;}return 0;
}
Petya and Inequiations 题解相关推荐
- codeforces 111A/112C Petya and Inequiations
题目:Petya and Inequiations 传送门: http://codeforces.com/problemset/problem/111/A http://codeforces.com/ ...
- C. Petya and Inequiations
C. Petya and Inequiations 题意: 给你一个数字 n,x,y 求使得 满足这个条件的 数组 a 问题分析: 尽量保证其中一个 平方数最大就行 因为一个数 分解成 几个数 取平方 ...
- D. Petya and Array(树状数组 + 前缀和 + 逆序对的思想)
Problem - D - Codeforces Petya 有一个由 n 个整数组成的数组 a.他最近学习了部分和,现在他可以非常快地计算出数组中任何一段元素的和.这个段是一个非空的序列,相邻的元素 ...
- 关于一些初级ACM竞赛题目的分析和题解(二)。
关于一些初级ACM竞赛题目的分析和题解(二). 今天写了关于排序的题 中间有加号的复杂的一行字符 其次还有关于tolower函数的应用, 上题 ...
- 关于一些初级ACM竞赛题目的分析和题解(六)。
关于一些初级ACM竞赛题目的分析和题解(六). 下面是关于一些关于数字判断的题,比较简单,先来看第一题: A. Lucky Division time limit per test 2 seconds ...
- CF Round #681(Div.2)/CF1443 口胡题解
由于一些原因(时间),本蒟蒻决定口胡这场比赛. 下面的题解纯口胡,但是与题解中的解法基本相同. Solution A 答案就是2n+2,2n+4,2n+6--4n2n+2, 2n+4, 2n+6--4 ...
- [JS][dfs]题解 | #迷宫问题#
题解 | #迷宫问题# 题目链接 迷宫问题 题目描述 定义一个二维数组 N*M ,如 5 × 5 数组下所示: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 1, 1 ...
- [JS][dp]题解 | #打家劫舍(一)#
题解 | #打家劫舍(一)# 题目链接 打家劫舍(一) 题目描述 描述 你是一个经验丰富的小偷,准备偷沿街的一排房间,每个房间都存有一定的现金,为了防止被发现,你不能偷相邻的两家,即,如果偷了第一家, ...
- [JS]题解 | #魔法数字#
题解 | #魔法数字# 题目链接 魔法数字 题目描述 牛妹给牛牛写了一个数字n,然后又给自己写了一个数字m,她希望牛牛能执行最少的操作将他的数字转化成自己的. 操作共有三种,如下: 在当前数字的基础上 ...
最新文章
- Gastroenterology:住院期间COVID-19患者肠道菌群的变化
- 错误:Parameter ‘0‘ not found.Available parameters are [arg1, arg0, param1, param2]的解决方法
- WPF - 资源收集
- python api调用展示_Python百视api调用示例
- 在mysql中插入日期
- arcgis按属性设置符号大小
- 价值200万的小米LOGO给UI设计师带来了什么?
- bzoj 3123 可持久化线段树启发式合并
- 微信公众号用到的网站
- SSD1306(OLED驱动芯片介绍)
- I don't know what to say 事件的 NPM 包中奖名单,有你在用的吗?
- uniapp弹窗滚动阻止外部滚动
- 宝塔面板可以建立静态网站吗?如何部署一个静态页面?
- 实现微信通知提醒的方法总结
- Android Facebook登录,进来看就对了
- maven-compiler-plugin 插件配置详解
- asc量子计算机,2020ASC世界大学生超级计算机竞赛聚焦量子计算和语言智能
- 前端全栈大佬是如何使用javaScript实现一个无缝轮播(最终版)
- Django + ajax
- mobaXterm无法上传,打开,下载文件解决方案