标签:
http://acm.nyist.net/JudgeOnline/problem.php?pid=773
1 import java.util.Scanner; 2 3 public class Main{ 4 public static void main(String[] args){ 5 int n; 6 double p; 7 Scanner cin = new Scanner(System.in); 8 while(true){ 9 n = cin.nextInt(); 10 p = cin.nextDouble(); 11 if(n == 0 && p == 0) break; 12 System.out.printf("%.0f\n", Math.pow(p, 1.0/n)); 13 } 14 } 15 }
POJ 1001 Exponentiation
http://poj.org/problem?id=1001
1 import java.io.*; 2 import java.math.*; 3 import java.util.*; 4 import java.text.*; 5 6 public class Main 7 { 8 public static void main(String[] args) 9 { 10 Scanner cin = new Scanner(System.in); 11 while(cin.hasNext()) 12 { 13 BigDecimal R = cin.nextBigDecimal(); 14 int n = cin.nextInt(); 15 String ans = R.pow(n).stripTrailingZeros().toPlainString(); 16 if(ans.startsWith("0")) 17 ans = ans.substring(1); 18 System.out.println(ans); 19 } 20 } 21 }
HDU 1042 N!
http://acm.hdu.edu.cn/showproblem.php?pid=1042
java版:
1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10 9 11 10 12 11 13 12 14 13 15 14 16 15 17 16 18 17 import java.util.Scanner; 18 import java.math.BigInteger; 19 public class Main{ 20 public static void main(String[] args){ 21 Scanner input = new Scanner(System.in); 22 int A, i; 23 while(input.hasNext()) 24 { 25 A = input.nextInt(); 26 BigInteger B = BigInteger.ONE; 27 for(i=1; i<=A; i++) 28 { 29 B = B.multiply(BigInteger.valueOf(i)); 30 } 31 System.out.println(B); 32 } 33 } 34 }
C++版:
1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10 9 11 10 12 11 13 12 14 13 15 14 16 15 17 16 18 17 19 18 20 19 21 20 22 21 23 22 24 23 25 24 26 25 27 26 28 27 29 28 30 29 31 30 32 31 33 32 34 33 35 34 36 35 37 36 38 37 39 38 40 39 41 40 42 41 43 42 44 43 45 44 46 45 47 46 48 47 49 48 #include<iostream> 49 #include<string.h> 50 #include<stdio.h> 51 #include<ctype.h> 52 #include<algorithm> 53 #include<stack> 54 #include<queue> 55 #include<set> 56 #include<map> 57 #include<math.h> 58 #include<vector> 59 #include<deque> 60 #include<list> 61 #define INF 0x7fffffff 62 #define inf 0x3f3f3f3f 63 #define maxn 40000 64 using namespace std; 65 int a[maxn]; 66 int main() 67 { 68 int n; 69 int s; 70 while(scanf("%d",&n)!=EOF) 71 { 72 memset(a,0,sizeof(a)); 73 a[0]=1; 74 for(int i=2; i<=n; i++) 75 { 76 int c=0; 77 for(int j=0; j<maxn; j++) 78 { 79 s=a[j]*i+c; 80 a[j]=s%10; 81 c=s/10; 82 } 83 } 84 int p; 85 for(int i=maxn; i>=0; i--) 86 if(a[i]) 87 { 88 p=i; 89 break; 90 } 91 for(int i=p; i>=0; i--) 92 printf("%d",a[i]); 93 printf("\n"); 94 } 95 return 0; 96 }
FZOJ 1602 Best results
http://acm.fzu.edu.cn/problem.php?pid=1602
1 import java.io.*; 2 import java.math.*; 3 import java.util.*; 4 import java.text.*; 5 6 public class Main 7 { 8 public static void main(String[] args) 9 { 10 Scanner cin = new Scanner(System.in); 11 while(cin.hasNext()) 12 { 13 int t = cin.nextInt(); 14 BigDecimal ans = BigDecimal.ONE; 15 while(t-- > 0) 16 { 17 String str = cin.next(); 18 int l = str.length(); 19 str = str.substring(0, l - 1); 20 int tep = Integer.parseInt(str); 21 BigDecimal Tep = BigDecimal.valueOf(tep); 22 Tep = Tep.divide(BigDecimal.valueOf(100)); 23 ans = ans.multiply(Tep); 24 } 25 System.out.println(ans.stripTrailingZeros().toPlainString()); 26 } 27 } 28 }
标签:
原文地址:http://www.cnblogs.com/qiucz/p/4396848.html