Mineral Water

nid=24#time" title="C、C++、go、haskell、lua、pascal Time Limit1000ms Memory Limit 65536K java、python2、python3、ruby、perl Time Limit2000ms Memory Limit 131072K" style="padding:0px; margin:0px; color:rgb(83,113,197); text-decoration:none">

Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描写叙述

Laoshan mineral water is one of famous well-known mineral water, Tyrant(means”Tu Hao”) Chierush liked to drink this mineral water very much. He said that it is such a natural taste, but this is not the focus. One day Chierush went to the campus supermarket
to buy n bottles of Laoshan mineral water, the boss see that he is an acquaintance, so he gave him a copy of preferential policies - he can change every m empty bottles into one bottle mineral water. Your task is to help Chierush calculate how many bottles
of mineral water he can drink?

输入

The input consists of multiple test cases. The first line contains an integer T means the number of test cases. Each test case consists of one line with two numbers represent n and m. (T<=100, 2<=n,m<=2*10^9)

输出

For each test case, output one line, including one number that represents the answer.

演示样例输入

2
2 2
5 4

演示样例输出

3
6
貌似山东某届的省赛题?也是够水的了
题意 :n瓶水,m个空瓶能够换一瓶水。问最多能够喝多少瓶水。
注意用LL 然后没什么了。先喝掉m的整数倍。然后剩下的n%m瓶加上能够换到水的瓶数,这时候把这个数看成最開始那个n就能够了。循环搞定。
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#define ll long long
using namespace std;
const int INF=0x3f3f3f3f;
int main()
{
ll n,m;int t;
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld",&n,&m);
ll ans=0;
while(n>=m)
{
ans+=(n-n%m);
ll tem=n/m;
n%=m;
n+=tem;
}
ans+=n;
printf("%lld\n",ans);
}
return 0;
}

SDUST 2844-Mineral Water(数学)的更多相关文章

  1. words2

    餐具:coffee pot 咖啡壶coffee cup 咖啡杯paper towel 纸巾napkin 餐巾table cloth 桌布tea -pot 茶壶tea set 茶具tea tray 茶盘 ...

  2. leetcode题目清单

    2016-09-24,开始刷leetcode上的算法题,下面整理一下leetcode题目清单.Github-leetcode 1.基本数学 Two Sum Palindrome Number Cont ...

  3. 编写高质量代码改善C#程序的157个建议[匿名类型、Lambda、延迟求值和主动求值]

    前言 从.NET3.0开始,C#开始一直支持一个新特性:匿名类型.匿名类型由var.赋值运算符和一个非空初始值(或以new开头的初始化项)组成.匿名类型有如下基本特性: 1.既支持简单类型也支持复杂类 ...

  4. memcached 系列2:memcached实例(转载)

    在上一篇文章,我们讲了,为什么要使用memched做为缓存服务器(没看的同学请点 这里).下面让我们以memcached-1.2.1-win32版本的服务组件(安装后是以一个windows服务做dae ...

  5. memcached实例(enyim.com Memcached Client)

    在上一篇文章,我们讲了,为什么要使用memched做为缓存服务器(没看的同学请点这里).下面让我们以memcached-1.2.1-win32版本的服务组件(安装后是以一个windows服务做daem ...

  6. C#开发157

    C#开发157条建议   编写高质量代码改善C#程序的157个建议[匿名类型.Lambda.延迟求值和主动求值] 摘要: 前言 从.NET3.0开始,C#开始一直支持一个新特性:匿名类型.匿名类型由v ...

  7. python 自然语言处理(四)____词典资源

    词典或者词典资源是一个词和/或短语及其相关信息的集合,例如:词性和词意定义等相关信息.词典资源附属于文本,而且通常在文本的基础上创建和丰富.下面列举几种nltk中的词典资源. 1. 词汇列表语料库 n ...

  8. (转)C# 中使用分布式缓存系统Memcached

    转自:http://blog.csdn.net/devgis/article/details/8212917 缘起: 在数据驱动的web开发中,经常要重复从数据库中取出相同的数据,这种重复极大的增加了 ...

  9. English trip -- VC(情景课)1 B Countries

    Vocabulary focus 核心词汇 Vo ca bu la ry   fo cus [və(ʊ)'kæbjʊlərɪ]      ['fəʊkəs] Listen and repeat  听并 ...

随机推荐

  1. IIS部署SSL证书后提示不可信的解决方案

    IIS部署SSL证书后提示不可信的解决方案   本帖最后由 wosign-support3 于 2015-7-17 17:18 编辑 第一步:打开mmc——点击文件——添加删除管理单元——证书——计算 ...

  2. Sublime Text3 学习笔记

    注:以下记录自己的 Sublime Text3学习过程(持续更新中) 目录: 安装 下载文件 破解试用 插件安装 安装 Sublime Text 是一套跨平台的文本编辑器,支持基于Python的插件. ...

  3. Centos6.5下 执行“ll”提示“-bash: ll: command not found”

    ll 是 ls -l的别名,之所所以 ll出现错误是因为没有定义别名. 如果要实现ll 命令,可以做如下操作: 编辑 ~./bashrc 添加 ls -l 的别名为 ll即可 [root@Centos ...

  4. sizeof and strlen 的区别

    首先,strlen 是函数,sizeof 是运算操作符,二者得到的结果类型为 size_t,即 unsigned int 类型.大部分编译程序在编译的时候就把 sizeof 计算过了,而 strlen ...

  5. MySQL-----唯一索引

    唯一索引: 单列唯一索引和联合唯一索引 索引是为了加速查找. 唯一索引是加了约束条件.例如主外键. 唯一索引的约束: 约束不能重复(可以为空) 主键不能重复(不能为空) 加速查找 create tab ...

  6. SIGPIPE 13 和其他信号的对照表

    SIGPIPE 13 和其他信号的对照表 SIGHUP 1 在控制终端上检测到挂断或控制线程死亡 是SIGINT 2 交互注意信号 是SIGQUIT 3 交互中止信号 是SIGILL 4 检测到非法硬 ...

  7. Python文件处理(txt、csv文件读取)

    打开文件 使用Python内置的方法 open()可以打开文件 file object = open(file_name [, access_mode][, buffering]) file_name ...

  8. Android BGABadgeView:显示提示数字(2)

     Android BGABadgeView:显示提示数字(2) 在附录文章3的基础上,对代码进行稍微改造,显示在红色小圆球内部显示数字,同时给红色小圆球通过可编程调控红色小圆球的整体外观,布局文件 ...

  9. [luoguP2617] Dynamic Ranking(树状数组 套 主席树 + 离散化)

    传送门 BZOJ上是权限题,洛谷赞啊. 求区间 K 大数很简单. 但是如果修改某个数的话,那么就得把这个数及后面所建的主席树都更新一遍 nlogn,显然不行. 所以可以在外面套一个树状数组来优化,树状 ...

  10. 567. Permutation in String

    Problem statement: Given two strings s1 and s2, write a function to return true if s2 contains the p ...