题意:

  有n dollar,the first banana cost  k dollars,第i个就需cost k*i,问买w个bananas是否需要借钱;借钱需要多少?

分析:首先计算w个bananas需要多少money,在与n比较。


代码如下:
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <iterator>
#include <vector> using namespace std; #define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 10000010
#define MAXM 1000010 int main()
{
int k, w;
long long n; while(scanf("%d%lld%d", &k, &n, &w)==)
{
int i;
LL tot = ;
for(i = ; i <= w; i++ )
tot += i*k; //计算w个bananas所需的money
if(n >= tot)
printf("0\n");
else
printf("%lld\n", tot - n); //比较总需费与n的大小,最后输出它们的差值
} return ;
}

 

 
 

CodeForces 546A-Soldier and Bananas的更多相关文章

  1. 546A. Soldier and Bananas

      等差数列: 以k为首相,k为公差,w个数量的和与n的大小关系 输出max(sum-0,0) Java程序   import java.util.Scanner; public class A546 ...

  2. 水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas

    题目传送门 /* 水题:ans = (1+2+3+...+n) * k - n,开long long */ #include <cstdio> #include <algorithm ...

  3. Soldier and Bananas

    Soldier and Bananas 题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=173141 题意: 给 ...

  4. 【codeforces 546A】Soldier and Bananas

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 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根香蕉的话,需要问他的朋友借 ...

  6. A - Soldier and Bananas

    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description A sold ...

  7. 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 ...

  8. Codeforces J. Soldier and Number Game(素数筛)

    题目描述: Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes inpu ...

  9. Codeforces 546E Soldier and Traveling(最大流)

    题目大概说一张无向图,各个结点初始有ai人,现在每个人可以选择停留在原地或者移动到相邻的结点,问能否使各个结点的人数变为bi人. 如此建容量网络: 图上各个结点拆成两点i.i' 源点向i点连容量ai的 ...

  10. codeforces 546E. Soldier and Traveling 网络流

    题目链接 给出n个城市, 以及初始时每个城市的人数以及目标人数.初始时有些城市是相连的. 每个城市的人只可以待在自己的城市或走到与他相邻的城市, 相邻, 相当于只能走一条路. 如果目标状态不可达, 输 ...

随机推荐

  1. 如何定位摄像机,使物体在屏幕上始终具有相同的像素宽度和高度?(threes)

    from How to position the camera so that the object always has the same pixel width and height on the ...

  2. maven 启动 报错 Fatal error compiling: 无效的目标发行版

    http://news.tuxi.com.cn/news/119999990123162/31622105.html http://lyking2001.iteye.com/blog/837440 针 ...

  3. MySQL在windows系统中修改datadir路径后无法启动问题,报错1067

    windows server2008下如何更改MySQL数据库的目录的帖子已经很多了,这里简单介绍一个步骤,如果不成功请先查看其它帖子. 更改默认的mysql数据库目录 将 C:\Documents ...

  4. 2016年GitHub排名前20的Python机器学习开源项目(转)

    当今时代,开源是创新和技术快速发展的核心.本文来自 KDnuggets 的年度盘点,介绍了 2016 年排名前 20 的 Python 机器学习开源项目,在介绍的同时也会做一些有趣的分析以及谈一谈它们 ...

  5. Nginx + Tomcat 配置

    Windows下Nginx的启动.停止等命令 在Windows下使用Nginx,我们需要掌握一些基本的操作命令,比如:启动.停止Nginx服务,重新载入Nginx等,下面我就进行一些简单的介绍.1.启 ...

  6. jquery 全选功能

    1.直接全选(复选框名字要统一) <input type="CHECKBOX" id="cbSelectAll" onclick="$('inp ...

  7. Lecture Notes: Macros

    原论文链接失效,特在这里保存一份 http://www.apl.jhu.edu/~hall/Lisp-Notes/Macros.html Lisp functions take Lisp values ...

  8. jQuery用户从服务器端注册登录

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. 如何理解和熟练使用JS 中的call apply

    有时候看一两个关于apply或call的小例子,感觉能够理解一点点但是下次碰到又要纠结半天才能转过弯来-而且不知道怎么应用到实际工作当中去- call 和 apply 都是为了改变某个函数运行时的 c ...

  10. Android系统启动过程-uBoot+Kernel+Android

    摘要:本文是参考大量网上资源在结合自己查看源代码总结出来的,让自己同时也让大家加深对Android系统启动过程有一个更加深入的了解!再次强调,本文的大多数功劳应归功于那些原创者们,同时一些必要的参考链 ...