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 ...
随机推荐
- error MIDL2311 解决方法
error MIDL2311 : statements outside library block are illegal in mktyplib compatability mode : [] 在编 ...
- 深入GCD(五):资源竞争
概述我将分四步来带大家研究研究程序的并发计算.第一步是基本的串行程序,然后使用GCD把它并行计算化.如果你想顺着步骤来尝试这些程序的话,可以下载源码.注意,别运行imagegcd2.m,这是个反面教材 ...
- 求菲波那契数列的第n个数
1,2,3,5,8,13..... 求第n个数 def get_num(n): if n == 1: return 1 if n == 2: return 2 return get_num(n - 1 ...
- 在 Edison 上自动启动 Arduino Sketch
前言 原创文章,转载引用务必注明链接,水平有限,如有疏漏,欢迎指正. 本文使用Markdown写成,为获得更好的阅读体验和正常的链接.图片显示,请访问我的博客原文: http://www.cnblog ...
- java cup占用高分析脚本
[was@dmgr ita-scripts]$ vi java_analys.sh PID=$1 ; ps -mp $PID -o THREAD,tid,time | awk -F " ...
- 还在为开发APP发愁? 这里就有现成通用的代码!
1.开源控件 1)首页: 1.1)首先是下拉刷新数据的 SwipeRefreshLayout 地址:https://github.com/hanks-zyh/SwipeRefreshLayout 1. ...
- iOS simulator+Appium
Why are you trying to run iOS automation on a real device? That's a bad idea. iOS Automation on a re ...
- Python 002- 爬虫爬取淘宝上耳机的信息
参照:https://mp.weixin.qq.com/s/gwzym3Za-qQAiEnVP2eYjQ 一般看源码就可以解决问题啦 #-*- coding:utf-8 -*- import re i ...
- 使用Genymotion调试出现错误INSTALL_FAILED_CPU_ABI_INCOMPATIBLE解决的方法
今天在使用android studio在Genymotion上调试程序出现INSTALL_FAILED_CPU_ABI_INCOMPATIBLE导致程序安装不了: 后来百度发现是要安装:http:// ...
- 端口扫描 开启 防火墙 iptables SELinux
Linux 如何打开端口 - lclc - 博客园 https://www.cnblogs.com/lcword/p/5869522.html linux如何查看端口相关信息_百度经验 https:/ ...