Page 2 of 2

10375

Posted: Tue Oct 04, 2005 5:51 pm
by vardiar
wht is wrong about this code to GET 25 WA????
//10375
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;
void main()
{
long long m1,n1,m2,n2;
while(cin>>m1>>n1>>m2>>n2)
{
long long c1=m1-n1;
long long c2=m2-n2;
vector<long long>s;
vector<long long>m;
s.push_back(m1);
s.push_back(c2);
s.push_back(n2);
m.push_back(m2);
m.push_back(c1);
m.push_back(n1);
sort(s.begin(),s.end());
sort(m.begin(),m.end());
long long sj[3];
sj[0]=s[0];
sj[1]=s[1];
sj[2]=s[2];
long long mj[3];
mj[0]=m[0];
mj[1]=m[1];
mj[2]=m[2];
vector<long double> so;
for(long long i=s[0];i>m[0];i--)
{
so.push_back(i);
}
for(long long i=s[1];i>m[1];i--)
{
so.push_back(i);
}
for(long long i=s[2];i>m[2];i--)
{
so.push_back(i);
}
vector<long double> ma;
for(long long i=m[0];i>s[0];i--)
{
ma.push_back(i);
}
for(long long i=m[1];i>s[1];i--)
{
ma.push_back(i);
}
for(long long i=m[2];i>s[2];i--)
{
ma.push_back(i);
}
long double sorat=1;
int v=0;
for(int i=0;i<so.size();i++)
{
sorat*=so;
if(sorat>ma[v] && v<ma.size())
{
sorat/=ma[v];
v++;
}
}
for(int i=v;i<ma.size();i++)
{
sorat/=ma;
}
printf("%.5lf\n",sorat);
}
}

Log is possible

Posted: Mon Mar 10, 2008 12:18 am
by mpi
This problem can be solved using log and long double

Re: 10375 - Choose and Divide

Posted: Wed Jan 07, 2009 7:01 am
by stcheung
If you are using Java and keep getting WA, you might want to try using C/C++. At first I converted the program in the 1st thread into a Java program. I also took the suggestion in the 2nd thread and converted the 6 loops into a single loop. However that got me WA whether I use Math.log10 or Math.log. Then I tried implementing the exact same thing in C++ and got AC.

Re: 10375 - Choose and Divide

Posted: Fri May 28, 2010 4:38 pm
by tkcn
stcheung wrote:If you are using Java and keep getting WA, you might want to try using C/C++. At first I converted the program in the 1st thread into a Java program. I also took the suggestion in the 2nd thread and converted the 6 loops into a single loop. However that got me WA whether I use Math.log10 or Math.log. Then I tried implementing the exact same thing in C++ and got AC.
Hello.
I was trying to solving this problem using Java.
It's just like stcheung said, I jsut got WA.
Finally I try to using BigDecimal and got AC.

Re: 10375 - Choose and Divide

Posted: Thu Jul 14, 2011 7:32 pm
by plamplam
First of all, you can't get AC with double. You must use long double to get Accepted and remember you can't use log or ln for this problem as this would cause precision error. (May be it is possible to solve this using log or ln by adding/subtracting or looping less, but I wouldn't recommend using it).
Some test cases in case you get stuck:

Code: Select all

9999 5000 9999 5256
1271 18 1922 18
156 45 156 46
5600 2800 5595 2795
9191 19 9189 19
9876 1234 9899 1222

Code: Select all

521350.34067
0.00056
0.41441
32.05724
1.00415
713086555.90808
Cheers :)

Re: 10375 - Choose and Divide

Posted: Wed Sep 03, 2014 10:08 am
by AbyssalGreed

Code: Select all

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

class Main
{
	public static void main(String args[])throws Exception
	{
		Scanner sc = new Scanner(new File("input.txt"));
		DecimalFormat df = new DecimalFormat("0.00000");
		while(sc.hasNext())
		{
			
			long num1 = sc.nextLong();
			long num2 = sc.nextLong();
			long num3 = sc.nextLong();
			long num4 = sc.nextLong();
			
			BigDecimal fact1 = new BigDecimal("1");
			for(int a=1; a<=num1; a++)
			{
				fact1 = fact1.multiply(BigDecimal.valueOf(a));
			}
		
			BigDecimal fact2 = new BigDecimal("1");
			for(int a=1; a<=num2; a++)
			{
				fact2 = fact2.multiply(BigDecimal.valueOf(a));
			}
		
			BigDecimal fact3 = new BigDecimal("1");
			for(int a=1; a<=num3; a++)
			{
				fact3 = fact3.multiply(BigDecimal.valueOf(a));
			}
		
			BigDecimal fact4 = new BigDecimal("1");
			for(int a=1; a<=num4; a++)
			{
				fact4 = fact4.multiply(BigDecimal.valueOf(a));
			}
			
			long difnum1num2 = num1-num2;
			BigDecimal difnum1 = new BigDecimal("1");
			for(int a=1; a<=difnum1num2; a++)
			{
				difnum1 = difnum1.multiply(BigDecimal.valueOf(a));
			}
			
			long difnum3num4 = num3-num4;
			BigDecimal difnum2 = new BigDecimal("1");
			for(int a=1; a<=difnum3num4; a++)
			{
				difnum2 = difnum2.multiply(BigDecimal.valueOf(a));
			}
			
			BigDecimal num = factor1(fact1,fact2,difnum1);
			BigDecimal den = factor2(fact3,fact4,difnum2);
			BigDecimal qou = num.divide(den, 20, RoundingMode.CEILING);
			if(qou.compareTo(BigDecimal.valueOf(0.00000000000000000001))==0)
				System.out.println(df.format(qou));
			else
				System.out.println(String.format("%.5f",qou));
		
		}	
	}	
	
	static BigDecimal factor1(BigDecimal fact1, BigDecimal fact2, BigDecimal difnum1)
	{
		BigDecimal _fact1 = new BigDecimal("1");
		_fact1 = fact1.divide(fact2.multiply(difnum1), 10, RoundingMode.CEILING);
		return _fact1;
		
	}
	static BigDecimal factor2(BigDecimal fact3, BigDecimal fact4, BigDecimal difnum2)
	{
		BigDecimal _fact2 = new BigDecimal("1");
		_fact2 = fact3.divide(fact4.multiply(difnum2), 10, RoundingMode.CEILING);
		return _fact2;
	}	
}

here's my code.. and i don't know this is TLE.. I tried to compile and runs in 1.120 sec, but submitting it in UVA OJ gives me TLE..
can anybody help??

thanks in advance!!

Re: 10375 - Choose and Divide

Posted: Wed Sep 03, 2014 6:59 pm
by brianfry713
Don't read from a file.

Re: 10375 - Choose and Divide

Posted: Thu Sep 04, 2014 1:45 am
by AbyssalGreed
I've change it to System.in before submiiting.. it's still TLE.. hehe!! oopss! sorry if I forgot to change that in my code!!! my faullt!

Re: 10375 - Choose and Divide

Posted: Thu Sep 04, 2014 7:31 pm
by brianfry713
Next time post the code you'd actually submit.
Try using BufferedReader and BufferedWriter.