码迷,mamicode.com
首页 > 编程语言 > 详细

ACdream训练赛系列のJava专场

时间:2015-05-20 12:39:46      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:

 

 

/*
* this code is made by mhy12345
* Problem: 1669
* Verdict: Accepted
* Submission Date: 2015-04-21 13:39:02
* Time: 140MS
* Memory: 23196KB
*/
import java.util.*;
import java.math.*;
 
public class Main
{
        static public void main(String args[])
        {
                Scanner in=new Scanner(System.in);
                while (in.hasNext())
                {
                        BigInteger n=in.nextBigInteger();
                        BigInteger l,r,mid;
                        l=new BigInteger("0");
                        r=n.add(BigInteger.valueOf(1));
                        while (r.subtract(l).compareTo(BigInteger.valueOf(1))>0)
                        {
                                //  System.out.println(l);
                                //  System.out.println(r);
                                mid=(r.add(l)).divide(BigInteger.valueOf(2));
                                if (mid.multiply(mid).compareTo(n)>0)
                                {
                                        r=mid;
                                }else
                                {
                                        l=mid;
                                }
                        }
                        System.out.println(l.remainder(BigInteger.valueOf(2)));
                }
        }
}

 

B

/*
* this code is made by mhy12345
* Problem: 1670
* Verdict: Accepted
* Submission Date: 2015-04-21 15:01:14
* Time: 172MS
* Memory: 27336KB
*/
import java.util.*;
import java.math.*;
import java.io.File;
import java.io.IOException;
 
public class Main
{
        static public void main(String args[])throws IOException
        {
                Scanner in = new Scanner(System.in);
                //Scanner in = new Scanner(new File("input.txt"));
                while (in.hasNext())
                {
                        BigInteger n=in.nextBigInteger();
                        BigInteger x=new BigInteger("1");
                        for (int i=2;i<=10000000;i++)
                        {
                                boolean flag=true;
                                for (int j=2;j<i;j++)
                                {
                                        if (i%j==0)
                                        {
                                                flag=false;
                                                break;
                                        }
                                }
                                if (!flag)continue;
                                if (x.multiply(BigInteger.valueOf(i)).compareTo(n)>0)
                                        break;
                                x=x.multiply(BigInteger.valueOf(i));
                        }
                        System.out.println(x.toString());
                }
      

 

C

/*
* this code is made by mhy12345
* Problem: 1668
* Verdict: Accepted
* Submission Date: 2015-04-21 17:43:49
* Time: 992MS
* Memory: 152756KB
*/
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main
{
        static public void main(String args[])throws IOException
        {
                Scanner in = new Scanner(System.in);
                int n;
                while (in.hasNext())
                {
                        n=in.nextInt();
                        int a1,b1,a2,b2,a3,b3;
                        a1=in.nextInt();
                        b1=in.nextInt();
                        a2=in.nextInt();
                        b2=in.nextInt();
                        a3=in.nextInt();
                        b3=in.nextInt();
                        BigDecimal v1=BigDecimal.valueOf(a1).divide(BigDecimal.valueOf(b1),100,BigDecimal.ROUND_HALF_EVEN);
                        BigDecimal v2=BigDecimal.valueOf(a2).divide(BigDecimal.valueOf(b2),100,BigDecimal.ROUND_HALF_EVEN);
                        BigDecimal v3=BigDecimal.valueOf(a3).divide(BigDecimal.valueOf(b3),100,BigDecimal.ROUND_HALF_EVEN);
                        BigDecimal dp[][]=new BigDecimal[110][];
                        for (int i=0;i<110;i++)
                                dp[i]=new BigDecimal[110];
                        for (int i=0;i<110;i++)
                                for (int j=0;j<110;j++)
                                        dp[i][j]=new BigDecimal("0");
                        BigDecimal poss[][]=new BigDecimal[110][];
                        for (int i=0;i<110;i++)
                                poss[i]=new BigDecimal[110];
                        for (int i=0;i<110;i++)
                                for (int j=0;j<110;j++)
                                        poss[i][j]=new BigDecimal("0");
                        dp[n][n]=BigDecimal.ZERO;
                        poss[n][n]=BigDecimal.ONE;
                        BigDecimal va=v1.add(v3.divide(BigDecimal.valueOf(2),100,BigDecimal.ROUND_HALF_EVEN));
                        BigDecimal vb=v2.add(v3.divide(BigDecimal.valueOf(2),100,BigDecimal.ROUND_HALF_EVEN));
                        for (int i=n;i>=1;i--)
                        {
                                for (int j=n;j>=i;j--)
                                {
                                        if (j!=i && i!=1)
                                        {
                                                poss[i-1][j]=poss[i-1][j].add(poss[i][j].multiply(v2));
                                                dp[i-1][j]=dp[i-1][j].add(dp[i][j].add(poss[i][j]).multiply(v2));
                                                poss[i][j-1]=poss[i][j-1].add(poss[i][j].multiply(v3));
                                                dp[i][j-1]=dp[i][j-1].add(dp[i][j].add(poss[i][j]).multiply(v3));
                                                poss[i-1][j-1]=poss[i-1][j-1].add(poss[i][j].multiply(v1));
                                                dp[i-1][j-1]=dp[i-1][j-1].add(dp[i][j].add(poss[i][j]).multiply(v1));
                                                //System.out.println(poss[i][j-1] +" "+ poss[i][j]);
                                        }else if (i==1 && j!=i)
                                        {
                                                poss[i][j-1]=poss[i][j-1].add(poss[i][j]);
                                                dp[i][j-1]=dp[i][j-1].add(dp[i][j].add(poss[i][j]));
                                        }else if (j==i && i!=1)
                                        {
                                                poss[i-1][j-1]=poss[i-1][j-1].add(poss[i][j].multiply(va));
                                                dp[i-1][j-1]=dp[i-1][j-1].add((dp[i][j].add(poss[i][j])).multiply(va));
                                                poss[i-1][j]=poss[i-1][j].add(poss[i][j].multiply(vb));
                                                dp[i-1][j]=dp[i-1][j].add((dp[i][j].add(poss[i][j])).multiply(vb));
                                        }
                                }
                        }
                        /*
                        for (int i=1;i<=n;i++)
                        {
                                for (int j=1;j<=n;j++)
                                {
                                        System.out.print(dp[i][j]+" ");
                                }
                                System.out.println();
                        }
                        */
                    //  System.out.println(dp[1][1]);
                        System.out.println(dp[1][1].setScale(50, BigDecimal.ROUND_HALF_EVEN).toString());
                        /*
                        double vv1,vv2,vv3;
                        vv1=(double)a1/b1;
                        vv2=(double)a2/b2;
                        vv3=(double)a3/b3;
                        double dp[][]=new double[110][];
                        for (int i=0;i<110;i++)
                                dp[i]=new double[110];
                        double poss[][]=new double[110][];
                        for (int i=0;i<110;i++)
                                poss[i]=new double[110];
                        dp[n][n]=0;
                        poss[n][n]=1;
                        for (int i=n;i>=1;i--)
                        {
                                for (int j=n;j>=i;j--)
                                {
                                        if (j!=i && i!=1)
                                        {
                                                //System.out.println("hehe"+i+" "+j);
                                                poss[i-1][j]+=poss[i][j]*vv2;
                                                dp[i-1][j]+=(dp[i][j]+poss[i][j])*vv2;
                                                poss[i][j-1]+=poss[i][j]*vv3;
                                                dp[i][j-1]+=(dp[i][j]+poss[i][j])*vv3;
                                                poss[i-1][j-1]+=poss[i][j]*vv1;
                                                dp[i-1][j-1]+=(dp[i][j]+poss[i][j])*vv1;
                                                //System.out.println(poss[i][j-1] +" "+ poss[i][j]);
                                        }else if (i==1 && j!=i)
                                        {
                                                poss[i][j-1]+=poss[i][j];
                                                dp[i][j-1]+=dp[i][j]+poss[i][j];
                                        }else if (j==i && i!=1)
                                        {
                                                poss[i-1][j-1]+=poss[i][j]*(vv1+vv3/2);
                                                dp[i-1][j-1]+=(dp[i][j]+poss[i][j])*(vv1+vv3/2);
                                                poss[i-1][j]+=poss[i][j]*(vv2+vv3/2);
                                                dp[i-1][j]+=(dp[i][j]+poss[i][j])*(vv2+vv3/2);
                                        }
                                }
                        }
                        for (int i=1;i<=n;i++)
                        {
                                for (int j=1;j<=n;j++)
                                {
                                        System.out.print(poss[i][j]+" ");
                                }
                                System.out.println();
                        }
                        System.out.println(dp[1][1]);
                        //System.out.println(poss[1][1]);
                        */
                }
        }
};

 

剩下两道题简直有意思。。。。。不写了。

ACdream训练赛系列のJava专场

标签:

原文地址:http://www.cnblogs.com/mhy12345/p/4516617.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!