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 nx 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 贪心的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  5. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  6. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  7. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  8. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  9. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

随机推荐

  1. <九>面向对象分析之UML核心元素之设计类,类,属性,方法,可见性

    设计类

  2. 一天一个Java基础——对象和类

    1.在Java中你所做的全部工作就是定义类,产生那些类的对象,以及发送消息给这些对象 2.可以在类中设置两种类型的元素:字段(也被称作数据成员)和方法(也被称作成员函数) 3.字段可以是任何类型的对象 ...

  3. RAC集群时间同步服务

    集群时间同步服务在集群中的两个 Oracle RAC 节点上执行以下集群时间同步服务配置.Oracle Clusterware 11g 第 2 版及更高版本要求在部署了 Oracle RAC 的集群的 ...

  4. Kotlin 语言高级安卓开发入门

    过去一年,使用 Kotlin 来为安卓开发的人越来越多.即使那些现在还没有使用这个语言的开发者,也会对这个语言的精髓产生共鸣,它给现在 Java 开发增加了简单并且强大的范式.Jake Wharton ...

  5. [转] arcgis Engine创建shp图层

    小生 原文 arcgis Engine创建shp图层 以创建点图层为例.首先要得到保存文件的地址. SaveFileDialog saveFileDialog = new SaveFileDialog ...

  6. Linux+Apache+Tomcat集群配置

    参考: http://blog.csdn.net/bluishglc/article/details/6867358# http://andashu.blog.51cto.com/8673810/13 ...

  7. ZOJ 3329-One Person Game(概率dp,迭代处理环)

    题意: 三个色子有k1,2,k3个面每面标号(1-k1,1-k2,1-k3),一次抛三个色子,得正面向上的三个编号,若这三个标号和给定的三个编号a1,b1,c1对应则总和置零,否则总和加上三个色子标号 ...

  8. acdream 1056 (黑白染色)

    题意:给你一些关系,每个关系是两只马的名字,表示这两个马不能在一个分组里,问你能否将这些马分成两组. 黑白染色,相邻的点染不同颜色.bfs搞即可,水题. /* * this code is made ...

  9. Tableau学习笔记之二

    2张图片解析下Tableau 9.0界面的功能 1.数据加载界面: 2.数据分析界面:

  10. 【Linux学习】 包含子目录的makefile简单应用

    1 .目录结构 practice6 / ui / ui.h   ui.c practice6 / dal / dal.h dal.c practice6 / bll / bll.h  bll.c pr ...