CodeForces 546A Soldier and Bananas
来源:互联网 发布:广联达软件配置要求 编辑:程序博客网 时间:2024/05/17 07:31
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.
Sample Input
Input
3 17 4
Output
13
实现代码
#include<iostream>using namespace std;#define num 1010int doll[num];int main(){ int k,w; long long n; int sum=0; cin>>k>>n>>w; for(int i=1;i<=w;i++) doll[i]=i*k; for(int i=1;i<=w;i++) sum=sum+doll[i]; if(sum<=n) cout<<"0"<<endl; if(sum>n) cout<<sum-n<<endl; return 0;}
题解:
一个soldier去商店买香蕉
k:香蕉初始单价
n:最初的钱
w:购买香蕉的数量
sum:购买w香蕉所需的总费用
注:香蕉的单价为k*i (i=1;i++)
第一个for求出不同购买数量的单价
第二个for求出购买的费用
即可得到所需要向朋友借的钱
- CodeForces 546A Soldier and Bananas
- Soldier and Bananas( CodeForces - 546A)
- CodeForces-546A-Soldier and Bananas
- 【CodeForces】[546A]Soldier and Bananas
- 【codeforces 546A】Soldier and Bananas
- Problem--546A--Codeforces--Soldier and Bananas
- codeforces 546A Soldier and Bananas
- CodeForces 546 A - Soldier and Bananas(模拟求和)
- codeforces 546A(Soldier and Bananas) Java
- A. Soldier and Bananas
- CF 546A Soldier and Bananas
- CF 546A-Soldier and Bananas
- A. Soldier and Bananas(CF546) Codeforces Round #304 (Div. 2)
- Codeforces刷题之路——546A Soldier and Bananas
- Codeforces546A:Soldier and Bananas
- Coderforces Soldier and Bananas
- #codeforces 546C# Soldier and Cards (模拟)
- CodeForces 546D Soldier and Number Game
- Gifview的使用
- 如何在struts2的action返回结果之后再来进行费时的数据库操作呢?
- Android初学习 - 明暗度,窗体透明等的设置技巧
- poj 3414 Pots(BFS)(简单题)
- Monkey log异常分析说明
- CodeForces 546A Soldier and Bananas
- The sizeof Operator
- Oracle库Delete删除千万以上普通堆表数据的方法
- opencv中各种矩阵乘的区别
- display属性
- java快速排序实现
- Android中的UI更新
- 获得二叉树中两个节点的所有公共祖先
- synergy使用配置<Server window7 Client Fedora21>