A - Soldier and Bananas
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
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
Input3 17 4Output13
题意:
士兵去买香蕉,买的第一根香蕉的价格为k,第i根的价格为i*k。给定士兵带的钱和需要买的香蕉数目,求士兵要借多少钱,如果不用借钱,则输出0.(由于没有判断输出0的条件WA了一发..冤枉啊!!!!!)
虽然是一道水题,但还是发出来劝解各位小伙伴和自己一定要认真读题,千万不要冤WA。
还是附AC代码:
#include<iostream>
using namespace std; int a[]; int main(){
int k,n,w,sum=;
cin>>k>>n>>w;
for(int i=;i<=w;i++){
a[i]=i*k;
sum+=a[i];
}
if(sum-n>)//!!!!!!
cout<<sum-n<<endl;
else
cout<<""<<endl;
return ;
}
A - Soldier and Bananas的更多相关文章
- Soldier and Bananas
Soldier and Bananas 题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=173141 题意: 给 ...
- 水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas
题目传送门 /* 水题:ans = (1+2+3+...+n) * k - n,开long long */ #include <cstdio> #include <algorithm ...
- B - Soldier and Bananas
Problem description A soldier wants to buy w bananas in the shop. He has to pay k dollars for the fi ...
- 【codeforces 546A】Soldier and Bananas
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 546A. Soldier and Bananas
等差数列: 以k为首相,k为公差,w个数量的和与n的大小关系 输出max(sum-0,0) Java程序 import java.util.Scanner; public class A546 ...
- codeforces水题100道 第五题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas (math)
题目链接:http://www.codeforces.com/problemset/problem/546/A题意:一个人现在有n元,它买第i根香蕉需要i*k元,问他要买w根香蕉的话,需要问他的朋友借 ...
- Codeforces Round #304 (Div. 2) -----CF546
A. Soldier and Bananas A soldier wants to buy w bananas in the shop. He has to pay k dollars for t ...
- codeforcess水题100道
之所以在codeforces上找这100道水题的原因是为了巩固我对最近学的编程语言的掌握程度. 找的方式在codeforces上的PROBLEMSET中过的题最多的那些题里面出现的最前面的10个题型, ...
- Codeforces Round #304 (Div.2)
A. Soldier and Bananas 题意:有个士兵要买w个香蕉,香蕉起步价为k元/个,每多买一个则贵k元.问初始拥有n元的士兵需要借多少钱? 思路:简单题 #include<iostr ...
随机推荐
- ASP.NET Core 如何记录每次响应的Response信息 - sky 胡萝卜星星 - CSDN博客
原文:ASP.NET Core 如何记录每次响应的Response信息 - sky 胡萝卜星星 - CSDN博客 上一篇文章中我们已经成功的记录了Request部分的信息,现在我们来看下如何记录Res ...
- BUPT复试专题—串查找(?)
https://www.nowcoder.com/practice/a988eda518f242c29009f8620f654ede?tpId=67&tqId=29642&rp=0&a ...
- 下篇:express、koa1、koa2的中间件原理
本作品采用知识共享署名 4.0 国际许可协议进行许可.转载联系作者并保留声明头部与原文链接https://luzeshu.com/blog/express-koa 本博客同步在http://www.c ...
- 【剑指offer】异或去重
转载请注明出处:http://blog.csdn.net/ns_code/article/details/27568975 这篇文章没有代码.介绍的是纯理论的思路. 异或是一种基于二进制的位运算,用符 ...
- dom get selector
function realsQuery(element) { if(!element){ return ""; } var currentQuery=""; i ...
- centos7+php7 swoole 安装
下载 swoole 首先下载swoole的源码包,这个操作很简单,没有太多说的. wget -c https://github.com/swoole/swoole-src/archive/v2.0.6 ...
- lonlifeOJ1152 “玲珑杯”ACM比赛 Round #19 概率DP
E -- Expected value of the expression DESCRIPTION You are given an expression: A0O1A1O2A2⋯OnAnA0O1A1 ...
- liberOJ#6006. 「网络流 24 题」试题库 网络流, 输出方案
#6006. 「网络流 24 题」试题库 题目描述 假设一个试题库中有 n nn 道试题.每道试题都标明了所属类别.同一道题可能有多个类别属性.现要从题库中抽取 m mm 道题组成试卷.并要求 ...
- XML复习笔记(复习资料为菜鸟教程里的XML教程)
XML 指可扩展标记语言(eXtensible Markup Language) XML 的设计宗旨是传输数据,而不是显示数据. XML 标签没有被预定义.您需要自行定义标签. XML 被设计为具有自 ...
- Mac OS安装Scrapy
个人觉得掌握简单的爬虫知识非常有用,特别是想要从一些特定网站自动地下载一些资源或者统计一些数据,非常的有用.对于产品经理来说,如果要了解竞争产品.替代产品的价格,可以写一个爬虫脚本从各大电商网站爬取相 ...