博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2015 HUAS Provincial Select Contest #1 A
阅读量:4579 次
发布时间:2019-06-09

本文共 1183 字,大约阅读时间需要 3 分钟。

题目:

Description

A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).

He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?

Input

The first line contains three positive integers k, n, w (1  ≤  k, w  ≤  1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.

Output

Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.

题目大意:第i个香蕉的价格是ik元,求总共的价钱

算法用等差数列的求和公式:(1+i)*i/2;

代码:

1 #include
2 using namespace std; 3 int main() 4 { 5 int k,w,n,sum,b,price; 6 while(cin>>k>>n>>w) 7 { 8 if(k>=1&&w<=1000&&n>=0&&n<=1000000000) 9 {10 sum=(1+w)*w/2;11 price=sum*k;12 if(price>n)13 {14 b=price-n;15 printf("%d\n",b); 16 }17 else printf("0\n");18 }19 }20 return 0;21 }

 

 

转载于:https://www.cnblogs.com/huaxiangdehenji/p/4652273.html

你可能感兴趣的文章
第七章学习小结
查看>>
GS LiveMgr心跳管理类
查看>>
设计模式学习笔记(二)之观察者模式、装饰者模式
查看>>
mysql导出数据库和恢复数据库代码
查看>>
走出软件泥潭 第一回 雪上加霜
查看>>
小鸟哥哥博客 For SAE
查看>>
gui编程实践(3)--记事本界面 JMenuBar JMenu
查看>>
App测试方法总结
查看>>
51nod-1228: 序列求和
查看>>
BZOJ1303: [CQOI2009]中位数图
查看>>
2015上海马拉松线上跑感悟-人生如同一场马拉松
查看>>
北航软院2013级C#期末考试部分考题解答
查看>>
CentOS 系统中安装 ArcGIS Server10.1 一些问题及解决
查看>>
Sharepoint学习笔记—习题系列--70-573习题解析 -(Q142-Q143)
查看>>
asp.net里登陆记住密码
查看>>
【BZOJ】2190 [SDOI2008]仪仗队(欧拉函数)
查看>>
线性规划中的单纯形法与内点法(原理、步骤以及matlab实现)(一)
查看>>
简单DP【p2758】编辑距离
查看>>
Spring Data JPA:关联映射操作
查看>>
JWT入门简介
查看>>