24h購物| | PChome| 登入
2012-09-26 08:24:15| 人氣7,218| 回應1 | 上一篇 | 下一篇

[UVA] 10170 - The Hotel with Infinite Rooms

推薦 0 收藏 0 轉貼0 訂閱站台

Problem C

The Hotel with Infinite Rooms

Input: standard input

Output: standard output

Time Limit: 2 seconds

 

The city of HaluaRuti has a strange hotel with infinite rooms. The groups that come to this hotel follow the following rules:

 

a)      At the same time only members of one group can rent the hotel.

 

b)      Each group comes in the morning of the check-in day and leaves the hotel in the evening of the check-out day.

 

c)      Another group comes in the very next morning after the previous group has left the hotel.

 

d)      A very important property of the incoming group is that it has one more member than its previous group unless it is the starting group. You will be given the no of members of the starting group.

 

e)      A group with n members stays for n days in the hotel. For example, if a group of four members comes on 1st August in the morning, it will leave the hotel on 4th August in the evening and the next group of five members will come on 5th August in the morning and stay for five days and so on.

 

Given the initial group size you will have to find the group size staying in the hotel on a specified day.

 

Input

The input contains round numbers S(1<=S<=10000) and D(1<=D<10^15) in every line. S denotes the initial size of the group and D denotes that you will have to find the group size staying in the hotel on D th day (starting from 1). All the input and output integers will be less than 10^15. A group size S means that on the first day a group of S members come to the hotel and stays for S days then comes a group of S+1 members according to the previously described rules and so on.

 

Output

 For each line of input, print on a single line the size of the group staying in the hotel on the D th day.

 

Sample Input:

1 6
3 10
3 14

 

Sample Output:

3
5
6

這一題理解題目就不難了, 給一開始的團隊人數n, 然後每個團隊占據n天, 請問第 D 天, 是哪個團隊


#include <stdio.h>

int main() {
    long long s, d;
    while(scanf("%lld %lld", &s, &d) == 2) {
        long long i = s, sum = 0;
        while(1) {
            sum += i;
            if(sum >= d) {
                printf("%lld\n", i);
                break;
            }
            i++;
        }
    }
    return 0;
}


台長: Morris
人氣(7,218) | 回應(1)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 10050 - Hartals
此分類上一篇:[UVA] 11713 - Abstract Names

口袋蔥餅
請問這題有辦法用等差級數和來求解嗎?
Sn = (2a1 + (n-1)d)n / 2 >= Dday
(d = 1)
導出一元二次方程式,再利用公式解
但因為式子是不等式,所以我求不出來。
2016-05-29 12:05:25
是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文