首页 > 其他 > 详细

CodeForces 546 A - Soldier and Bananas

时间:2015-05-27 10:01:10      阅读:204      评论:0      收藏:0      [点我收藏+]

题目链接click here~~

【题目大意】

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?

【解题思路】

公式:判断(((w+1)*(w)/2)*k-n)是否大于零

代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k,n,w;
    scanf("%d%d%d",&k,&n,&w);
    printf("%d\n",(((w+1)*(w)/2)*k-n)>0?(((w+1)*(w)/2)*k-n):0);
    return 0;
}


CodeForces 546 A - Soldier and Bananas

原文:http://blog.csdn.net/u013050857/article/details/46042479

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!