2016 年青島網路賽---Tea

来源:http://www.cnblogs.com/chen9510/archive/2016/09/17/5879710.html
-Advertisement-
Play Games

題目鏈接 http://acm.hdu.edu.cn/showproblem.php?pid=5881 Problem Description Tea is good.Tea is life.Tea is everything.The balance of tea is a journey of p ...


題目鏈接

http://acm.hdu.edu.cn/showproblem.php?pid=5881

 

Problem Description Tea is good.

Tea is life.

Tea is everything.

The balance of tea is a journey of pursuing balance of the universe.

Alice knows that. 

Alice wants to teach you the art of pouring tea.

Alice has a pot of tea.

The exact volume of tea is not important.

The exact volume of tea is at least L.

The exact volume of tea is at most R.

Alice put two empty cups between you and her.

Alice wants the two cups filled by almost equal volume of tea.

Yours cannot be 1 unit more than hers.

Hers cannot be 1 unit more than yours.

Alice wants you to pour the tea.

Alice wants you to pour until the pot is almost empty.

Alice wants no more than 1 unit volume of tea remaining in the pot.

You cannot read the residue volume of tea remaining in the pot.

You can only know the tea status in the pot, empty or not.

Alice does not want you to pour the tea too many times.

You better pour as few times as possible.
  Input There are multiple cases.
For each case, there is one line of two integers L and R, separated by single space.

Here are some analyses about sample cases.
For the first case, pouring 1 unit into one cup will satisfy Alice.
For the second case, it is clearly that you cannot only pour once to reach the desired balance, but she can achieve it by pouring twice.
First you pour 1.5 units into one cup, then you attempt to pour another 1.5 units into the other cup.
Since the lower bound is 2, at least 0.5 unit remains in the pot after the first pouring.
If the initial volume is in range [2,3], the second cup will have volume in range [0.5,1.5] which is balanced with 1.5 unit in the first cup, and at most 1 unit remain after these two attempts.

About 1000 test cases, and 0LR1016.
  Output For each case, there should be a single integer in a single line, the least number of pouring attempts.   Sample Input 2 2 2 4   Sample Output 1 2   Source 2016 ACM/ICPC Asia Regional Qingdao Online  

 

Recommend wange2014   |   We have carefully selected several similar problems for you:  5891 5890 5889 5887 5886    題意:輸入L,R 表示一壺茶的茶的體積的範圍L~R,不確定精確量(整數), 現在往兩個茶杯中倒茶(不考慮茶杯容量) ,要求使兩個茶杯中茶相差不超過1 ,而茶壺中剩餘的茶不能超過1, 求最少倒茶的次數;         樣例解釋一下:2 2 答案是1 ,我們可以往第一個茶杯中倒1 ,第二杯不倒, 那麼兩個茶杯相差為1 ,茶壺剩餘量為0~1 , 符合題目要求; 2 4 答案是2 ,我們可以往第一杯倒入1.5  那麼第二杯按1.5 到,如果茶壺 茶量為2,那麼第二杯倒入0.5 兩倍相差1 茶壺為0 符合題目要求,如果茶壺 茶量為4, 第二杯倒入1.5 兩杯量相同, 茶壺剩餘1, 符合題目要求;   思路: 先考慮普通情況,第一杯倒入(L+1)/2, 第二杯按照(L+1)/2+1倒, 那麼如果茶壺量為L<=茶壺<=L+2 ,則茶壺為0 了,兩杯茶相差0~1 ;如果情況糟糕茶壺不空,那麼接下來往第一杯中倒入2 ,第二杯中倒入2 ,第一杯中倒入2 ......知道茶壺不足2 (即茶壺剩餘量為0或者1) ,這樣兩杯茶始終相差1,符合題意;   代碼如下:
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <queue>
#include <cmath>
#include <string.h>
using namespace std;

int main()
{
    long long L,R;
    while(scanf("%lld%lld",&L,&R)!=EOF)
    {
        if(L==R)
        {
            if(R<=1) puts("0");
            else if(R==2) puts("1");
            else puts("2");
            continue;
        }
        if(L==0)
        {
            if(R==1) puts("0");
            else if(R==2) puts("1");
            else printf("%lld\n",(R+1)/2);
        }
        else
        {
            if(L==1&&R==2)  puts("1");
            else{
            if(L+2>=R-1) puts("2");
            else printf("%lld\n",(R-L+2)/2);
            }
        }
    }
    return 0;
}

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 類的基本成員才有預設值 finalize()並非析構,Java中沒有析構,使用finalize()通常在於跨語言調用情景:比如使用C進行malloc記憶體分配以後,要在finalize()方法中進行free,以便於提供一種記憶體釋放的方法,否則當量達到一定程度時會造成out of memories。Jv ...
  • 介紹一個生成動態鏈接庫*.so的例子: 首先新建1個頭文件test.h: 然後新建3個源文件first.c/second.c/third.c: first.c: second.c: third.c: 然後,生成動態鏈接庫libtest.so: gcc first.c second.c third.c ...
  • 編譯環境:windows 7 64位 編譯工具:codeblocks 13.12 備註:未使用graphics.h 聲明:個人原創,未經允許,禁止轉載!!! 數據結構:雙向鏈表 1.程式未使用graphis.h中的 函數,所以採用先清屏,再列印的方式顯示圖形,大約每秒刷新一次; 2.除蛇頭元素外,其 ...
  • 在EL表達式中,假設某個entity的status屬性為char類型,此處假設為'1',在jsp中,對於${entity.status=='1'},我們預期的結果是true,但實際上是false - -! why?是這樣的,EL表達式比較偷懶,把char類型數據做了自動轉型,所以上面的EL換一種寫法 ...
  • 建議52:推薦使用String直接量賦值 一般對象都是通過new關鍵字生成的,但是String還有第二種生成方式,也就是我們經常使用的直接聲明方式,這種方式是極力推薦的,但不建議使用new String("A")的方式賦值。為什麼呢?我們看如下代碼: 註意看上面的程式,我們使用"=="判斷的是兩個對 ...
  • 1.如何獲取某個方法 方法的名稱和方法的參數列表才能唯一決定一個方法 2.方法反射的操作 method.invoke(); 如果方法是private的會報這個錯誤 java.lang.IllegalAccessException ...
  • carbaugh/lice "lice" : Generate license files for your projects 一個用來為你的項目生成許可證的工具。這下可方便了,不用手工的去修改了! coleifer/peewee "peewee" : a small, expressive orm ...
  • 一、首先先在碼雲上新建一個項目 二、複製項目的鏈接 三、打開SmartGit,點擊clone 4、把複製的項目鏈接粘上去 5、然後點兩次next,選擇一個路徑,finish 6、打開剛剛選擇的路徑,我們能看到: 7、現在我們要把我們自己的maven項目粘進去 8、做完之後,我們能夠看到SmartGi ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...