• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

  • 博客园
  • 联系
  • 订阅
  • 管理

View Post

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 }

 

 

 


 
 

 

posted on 2015-07-17 20:57  tony-cao  阅读(268)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3