您的位置:首页 > 编程语言 > Go语言

hust 1170 - Baskets of Gold Coins

2014-06-14 10:51 253 查看
题目描述

YouaregivenNbasketsofgoldcoins.Thebasketsarenumberedfrom1toN.Inallexceptoneofthebaskets,eachgoldcoinweighswgrams.Intheoneexceptionalbasket,eachgoldcoinweighsw-dgrams.Awizardappearsonthesceneandtakes1coinfromBasket1,2coinsfromBasket2,andsoon,uptoandincludingN-1coinsfromBasketN-1.HedoesnottakeanycoinsfromBasketN.HeweighstheselectedcoinsandconcludeswhichoftheNbasketscontainsthelightercoins.Yourmissionistoemulatethewizard'scomputation.

输入

Theinputfilewillconsistofoneormorelines;eachlinewillcontaindataforoneinstanceoftheproblem.Morespecifically,eachlinewillcontainfourpositiveintegers,separatedbyoneblankspace.Thefirstthreeintegersare,respectively,thenumbersN,w,andd,asdescribedabove.Thefourthintegeristheresultofweighingtheselectedcoins.Nwillbeatleast2andnotmorethan8000.Thevalueofwwillbeatmost30.Thevalueofdwillbelessthanw.

输出

Foreachinstanceoftheproblem,yourprogramwillproduceonelineofoutput,consistingofonepositiveinteger:thenumberofthebasketthatcontainslightercoinsthantheotherbaskets.

样例输入

102581109
102581045
80003012959879400

样例输出

2
10
50

这个题目个人认为第二个样例是有问题的,这个题在hdu上也有,不过在hdu上longlong是不通过的,所以个人觉得hdu这样一个大平台,应该多兼容一下,要不会影响很多人的发挥,就像这次百度之星一样,有很多人就死在longlong和__int64的手里


#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cmath>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#defineinf0x0f0f0f0f

usingnamespacestd;

intmain()
{
//freopen("in.txt","r",stdin);
intsum,n,w,d,ans;
while(scanf("%d%d%d%d",&n,&w,&d,&sum)!=EOF)
{
ans=(((n*(n-1))/2)*w-sum)/d;
if(ans==0)printf("%d\n",n);
elseprintf("%d\n",ans);
}
return0;
}


作者chensunrise


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: