当前位置:编程学习 > C/C++ >>

hdu 称乒乓球

[cpp]  
Problem Description  
有N只乒乓球,其中有且仅有1只质量有问题,比正常的球要轻一些。给你一驾没有砝码的天平,你最少要多少次才能保证找到有问题的乒乓球?  
Input  
输入包含多组数据  
每组数据输入一个整数N(N<=1000)  
Output  
对于每组数据,输出最少的称量次数  
Sample Input  
  
2  
6  
  
Sample Output  
  
1  
2  
  
#include <iostream>  
#include <stdio.h>  
#include <stdlib.h>  
#include <math.h>  
using namespace std;  
int main()  
{  
    int n, res;  
    while(scanf("%d", &n) == 1) {  
        double temp = (log10(n)*1.0)/log10(3);  
        res = ceil(temp);  
        printf("%d\n", res);  
    }  
    return 0;  
}  
 
补充:软件开发 , C++ ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,