星期二, 十一月 06, 2007

偶的第一个java程序~~~

今天去SGU刷瓜题,结果遇到了一道必须用高精度的题...SGU356,由于用C++写不知道又要写多长...于是,我用起了才学几天的Java。

在网上翻了n久资料,在被误导(居然有个Blog把BigInteger.divide说成是减法...)和Compile Error了
x次之后,我终于过样例了!

可惜的是,SGU又成SGUJOS了...wating了一长串。希望一觉之后,我看到的是一个Accept。

My Program:

import java.io.*;

import java.util.*;

import java.math.BigInteger;


public class Solution

{

____public static void main(String args[])

____{

________Scanner cin=new Scanner(System.in);

________int m=cin.nextInt(),n=cin.nextInt();

________BigInteger A=new BigInteger("0"),B=new BigInteger("1"),V,g;

________for(int i=2;i<=n-m;i++)

____________B=B.multiply(BigInteger.valueOf(i));

________V=B;

________for(int i=2;i<=m;i++)

____________B=B.multiply(BigInteger.valueOf(i));

________for(int i=0;i<=n-m;i++)

________{

____________if(i>0)V=V.divide(BigInteger.valueOf(i));

____________if((i&1)==1)A=A.subtract(V);

____________else A=A.add(V);

________}

________g=A.gcd(B);

________A=A.divide(g);

________B=B.divide(g);

________if(A.compareTo(BigInteger.ZERO)==0)System.out.println("0");

________else System.out.println(A.toString()+"/"+B.toString());

____}

}



5 条评论:

匿名 说...

Ι аm nοw not сeгtain the ρlаce you
аre getting уour informatіοn, but goоd
toріс. I must ѕpend sоmе time stuԁying more or undeгstanding morе.
Thanks for magnіficеnt info I was οn the lοokοut foг thіs іnfοrmatiоn for my missіοn.


my wеbрage; crear facebook gratis

匿名 说...

An іmprеssivе share! I've just forwarded this onto a colleague who had been conducting a little research on this. And he in fact ordered me dinner due to the fact that I discovered it for him... lol. So allow me to reword this.... Thanks for the meal!! But yeah, thanx for spending time to discuss this issue here on your web page.

Visit my blog post :: crear facebook gratis

匿名 说...

At this tіme it appeaгs like Drupal iѕ the preferred
blogging platform out there гight noω. (from what І've read) Is that what you are using on your blog?

my site crear facebook

匿名 说...

Eхcellent beat ! I wish to apрrentice whilst уοu amend
your wеb site, hoω can i subѕсribe fог a weblog ωeb site?
Τhe aсcount aided me a acceptable deal. I have
bееn a little bit acquainted of this your broadcast offereԁ vibrant clear concept

Here is my webpage ... abrir Cuenta facebook

匿名 说...

Attrаctive section of сontent. I јust stumblеd uрon your
ωeb site and іn аccеssiοn caρital to asѕегt
thаt І аcquiге аctuаlly
enjοyed accοunt your blog poѕts.
Αnyway I'll be subscribing to your feeds and even I achievement you access consistently quickly.

My web blog: http://konektados.com/dise%C3%B1o-web/?page_id=13&hl=