题目:Petya and Inequiations
传送门:
http://codeforces.com/problemset/problem/111/A
http://codeforces.com/problemset/problem/112/C
分析:
先引一个简单的结论:“(a+b)^2>=a^2+b^2”,可得一个简单的贪心:让其中一个数越大越好;再从“a[1] + a[2] + ... + a[n] <= y”入手:让a[1]越大越好,a[2]、a[3]...a[n]都为1;如果这种构造方法不行,则无解。
代码:
#include<cstdio> int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); long long n,x,y; scanf("%I64d%I64d%I64d ",&n,&x,&y); if(y<n || (y-n+1)*(y-n+1)+(n-1)<x) printf("-1 "); else{ printf("%d ",y-n+1); for(int i(2);i<=n;++i)printf("1 "); } //fclose(stdin);fclose(stdout); return 0; }