CodeForces 546A-Soldier and Bananas


题意:

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

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



代码如下:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <fstream>
 5 #include <cmath>
 6 #include <ctime>
 7 #include <cstdlib>
 8 #include <algorithm>
 9 #include <set>
10 #include <map>
11 #include <list>
12 #include <stack>
13 #include <queue>
14 #include <iterator>
15 #include <vector>
16 
17 using namespace std;
18 
19 #define LL long long
20 #define INF 0x3f3f3f3f
21 #define MOD 1000000007
22 #define MAXN 10000010
23 #define MAXM 1000010
24 
25 int main()
26 {
27     int k, w;
28     long long n;
29 
30     while(scanf("%d%lld%d", &k, &n, &w)==3)
31     {
32         int i;
33         LL tot = 0;
34         for(i = 1; i <= w; i++ )
35             tot += i*k; //计算w个bananas所需的money
36         if(n >= tot)
37             printf("0\n");
38         else
39             printf("%lld\n", tot - n);  //比较总需费与n的大小,最后输出它们的差值
40     }
41 
42     return 0;
43 }



优质内容筛选与推荐>>
1、spring源码学习2
2、常用的jvm命令
3、关于路径的使用,assi下载和
4、出处
5、Linux 系统参数优化


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号