546A. Soldier and Bananas

等差数列: 以k为首相,k为公差,w个数量的和与n的大小关系 输出max(sum-0,0)
Java程序
import java.util.Scanner;
public class A546 {
static void run(){
Scanner in = new Scanner(System.in);
int k =in.nextInt();
int n = in.nextInt();
int w = in.nextInt();
int count = 0;
count = (1+w)*w*k/2;
// System.out.println(count);
if(count>n){
System.out.println(count-n);
}else
System.out.println(0);
}
public static void main(String[] args){
run();
}
}
Python程序
def A546():
k,n,w = map(int, raw_input().split())
count = (1+w)*w*k*0.5
if count > n :
print int(count -n)
else:
print 0 if __name__=='__main__':
A546()
546A. 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 ...
- 【codeforces 546A】Soldier and Bananas
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 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水题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 ...
随机推荐
- 取精华、去糟粕!适合iOS开发者的15大网站推荐
iOS开发者若想使技艺达到炉火纯青的地步,就要不断借鉴他人的有益经验,紧跟新兴科技和工具的步伐.除了Apple的开发者中心,其他网站上的文章和资源也具备参考价值,若能学得一二,必能锦上添花.不过,时间 ...
- web安全之token
Token,就是令牌,最大的特点就是随机性,不可预测.一般黑客或软件无法猜测出来. 那么,Token有什么作用?又是什么原理呢? Token一般用在两个地方: 1)防止表单重复提交. 2)anti c ...
- PHP笔记-PHP中Web Service.
这几天工作需要.net站点免登陆访问PHP的Wiki站点. PHP不熟,感觉很苦逼.任务下来了,必须搞定.准备用SSO,太麻烦了,要改写别人很多代码,这个是第三方CMS,封装的很厉害,不好改.最后我的 ...
- 31.DDR2问题3_waring?
Warning: (vlog-2275) 'ddr2_controller' already exists and will be overwritte. 出现这个waring,是因为xxx_bb.v ...
- P3382: [Usaco2004 Open]Cave Cows 3 洞穴里的牛之三
首先,我们先确定,最长的曼哈顿距离只可能为 x1+y2-(x2+y2) 和 x1-y1-(x2-y2) 所以我们只需要维护四个值, 分别代表 max(x+y) ; max(x-y) ; min(x+y ...
- matlab求距一个数最近的奇(偶)数
int_a = floor(a);minEven = int_a+mod(int_a,2); %最近偶数minOdd = int_a+1-mod(int_a,2); %最近奇数
- Lua与C++交互初探之Lua调用C++
Lua与C++交互初探之Lua调用C++ 上一篇我们已经成功将Lua的运行环境搭建了起来,也成功在C++里调用了Lua函数.今天我来讲解一下如何在Lua里调用C++函数. Lua作为一个轻量级脚本语言 ...
- 代码实现Autolayout
代码实现Autolayout的步骤 利用NSLayoutConstraint类创建具体的约束对象 添加约束对象到相应的view上 - (void)addConstraint:(NSLayoutCons ...
- C++编程显示四则运算题目
题目:C++编程显示四则运算题目 设计思路:(1)让用户自己确定出题的数量,同时显示加减乘除四则运算. (2)考虑到用户可能只会一种运算,因此可以选择运算.
- android ViewPaper高度自适应
tv_btn_web.measure(0, 0);//计算所需的真实宽高 LayoutParams params=vp_btn_menu.getLayoutParams(); params.heigh ...