Soldier and Bananas
Soldier and Bananas
题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=173141
题意:
给出第一个香蕉的价钱k,后买的第i个香蕉所需要的价钱就是i*k;
给出手上所有的钱,求出如果要买w个香蕉还少多少钱。
代码:
#include<iostream>
using namespace std;
int main()
{
int k,w,n, sum=;
cin>>k>>n>>w;
for(int i=;i<=w;i++)
{
sum=sum+i*k;
}
if(sum<=n)
cout<<<<endl;
else cout<<sum-n<<endl;
return ;
}
Soldier and Bananas的更多相关文章
- 水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas
题目传送门 /* 水题:ans = (1+2+3+...+n) * k - n,开long long */ #include <cstdio> #include <algorithm ...
- A - Soldier and Bananas
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description A sold ...
- 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 ...
随机推荐
- php mysql PDO基本操作
<?php $dbh = new PDO('mysql:host=localhost;dbname=localhost', 'root', ''); $dbh->setAttribute( ...
- Windows MDL原理总结
http://blog.csdn.net/tbwood/article/details/5400419 http://www.cnblogs.com/jack204/archive/2011/12/2 ...
- AIDL
在介绍跨程序进程间通信AIDL前,先看一下本程序activity与某个服务是怎么绑定在一起进行交互的. 需求:服务有两个方法.分别是播放音乐与停止播放音乐.该程序的活动要访问这两个方法,在activi ...
- Vs2012调试本地windows服务
背景: 在我的工作经历中,我用到了一个我们以前学习中没有接触过的老东西-服务.之所说以前没有接触过,是因为自己没有系统的研究过这东西:之所以又说它是老东西,是因为我们其实早就知道他的存在,经常用它去干 ...
- Android:res之shape制作圆角、虚线、渐变
xml控件配置属性 android:background="@drawable/shape" 标签 corners ----------圆角gradient ----------渐 ...
- Loadrunner中动态添加虚拟用户
添加的虚拟用户会立马开始执行: 场景组的两种模式: Vuser组模式: Vuser组模式中,对于压力负载机是不能同时添加多个 但是我们可以在一个脚本里通过多次添加Vuser,每次添加30个Vuser, ...
- css/js(工作中遇到的问题)-3
设置宽高比 使用padding/margin-top/bottom; 设置出教准确的自适应布局; 用于预加载图片; 关于数据库设置 添加extra对象用于扩展; 添加type类型; 对于字体 使用百分 ...
- Ubantu下面命令听歌(豆瓣fm)
在Linux下一直是不太方便的事情,下面推荐一个方法: 终端中输入以下命令安装豆瓣fm: >> sudo pip install douban.fm >> sudo apt-g ...
- Spring mvc 验证码的做法
http://jingyan.baidu.com/article/4f7d5712da7a131a201927b0.html
- http://blog.csdn.net/a491057947/article/details/46724707
http://blog.csdn.net/a491057947/article/details/46724707