2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem J. Joke 水题

Problem J. Joke

题目连接:

http://codeforces.com/gym/100714

Description

The problem is to cut the largest possible number of circles with diameter y out of a stripe of length x
and width y.

Input

The only line of input consists of two positive real numbers x and y with 9-digit precision separated by
spaces. The integers may be written without decimal point.

Output

Output a single integer — the maximum number of circles one can cut out of the stripe.

Sample Input

6.3 0.9

Sample Output

7

Hint

题意

给你两个数,问你A/B是多少,保证小数点后9为小数以内。

题解:

乘以1e9,然后再除就好了

代码

import java.io.*;
import java.math.*;
import java.util.*;

public class Main
{
    public static void main(String argv[]) throws Exception
    {
    	Scanner cin = new Scanner(System.in);
    	String x = cin.next() , y = cin.next();
    	{
    		int find = 0;
    		for(int i = 0 ; i < x.length() ; ++ i) if( x.charAt(i) =='.' ) find = 1;
    		if( find == 0 ) x += '.';
    	}
    	{
    		int find = 0;
    		for(int i = 0 ; i < y.length() ; ++ i) if( y.charAt(i) =='.' ) find = 1;
    		if( find == 0 ) y += '.';
    	}
    	int m1 = 0 , m2 = 0;
    	{
    		int find = 0;
    		for(int i = 0 ; i < x.length() ; ++ i){
    			if( x.charAt(i) == '.' )  find = 1;
    			else if( find == 1 )  ++ m1;
    		}
    	}
    	{
    		int find = 0;
    		for(int i = 0 ; i < y.length() ; ++ i){
    			if( y.charAt(i) == '.' )  find = 1;
    			else if( find == 1 )  ++ m2;
    		}
    	}
    	int ms = Math.max( m1 , m2 );
    	for(int i = m1 ; i < ms ; ++ i) x+='0';
    	for(int i = m2 ; i < ms ; ++ i) y+='0';
    	BigInteger A = BigInteger.ZERO , B = BigInteger.ZERO;
	    for(int i = 0 ; i < x.length() ; ++ i){
	    	if( x.charAt(i) != '.' ){
	    		int add = x.charAt(i) - '0';
	    		A = A.multiply( BigInteger.valueOf(10) );
	    		A = A.add( BigInteger.valueOf(add) );
	    	}
	    }  
	    for(int i = 0 ; i < y.length() ; ++ i){
	    	if( y.charAt(i) != '.' ){
	    		int add = y.charAt(i) - '0';
	    		B = B.multiply( BigInteger.valueOf(10) );
	    		B = B.add( BigInteger.valueOf(add) );
	    	}
	    }
	    System.out.println( A.divide(B) );
    }
}
原文地址:https://www.cnblogs.com/qscqesze/p/5752305.html