1057: Counterfeit Currency
Time limit (Common/Java): 1000 MS/10000 MS Running memory limit: 65536 KByte
Total submissions: 2844 Tested: 773
Description
There are counterfeit coins !!!
This is the case. Now, pork has risen, but the wages of farmers have not risen. How can I buy pork if I have no money. Yuan Zi went here to buy pork. As a result, there were counterfeit coins in the change !!! Unfortunately, yuanzi accidentally mixed it into a pile of real coins. We now know that counterfeit coins are lighter than real coins. Give you a balance. Please use the fastest time to find out the hateful counterfeit currency.
Input
1 ≤ n ≤ 230, input 0 to end the program.
Output
The counterfeit currency can be found at least several times.
Sample Input
3
12
0
Sample output
1
3
Prompt
In example 1, there are three coins in total, so take any two coins and weigh them on the balance.
Because the counterfeit currency is light in weight.
- If the balance is not balanced, the lighter one is the counterfeit currency.
- If the balance is balanced, the two coins are true, and the remaining one is a counterfeit coin.
The optimal features of the problem are divided into three heaps.
#include <stdio.h><math.h> f(( == ( == ( == (x == (pow(, ()( log (x) / log ( (log (x) / log ( ( + ()(log (x) / log (
#include <stdio.h>(scanf(, &n), n != count = (n != ( == ( ==+= ( ==+= (n % ) : n /= ; : n = (n + ) / ; : n = (n + ) / ;++
Add a function
Function Name: ceil
Usage: double ceil (double x );
Function: returns the smallest integer greater than or equal to the specified expression.
Header file: math. h
Chinese name
Ceil
UseMethod
Double ceil
MeritYes
Returns the smallest integer greater than or equal to the expression.
Header file
Math. h
Simplification of the first solution
#include<stdio.h><math.h> (scanf(,&n),n != ,ceil(log(n)/log())); }