iT邦幫忙

2024 iThome 鐵人賽

DAY 12
0
佛心分享-刷題不只是刷題

CPE C++ 刷題系列 第 12

CPE C++ 刷題 Day 12

  • 分享至 

  • xImage
  •  

今天來解YKL12(UVA10170):The Hotel with Infinite Rooms

The Hotel with Infinite Rooms

https://ithelp.ithome.com.tw/upload/images/20240926/20155574TSShB5smVF.png
https://ithelp.ithome.com.tw/upload/images/20240926/20155574HNNDH3InfQ.png
input:
第一個參數是S
第二個參數是D

output:
第D天的group size S

大概長下圖這樣
https://ithelp.ithome.com.tw/upload/images/20240926/20155574vWv66V3U5j.png

#include <iostream>

using namespace std;

int main(){
    long long S,D;
    while(cin >> S >> D){
        long long curr = 0;
        while(curr < D){
            curr += S;
            if(curr >= D){
                cout << S << endl;
                break;
            }
            S++;
        }
    }
    return 0;
}

上一篇
CPE C++ 刷題 Day 11
下一篇
CPE C++ 刷題 Day 13
系列文
CPE C++ 刷題20
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言