首页 > ACM题库 > HDU-杭电 > HDU 3469-Catching the Thief[解题报告]HOJ
2014
03-30

HDU 3469-Catching the Thief[解题报告]HOJ

Catching the Thief

问题描述 :

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.

输入:

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)

输出:

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)

样例输入:

2
1
2

样例输出:

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<cstdio>
int main()
{
	int t,cas=1,n;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		if(n!=1&&n!=2)
			n=n*2-4;
		printf("Case %d: %d\n",cas++,n);
	}
	return 0;
}

  1. #include <stdio.h>
    int main()
    {
    int n,p,t[100]={1};
    for(int i=1;i<100;i++)
    t =i;
    while(scanf("%d",&n)&&n!=0){
    if(n==1)
    printf("Printing order for 1 pages:nSheet 1, front: Blank, 1n");
    else {
    if(n%4) p=n/4+1;
    else p=n/4;
    int q=4*p;
    printf("Printing order for %d pages:n",n);
    for(int i=0;i<p;i++){
    printf("Sheet %d, front: ",i+1);
    if(q>n) {printf("Blank, %dn",t[2*i+1]);}
    else {printf("%d, %dn",q,t[2*i+1]);}
    q–;//打印表前
    printf("Sheet %d, back : ",i+1);
    if(q>n) {printf("%d, Blankn",t[2*i+2]);}
    else {printf("%d, %dn",t[2*i+2],q);}
    q–;//打印表后
    }
    }
    }
    return 0;
    }