hdu catch the thief

本文探讨了在Qingshui村警匪追捕问题中,警察如何在最少天数内抓住藏匿于n个房子之一的贼。通过分析贼的行动规律和警察的检查策略,揭示了在不同房子数量下的最优追捕天数。案例研究包括单一和双房间场景,展示了解决此类问题的逻辑和数学模型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 这道题目前没想法,猜想是奇数和偶数分情况讨论。答案是2*n-4,求大牛指教!!!

Problem Description

In the Qingshui Village, there's a clever thief and a cleverer police.

There are N houses in Qingshui Village which are located in a straight line. And the N houses are numbered from 1 to N according to the direction of the line. Two houses are consided to be neighbor of each other if and only if there is no other house between them.

The thief hides in one of N houses now, and the police tries to find him out. Every day the police will choose a house to check and he will catch the thief if he hides in that house. If the thief survive the arrest of the police, in the night he will move to a neighboring house to pass through the next day.

What is the number of days the police needs to catch the thief in the worst case?
Remember that the police is a clever man.

Input

In the first line, an integer T (T <= 100) indicates the number of cases.
T lines follow. Each contains an integer N described above. (1 <= N <= 10000)


Output

For each test case, output “Case x: d” in which x is the number of test case counted from one, and d is the number of days before the police catch the thief in the worst case.

Sample Input

2
1
2

Sample Output

Case 1: 1
Case 2: 2

Hint

Case 1: There is only one room, so the police can catch the thief on the first day.
Case 2: There are two rooms. The police can check room 1 on the first day. The worst case is that the thief is in room 2, but in this case the police
can check room 1 on the second day and will catch the thief for sure.
 
代码:
#include<iostream>
using namespace std;
int main()
{
    int n,t,caset=0;
    scanf("%d",&t);
    while(t--)
    {
       caset++;
       scanf("%d",&n);
       printf("Case %d: ",caset);
       if(n==1) printf("1%\n");
       else if(n==2) printf("2%\n");
       else printf("%d%\n",2*n-4);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值