CodeForces 546A A Contest #1(A. Soldier and Bananas)
2015-07-17 20:57
281 查看
Asoldierwantstobuywbananasintheshop.Hehastopaykdollarsforthefirstbanana,2kdollarsforthesecondoneandsoon(inotherwords,hehastopayi·kdollarsforthei-thbanana).Hehasndollars.Howmanydollarsdoeshehavetoborrowfromhisfriendsoldiertobuywbananas?InputThefirstlinecontainsthreepositiveintegersk, n, w(1 ≤ k, w ≤ 1000,0 ≤ n ≤ 109),thecostofthefirstbanana,initialnumberofdollarsthesoldierhasandnumberofbananashewants.OutputOutputoneinteger—theamountofdollarsthatthesoldiermustborrowfromhisfriend.Ifhedoesn'thavetoborrowmoney,output0.SampleInputInput3174Output13这个题目是意思是有ndollar,thefirstbananacostkdollars,第i个就需costk*i,问买w个bananas是否需要借钱;借钱需要多少?分析:首先计算w个bananas需要多少money,在与n比较。#include<iostream>#include<cstdio>usingnamespacestd;intmain(){intk,n,w,b;inti;while(scanf("%d%d%d",&k,&n,&w)==3){intsum=0;for(i=1;i<=w;i++)sum+=i*k;//计算w个bananas所需的money
b=sum-n;//比较总需费与n的大小,最后输出b的结果 if(b==0||b<0) printf("0\n"); else printf("%d\n",b);}return0;}
相关文章推荐
- UVa-10317 - Equating Equations
- C语言--程序设计基础——9章
- 动态规划:钢条切割问题
- 黑马程序员----IO流(下)
- 关于导入项目到eclipse产生的奇葩问题
- pat 1035. Password (20)
- poj3279
- 饥荒抓蜜蜂的方法
- dp状态压缩-铺砖问题
- python各种类型转换
- 我是如何学会简谱的
- C文件操作
- XPages 揭秘
- 解读Web Page Diagnostics网页细分图
- 多个Activity相互调用和Intent
- Linux(定时任务)
- 1002. A+B for Polynomials (25)
- poj 1195 Mobile phones 二维树状数组
- IOS之UINavigationBar设计和定制
- 【小结】SG生成函数(Grundy函数)