几道java题

hdu1002 java

import java.math.BigInteger;
import java.util.Scanner;

public class Main{
    public static void main(String [] arguments){
        Scanner in=new Scanner(System.in);
        int T;
        T=in.nextInt();
        for(int i=1;i<=T;++i){
            if(i>1) System.out.println();
            System.out.println("Case "+i+":");
            BigInteger a,b;
            a=in.nextBigInteger();
            b=in.nextBigInteger();
            System.out.println(a + " + " + b + " = " + a.add(b));
        }
    }
}
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

hdu 1042 java

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

public class Main{
    public static void main(String [] arguments){
        Scanner S = new Scanner(System.in);
        while(S.hasNextInt()){
            int N=S.nextInt();
            BigInteger ans=BigInteger.ONE;
            for(int i=1;i<=N;i++){
                ans = ans.multiply(BigInteger.valueOf(i));
            }
            System.out.println(ans);
        }
    }
}
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

hdu1047 java

import java.util.*;
import java.util.Scanner;
import java.math.BigInteger;

public class Main{

    public static void main(String [] arguments){
        Scanner cin = new Scanner(System.in);
        int T=cin.nextInt();
        for(int i=1;i<=T;i++){
            BigInteger ans = BigInteger.ZERO;
            BigInteger x = cin.nextBigInteger();
            BigInteger Zero = BigInteger.ZERO;
            while(!x.equals(Zero)){
                ans = ans.add(x);
                x = cin.nextBigInteger();
            }
            System.out.println(ans);
            if(i<T) System.out.println();
        }
    }
}

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

hdu1250 java

import java.util.Scanner;
import java.math.BigInteger;

public class Main{

    public static void main(String [] arguements){
        Scanner cin = new Scanner(System.in);
        BigInteger[]f=new BigInteger[10086];
        f[0]=BigInteger.ONE;
        f[1]=BigInteger.ONE;
        f[2]=BigInteger.ONE;
        f[3]=BigInteger.ONE;
        for(int i=4;i<=10006;i++){
            f[i]=f[i-1].add(f[i-2]).add(f[i-3]).add(f[i-4]);
        }
        while(cin.hasNext()){
            int N = cin.nextInt();
            System.out.println(f[N-1]);
        }
    }
}
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

蓝桥杯 矩阵翻硬币

n*m的矩阵,按规则翻转,求一开始的正面朝上的个数。
首先,如果一枚硬币被翻了奇数次,那么它原来的状态肯定是反面朝上,所以,我们要找的就是被翻了奇数次的硬币。
求哪些数的约束个数有奇数个,完全平方数啊。
那么,ans = (int)sqrt( n ) * (int)sqrt(m) 容易得出。

link
对比一下,高下立判。

import java.util.Scanner;
import java.math.BigInteger;

public class Main{

    public static void main(String [] arguments){
        Scanner cin = new Scanner(System.in);
        BigInteger n = cin.nextBigInteger();
        BigInteger m = cin.nextBigInteger();
        BigInteger l = BigInteger.ONE;
        BigInteger r = n,N=BigInteger.ONE,M=BigInteger.ONE;
        while(l.compareTo(r)<=0 ){
            BigInteger mid = l.add(r).divide(BigInteger.valueOf(2));
            if( mid.multiply(mid).compareTo(n)<=0 ){
                l = mid.add(BigInteger.valueOf(1));
                N = mid;
            }
            else r = mid.add(BigInteger.valueOf(-1));
        }
        l = BigInteger.ONE;
        r = m;
        while(l.compareTo(r)<=0 ){
            BigInteger mid = l.add(r).divide(BigInteger.valueOf(2));
            if( mid.multiply(mid).compareTo(m)<=0 ){
                l = mid.add(BigInteger.valueOf(1));
                M = mid;
            }
            else r = mid.add(BigInteger.valueOf(-1));
        }
        System.out.println(N.multiply(M));
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值