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. Asp.Net MVC中Controller、Action、View是如何激活调用的

    上篇我们介绍了MVC的路由,知道在注册路由的时候会创建一个MvcHandler将其和Url规则一起放入到了RouteCollection中,之后请求通过UrlRoutingModule,根据当前的UR ...

  2. Java集合(三)--Collection、Collections和Arrays

    Collection: Collection是集合类的顶级接口,提供了对集合对象进行基本操作的通用接口方法.Collection接口的意义是为各种具体的集合提供了最大化 的统一操作方式,其直接继承接口 ...

  3. hdfs深入:09、获取分布式文件系统客户端的几种方式

    FileSystem是一个抽象类:获取一个抽象类有两种方式:第一种:看这个抽象类有没有提供什么方法返回他本身第二种:找子类 具体代码如下: /** * 通过url注册的方式访问hdfs,了解,不会用到 ...

  4. thinkphp5生成二维码

    1.运用composer下载拓展到vendor下 composer require aferrandini/phpqrcode 2.common.php 里面写生成二维码函数 <?php // ...

  5. [Python3网络爬虫开发实战] 6.1-什么是Ajax

    Ajax,全称为Asynchronous JavaScript and XML,即异步的JavaScript和XML.它不是一门编程语言,而是利用JavaScript在保证页面不被刷新.页面链接不改变 ...

  6. quilt-补丁工具

    参考:https://blog.csdn.net/adomwon/article/details/79047059 前言: 在查找openwrt中samba编译报错问题时直到了quilt这个工具,为了 ...

  7. Android Studio + Genymotion模拟器安装与配置

    一.Android studio 下载与安装 https://developer.android.google.cn/studio/index.html 进入谷歌官方链接下载Android studi ...

  8. stark组件之显示页面搭建(四)

    页面搭建包括第一如何获取前端传过来的数据,第二如何在前端渲染出对应标签. 一.后台获取数据并进行处理 在路由系统中,每一个路由都对应着一个处理函数,如下所示: def wrapper(self, fu ...

  9. N分之一 竖式除法模拟

    N分之一 Description Alice越来越痴迷于数学问题了.一天,爸爸出了个数学题想难倒她,让她求1 / n. 可怜的Alice只有一岁零九个月,回答不上来 ~~~~(>_<)~~ ...

  10. LeetCode 122. Best Time to Buy and Sell Stock II (stock problem)

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...