CodeForces 546A-Soldier and Bananas
题意:
有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的更多相关文章
- 546A. Soldier and Bananas
		
等差数列: 以k为首相,k为公差,w个数量的和与n的大小关系 输出max(sum-0,0) Java程序 import java.util.Scanner; public class A546 ...
 - 水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas
		
题目传送门 /* 水题:ans = (1+2+3+...+n) * k - n,开long long */ #include <cstdio> #include <algorithm ...
 - Soldier and Bananas
		
Soldier and Bananas 题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=173141 题意: 给 ...
 - 【codeforces 546A】Soldier and Bananas
		
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
 - 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根香蕉的话,需要问他的朋友借 ...
 - 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 J. Soldier and Number Game(素数筛)
		
题目描述: Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes inpu ...
 - Codeforces 546E Soldier and Traveling(最大流)
		
题目大概说一张无向图,各个结点初始有ai人,现在每个人可以选择停留在原地或者移动到相邻的结点,问能否使各个结点的人数变为bi人. 如此建容量网络: 图上各个结点拆成两点i.i' 源点向i点连容量ai的 ...
 - codeforces 546E. Soldier and Traveling  网络流
		
题目链接 给出n个城市, 以及初始时每个城市的人数以及目标人数.初始时有些城市是相连的. 每个城市的人只可以待在自己的城市或走到与他相邻的城市, 相邻, 相当于只能走一条路. 如果目标状态不可达, 输 ...
 
随机推荐
- 加速Eclipse使其成为超快的IDE
			
按照下述步骤来加速Eclipse为超快的IDE,它适用于32和64位版本的Eclipse /JDK(OS为64位Windows 7). 1.禁用防病毒软件,或将JDK.Eclipse.workspac ...
 - 华为 1.static有什么用途?(请至少说明两种)
			
1.static有什么用途?(请至少说明两种) 1)在函数体,一个被声明为静态的变量在这一函数被调用过程中维持其值不变. 2) 在模块内(但在函数体外),一个被声明为静态的变量可以被模块内所用函数访问 ...
 - 转:union 联合体(共用体)
			
转自:http://blog.csdn.net/xiao3404/article/details/22276485 2.共用体 2.1共用体的概念 共用体是一种构造类型的数据结构.在一个“共用体”内可 ...
 - EL 表达式
			
转载自 :http://blog.csdn.net/qwerasdf123/article/details/4189889 EL表达式 1.EL简介 1)语法结构 ${expr ...
 - 转!论if else与switch的效率高低问题
			
转 下面来详细描述switch与ifelse的区别. switch...case与if...else的根本区别在于,switch...case会生成一个跳转表来指示实际的case分支的地址,而这个跳转 ...
 - spring 编程式事务管理和声明式事务管理
			
编程式事务管理 Spring 的编程式事务管理概述 在 Spring 出现以前,编程式事务管理对基于 POJO 的应用来说是唯一选择.用过 Hibernate 的人都知道,我们需要在代码中显式调用be ...
 - js中正则表达式 书写方法
			
function test(){ var text="index.aspx?test=1&ww=2&www=3"; var re = ...
 - switch-case 执行顺序
			
switch(expression){ case value : //语句 break; //可选 case value : //语句 break; //可选 //你可以有任意数量的case语句 de ...
 - java 模板
			
模板模式: 解决某类事情的步骤有些是固定的,有些是会发生变化的,这时我们提供 一个模板代码,从而提高效率. 模板模式的作用: 1.解决这类事情其中一件的解决方案. 2.分析代码,把发生变化的代码抽象取 ...
 - .NET Reflector 8.2支持VS2013高亮显示和代码地图视图
			
Red Gate Software公司最近发布的.NET Reflector 8.2支持Visual Studio 2013,其Reflector 桌面程序能够转换十六进制/十进制值.桌面程序还支持局 ...