Codeforces Beta Round #85 (Div. 1 Only) A. Petya and Inequiations 贪心
A. Petya and Inequiations
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/111/problem/A
Description
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.
Sample Input
5 15 15
Sample Output
4
4
1
1
2
HINT
题意
让你找n个数,使其满足
a1^2+a2^2...+an^2>=x
a1+a2+...+an<=y
找不到输出-1
题解:
贪心一下,我们让a1-an-1都令为1,然后剩下的an我们就直接暴力枚举就好了~
代码
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std; int main()
{
int n;long long x,y;
cin>>n>>x>>y;
x-=(n-);
y-=(n-);
if(y<=){return puts("-1");}
int flag = ;
long long t;
for(int i=;i<=y;i++)
{
t = i;
if(t>y)
return puts("-1");
if(t*t>=x)
{
flag = ;
break;
}
}
if(flag==)
return puts("-1");
for(int i=;i<=n-;i++)
printf("1\n");
printf("%d\n",t);
}
Codeforces Beta Round #85 (Div. 1 Only) A. Petya and Inequiations 贪心的更多相关文章
- Codeforces Beta Round #85 (Div. 1 Only) B. Petya and Divisors 暴力
B. Petya and Divisors Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/111 ...
- codeforces水题100道 第二十四题 Codeforces Beta Round #85 (Div. 2 Only) A. Petya and Strings (strings)
题目链接:http://www.codeforces.com/problemset/problem/112/A题意:忽略大小写,比较两个字符串字典序大小.C++代码: #include <cst ...
- Codeforces Beta Round #85 (Div. 1 Only) C (状态压缩或是数学?)
C. Petya and Spiders Little Petya loves training spiders. Petya has a board n × m in size. Each cell ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
随机推荐
- iOS开发:AFNetworking、MKNetworkKit和ASIHTTPRequest比较
转:http://www.xue5.com/Mobile/iOS/747036.html 之前一直在使用ASIHTTPRequest作为网络库,但是由于其停止更新,iOS7上可能出现更多的问题,于是决 ...
- Java之UncaughtExceptionHandler
概述: UncaughtExceptionHandler是为了捕获没有被捕获的异常,包括运行时异常,执行错误(内存溢出等),子线程抛出的异常等,你可以在uncaughtException(xx)里对后 ...
- 头痛的ASCII和preg_replace()
说这个之前,大家先看下这条语句: preg_replace("/\<\?\=(\\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\[\]\"\'\$\x7f- ...
- 通过js检测到iframe,使父窗口重定向到index -----------???----------------------
通过js检测到iframe,使父窗口重定向到index -----------???---------------------- 如果本身已将在iframe中,那么重定向的页面应该直接添加到父级ifr ...
- jdbc:oracle:thin:@192.168.3.98:1521:orcl(详解)
整理自互联网 一. jdbc:oracle:thin:@192.168.3.98:1521:orcljdbc:表示采用jdbc方式连接数据库oracle:表示连接的是oracle数据库thin:表示连 ...
- redis 和 bloom filter
今天打算使用redis 的bitset搞一个 bloom filter, 这样的好处是可以节省内存,坏处是可能在会有一些数据因为提示重复而无法保存. bloom filter 的大体原理就是通过不同的 ...
- Linux环境上,Oracle常用命令
1.启动oracle数据库: //切换至Oracle用户: [root@server36 ~]# su - oracle //进入sqlplus环境,nolog参数表示不登录: [oracle@ser ...
- 通过简单的Linux内核启动程序代码窥探操作系统的启动原理
作者:吴乐 山东师范大学 <Linux内核分析> 孟宁 MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.程序设计与分析 ...
- linux-制作linux启动U盘
1. 使用的制作工具 Ø 下载需要制作启动盘的linux的iso文件 Ø 制作启动盘的软件linux usb creater Ø U盘(大小差不多需要4G的空间) 软件可以的下载的地址:http:// ...
- 瞬间从IT屌丝变大神——注释规则
注释的主要规则如下: 公共组件和各栏目的维护者都需要在文件头部加上注释说明: /** *文件用途说明 *作者姓名 *联系方式*制作日期 **/ 大的模块注释方法: //======= //代码用途 / ...