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-延迟操作方法总结
原文网址:http://lysongzi.com/2016/01/30/iOS-%E5%BB%B6%E8%BF%9F%E6%93%8D%E4%BD%9C%E6%96%B9%E6%B3%95%E6%80 ...
- ejabberd、jabber、jabberd、xmpp辨析
Jabber 是著名的即时通讯服务服务器,它是一个自由开源软件,能让用户自己架即时通讯服务器,可以在Internet上应用,也可以在局域网中应用. XMPP(可扩展消息处理现场协议)是基于可扩展 ...
- 锋利的jQuery读书笔记---jQuery中动画
jQuery中的动画: 1.show和hide 2.fadeIn和fadeOut 3.slideUp和slideDown <!DOCTYPE html> <html> < ...
- HDU 5437 Alisha’s Party
题意:有k个人带着价值vi的礼物来,开m次门,每次在有t个人来的时候开门放进来p个人,所有人都来了之后再开一次门把剩下的人都放进来,每次带礼物价值高的人先进,价值相同先来先进,q次询问,询问第n个进来 ...
- mysql-5.6.15_winX64在win764位系统下的安装操作步骤总结
mysql 版权声明:本文为博主原创文章,未经博主允许不得转载. 自从换了新电脑win764位,支持的内存从原来的3G(2G机身+1G内存条)变到了现在的8G(机身4G+4G内存条),机子的速度是 ...
- webdriver(python)学习笔记五——层级定位
层级定位 在实际的项目测试中,经常会有这样的需求:页面上有很多个属性基本相同的元素,现在需要具体定位到其中的一个.由于属性基本相当,所以在定位的时候会有些麻烦,这时候就需要用到层级定位.先定位父元素, ...
- android Loger日志类(获取内置sd卡)
Android手机自带内部存储路径的获取 原文地址:http://my.oschina.net/liucundong/blog/288183 直接贴代码: public static String g ...
- CSS_网站配色参考方案
http://www.cnblogs.com/QLeelulu/archive/2008/04/04/1136974.html Shiny silver [#EEEEEE] Reddi ...
- 【Spark学习】Apache Spark配置
Spark版本:1.1.1 本文系从官方文档翻译而来,转载请尊重译者的工作,注明以下链接: http://www.cnblogs.com/zhangningbo/p/4137969.html Spar ...
- Java ArrayList Sort
Collections.sort(hits_list, new Comparator<ScoreDoc>(){ @Override public int compare(ScoreDoc ...