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> ...
随机推荐
- 【周期串】NYOJ-1121 周期串
[题目链接:NYOJ-1121] 例如:abcabcabc 该字符串的长度为9,那么周期串的长度len只可能为{1,3,9},否则就不可能构成周期串. 接下来,就是要在各周期间进行比较.描述不清... ...
- java 访问器方法中对象引用的问题
"注意不要编写返回引用可变对象的访问器方法".因为会破坏类的封装性,引用的内容可能会被改变,产生业务逻辑上的错误. 什么是可变对象? 先要搞清楚java中值传递和引用传递的问题,总结如下: 1.对象就 ...
- win下Java环境安装
1.eclipse:eclipse.org 解压后直接打开 2.JDK:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-do ...
- loadrunner 发送gzip压缩json格式(转)
转:http://blog.csdn.net/gzh0222/article/details/7711281 使用java vuser实现,发送gzip压缩json格式. /* * LoadRunne ...
- bjfu1100 圆环
这题也是2011百度之星的一道题.知道做法后代码极简单. 不过我做完后随便上网搜了一下,发现竟然还有很多不同的做法.别的做法我就不管了,我只把我的做法的原理说清楚.我做题时是按如下顺序逐步找到规律的: ...
- NSarray 赋值 拷贝 等问题记录
1. NSArray * a1 = @[@"1",@"2",@"3"]; NSArray * a2 = a1; a1跟a2所指向的地址是一样 ...
- 线性模型(3):Logistic Regression
此笔记源于台湾大学林轩田老师<机器学习基石><机器学习技法> (一)Logistic Regression 原理 对于分类问题,假设我们想得到的结果不是(x属于某一类)这种形式 ...
- Ubuntu_wifi&pppoe
学校现在上网全部要拨号,加上我在宿舍用的是无线路由,也就是要在ubuntu下实现连接wifi后再拨号,这个功能在默认的ubuntu网络设置里面是没有的,里面有dsl但是对有线网络使用的,有点小郁闷.不 ...
- IO-同步,异步,阻塞,非阻塞,阅读摘要
http://www.cnblogs.com/Fly-Wind/p/io.html http://blog.csdn.net/historyasamirror/article/details/5778 ...
- 【SPOJ】Transposing is even more fun!
题意: 给出a.b 表示按先行后列的方式储存矩阵 现在要将其转置 可以交换两个点的位置 求最小操作次数 题解: 储存可以将其视为拉成一条链 设a=5.b=2 则在链上坐标用2^***(a,b)表示为( ...