Author Archives: toad, die

Poj Solution 3752

http://poj.org/problem?id=3752 import java.io.BufferedInputStream; import java.util.Scanner; /** * *poj3752 * ģ�� * @author NC */ public class Main { public static void main(String[] args) { Scanner scan = new Scanner(new BufferedInputStream(System.in)); if (scan.hasNext()) { int m = scan.nextInt(); int n = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3751

http://poj.org/problem?id=3751 import java.io.BufferedInputStream; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Locale; import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * poj3751 easy * … Continue reading

Posted in poj | Leave a comment

Poj Solution 3750

http://poj.org/problem?id=3750 #include <stdio.h> #include <string.h> int main() { int n, w, s; int i, j; char name[65][16]; scanf("%d", &n); getchar(); for (i=0; i<n; ++i) { gets(name[i]); } scanf("%d,%d", &w, &s); i = w-1; while (n != 0) { if (i+s-1 … Continue reading

Posted in poj | Leave a comment

Poj Solution 3749

http://poj.org/problem?id=3749 #include<stdio.h> #include<string.h> int main() { void translate(char word[]); char start[20]; char end[20]; char word[205]; while(1) { gets(start); if(strcmp(start,"START")!=0) break; gets(word); translate(word); puts(word); gets(end); } } void translate(char word[]) { int i,len; len=strlen(word); for(i=0;i<len;i++) { if(word[i]>=’A’&&word[i]<=’E’) { word[i]+=21; } else … Continue reading

Posted in poj | Leave a comment

Poj Solution 3748

http://poj.org/problem?id=3748 import java.io.BufferedInputStream; import java.util.Scanner; /** * *poj3748 * λ���� * @author NC */ public class Main { public static void main(String[] args) { Scanner scan = new Scanner(new BufferedInputStream(System.in)); if (scan.hasNext()) { String[] ss = scan.nextLine().trim().split("[,]"); Integer r = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3747

http://poj.org/problem?id=3747 //* @author /** * @version 2009/08/31 * @author sbzlyessit */ import java.io.*; import java.util.*; public class Main { private static BufferedReader in =new BufferedReader(new InputStreamReader(System.in)); private static StringTokenizer st; private static double[] x = new double[10], y = new … Continue reading

Posted in poj | Leave a comment

Poj Solution 3744

http://poj.org/problem?id=3744 //* @author: <strong> import java.util.*; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); double p,p1,p2,p3; while (sc.hasNext()) { int n=sc.nextInt(); int a[]=new int[n+1]; p=sc.nextDouble(); for (int i=1;i<=n;i++) a[i]=sc.nextInt(); if (a[1]==1) {System.out.println("0.0000000");continue;} int now=1; p1=0;p2=1; for (int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3742

http://poj.org/problem?id=3742 import java.math.BigInteger; import java.io.*; import java.util.*; public class Main { static int n; static BigInteger t=new BigInteger("1"); static BigInteger c[][] = new BigInteger [210][210]; /* static BigInteger C(int n,int m) { if(m==0||m==n) return BigInteger.ONE; BigInteger res=new BigInteger("1"); int i; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3740

http://poj.org/problem?id=3740 //* @author /** * @version 2009/08/28 * @author sbzlyessit */ import java.io.*; import java.util.*; public class Main { private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); private static StringTokenizer st; private static int[] matrix = new int[300]; public static … Continue reading

Posted in poj | Leave a comment

Poj Solution 3737

http://poj.org/problem?id=3737 //* @author: <strong> import java.util.*; public class Main{ static final double pi=Math.PI; public static void main(String args[]){ Scanner sc=new Scanner(System.in); double s; while (sc.hasNext()) { s=sc.nextDouble(); double h=Math.sqrt(2*s/pi); double r=Math.sqrt(s*s/(pi*pi*h*h+2*pi*s)); double v=(1.0/3.0)*(s*s)*h/(pi*h*h+2*s); System.out.printf("%.2fn%.2fn%.2fn",v,h,r); } } }

Posted in poj | Leave a comment

Poj Solution 3736

http://poj.org/problem?id=3736 //* @author: import java.io.*; import java.math.*; import java.util.*; import java.util.Comparator; import java.util.ArrayList; public class Main { public static class node { double x,y,s,r,d,t; node(double xx,double yy,double ss,double rr,double dd,double tt) { x=xx;y=yy;s=ss;r=rr;d=dd;t=tt; } double getx(){return x;} double gety(){return y;} … Continue reading

Posted in poj | Leave a comment

Poj Solution 3734

http://poj.org/problem?id=3734 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { /** * @param args * @return */ static int pow_mod(int a,int b,int c) { int r=1,d=a; while(b>0){ if((b&1)==1) r = r*d%c; d = d*d%c; b>>=1; } return r; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3723

http://poj.org/problem?id=3723 //* @author: //Kruskal �㷨: import java.io.*; import java.util.*; class cin { static int leave=0; static StringTokenizer st; static BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); static int nextInt() throws Exception { while (leave==0) { st=new StringTokenizer(in.readLine()); leave=st.countTokens(); } leave–; return Integer.parseInt(st.nextToken()); } … Continue reading

Posted in poj | Leave a comment

Poj Solution 3720

http://poj.org/problem?id=3720 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; /** * @author Administrator ѭ��С��+ѭ���� */ public class Main { /** *���� */ private int numerator; /** *��ĸ */ private int denominator; /** * ѭ���ڲ��ᳬ��100����� */ private static int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3708

http://poj.org/problem?id=3708 import java.util.*; import java.math.*; public class Main { static BigInteger x,y; static BigInteger[] a=new BigInteger[1000]; static BigInteger[] m=new BigInteger[1000]; static void egcd(BigInteger a,BigInteger b){ if(b.equals(BigInteger.ZERO)){ x=BigInteger.ONE; y=BigInteger.ZERO; return ; } egcd(b,a.mod(b)); BigInteger temp=y; y=x.subtract((a.divide(b)).multiply(y)); x=temp; } static BigInteger solve(int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3705

http://poj.org/problem?id=3705 //* @author: import java.util.Scanner; public class Main { Scanner cin = new Scanner(System.in); int n; public void inPut() { n = cin.nextInt(); reverse(); } private void reverse() { if (n == 1) { System.out.println(0); } else { if (n … Continue reading

Posted in poj | Leave a comment

Poj Solution 3692

http://poj.org/problem?id=3692 //* @author: <strong>Yeming&nbsp;Hu</strong>&quot;cslittleye@gmail.com&quot; import java.util.*; public class Main { public static int b; public static int g; public static int m; public static boolean[][] graph; public static boolean[] checked; public static int[] link; public static void main(String[] args) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 3687

http://poj.org/problem?id=3687 /* @author: */ import java.util.Scanner; import java.util.Arrays; public class Main{ int degree[]=new int[210]; boolean visit[][]=new boolean[210][210]; int path[]=new int[210]; int n,m,t; void topsort(){ for(int k=n;k>=1;k–){ int i=n; while(i>=1 && degree[i]!=0) i–; if(i< 1){ System.out.printf("-1n"); return; } degree[i]=-1; path[i]=k; for(int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3677

http://poj.org/problem?id=3677 //* @author import java.util.*; import java.io.*; class Main { static int armor[]; final static int MAX = 1000000; static class Node { Node l = null, r = null; int flag, step, value; Node(int k, int v) { flag … Continue reading

Posted in poj | Leave a comment

Poj Solution 3673

http://poj.org/problem?id=3673 import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner scanner=new Scanner(System.in); String str1=scanner.next(); String str2=scanner.next(); char[] array1=str1.toCharArray(); char[] array2=str2.toCharArray(); int sum1=0; for(int i=0;i< array1.length;i++){ sum1+=array1[i]-48; } int sum2=0; for(int i=0;i< array2.length;i++){ sum2+=array2[i]-48; } System.out.println(""+(sum1*sum2)); } }

Posted in poj | Leave a comment

Poj Solution 3672

http://poj.org/problem?id=3672 //* @author ������&lt;hongxp11@163.com&gt; import java.util.Scanner; public class Main { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int M = in.nextInt(); int T = in.nextInt(); int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3671

http://poj.org/problem?id=3671 import java.util.Scanner; import java.util.Arrays; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n; int v[]=new int[30002]; int f[]=new int[30002]; int g[]=new int[30002]; n=sc.nextInt(); for(int i=1;i<=n;i++) v[i]=sc.nextInt(); f[0]=0; g[n+1]=0; for(int i=1;i<=n;i++){ if(v[i]==2) f[i]=f[i-1]+1; else f[i]=f[i-1]; } … Continue reading

Posted in poj | Leave a comment

Poj Solution 3670

http://poj.org/problem?id=3670 /* @author: */ import java.util.Scanner; import java.util.Arrays; public class Main{ static int mintwo(int a,int b){ return a< b?a:b; } static int minthird(int a,int b,int c){ int temp=mintwo(a,b); return mintwo(temp,c); } public static void main(String args[]){ Scanner sc=new Scanner(System.in); int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3665

http://poj.org/problem?id=3665 /* @author: */ import java.util.Scanner; import java.util.Arrays; public class Main{ public static void main(String args[]) { Scanner sc=new Scanner(System.in); int arr[]=new int[10010]; int n,m,i,j,u; n=sc.nextInt(); m=sc.nextInt(); for(i=0;i< n;i++) arr[i]=sc.nextInt(); for(i=0;i< m;i++) { int maxx=-1,tag=0; for(j=0;j< n;j++) if(arr[j]>maxx) { maxx=arr[j]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3664

http://poj.org/problem?id=3664 //* @author ������&lt;hongxp11@163.com&gt; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Scanner; public class Main { static class vote { int first; int second; int index; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int N … Continue reading

Posted in poj | Leave a comment

Poj Solution 3663

http://poj.org/problem?id=3663 //* @author: 82638882@163.com import java.util.*; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); int a=in.nextInt(); int b=in.nextInt(); ArrayList< Integer> arr=new ArrayList< Integer>(); for(int i=0;i< a;i++) arr.add(in.nextInt()); Collections.sort(arr); int count=0; for(int i=0;i< a-1;i++) { int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3660

http://poj.org/problem?id=3660 //* @author popop0p0popo import java.util.*; import java.io.*; public class Main{ public static void main(String[] args){ Scanner in=new Scanner(new BufferedReader(new InputStreamReader(System.in))); int n=in.nextInt(); int m=in.nextInt(); int[][] p=new int[n][n]; for (int i=0;i< n ;i++ ){ for (int j=0;j< n ;j++ ){ … Continue reading

Posted in poj | Leave a comment

Poj Solution 3658

http://poj.org/problem?id=3658 //* @author /** * @version 2009/08/21 * @author sbzlyessit */ import java.io.*; import java.util.*; public class Main { private static final int MAX_N = 100000; private static BufferedReader in =new BufferedReader(new InputStreamReader(System.in)); private static StringTokenizer st; private static int[] … Continue reading

Posted in poj | Leave a comment

Poj Solution 3657

http://poj.org/problem?id=3657  

Posted in poj | Leave a comment

Poj Solution 3653

http://poj.org/problem?id=3653 //* @author: SmilingWang import java.util.*; import java.io.*; public class Main { static final int INF = 100000000; public static void main(String[] args){ Scanner in = new Scanner(new BufferedInputStream(System.in)); int x = in.nextInt(); int y = in.nextInt(); while(x != 0 … Continue reading

Posted in poj | Leave a comment

Poj Solution 3652

http://poj.org/problem?id=3652 import java.util.Arrays; import java.util.Scanner; public class Main { int a; int b; int c; int s; int x; char[] result; int flg; boolean[] dup; public Main() { Scanner scan = new Scanner(System.in); while ((a = scan.nextInt()) != 0) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 3650

http://poj.org/problem?id=3650 //* @author ������&lt;hongxp11@163.com&gt; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(true) { String input = in.nextLine(); if(input.equals("#")) break; int len = input.length(); for(int i = 0; i < len; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3646

http://poj.org/problem?id=3646 //* @author: import java.util.*; public class Main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int i,j,ans; end: while (sc.hasNext()) { int n=sc.nextInt(); if(n==0) break; int m=sc.nextInt(); int a[]=new int[n+1]; int b[]=new int[m+1]; for ( i=1;i<=n;i++) a[i]=sc.nextInt(); for … Continue reading

Posted in poj | Leave a comment

Poj Solution 3641

http://poj.org/problem?id=3641 //* @author: 82638882@163.com import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); while(true) { long p=in.nextLong(); long a=in.nextLong(); if(a==0&&p==0) break; if(isPrime(p)){ System.out.println("no"); continue; } System.out.println(sum(a,p,p)==a?"yes":"no"); } } public static boolean isPrime(long a) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 3640

http://poj.org/problem?id=3640 //* @author ������&lt;hongxp11@163.com&gt; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; public class Main { /** * @param args * @throws IOException * @throws NumberFormatException */ public … Continue reading

Posted in poj | Leave a comment

Poj Solution 3639

http://poj.org/problem?id=3639 //* @author: import java.util.*; public class Main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int i,n; double rate,us,ca,tus,tca,t1,t2; while (sc.hasNext()) { n=sc.nextInt(); if(n==0) break; ca=1000;us=0; for (i=1;i<=n;i++) { rate=sc.nextDouble(); t1=ca/rate*.97; t1=(Math.floor(t1*100))/100; t2=us*rate*.97; t2=(Math.floor(t2*100))/100; tus=(us>t1?us:t1); tca=(ca>t2?ca:t2); us=tus;ca=tca; } … Continue reading

Posted in poj | Leave a comment

Poj Solution 3637

http://poj.org/problem?id=3637 //* @author popop0p0popo import java.util.*; import java.io.*; public class Main{ public static void main(String[] args){ Scanner scanner=new Scanner(new BufferedReader(new InputStreamReader(System.in))); int n=scanner.nextInt(); int t,total; int[] prs; for (int i=0;i< n ;i++ ){ t=scanner.nextInt(); prs=new int[t]; for (int j=0;j< t … Continue reading

Posted in poj | Leave a comment

Poj Solution 3633

http://poj.org/problem?id=3633 //* @author /** * @version 2009/08/26 * @author sbzlyessit */ /*������. ״̬����, ���ü��仯����, ����ת�ƺķѾ޴�, ���������֦. *����Ҫ��һ���֦����ÿһλƥ��ʱ��Ҫȡ��ij��Ƚ�����һ������. */ import java.io.*; import java.util.*; public class Main { private static final int MAX_N = 18; private static BufferedReader in = new BufferedReader(new … Continue reading

Posted in poj | Leave a comment

Poj Solution 3632

http://poj.org/problem?id=3632 //* @author: 82638882@163.com import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); int a=in.nextInt(); while(a!=0) { int b=in.nextInt(); int[] c=new int[b]; for(int i=0;i< b;i++) { c[i]=in.nextInt(); } int d,e,g; for(d=e=c[0],g=0;g< b;g++) { if(d>c[g])d=c[g]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3630

http://poj.org/problem?id=3630 import java.util.Scanner; public class Main { private static Trie trie = new Trie(); private static boolean isConsistent = true; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int i = 0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3628

http://poj.org/problem?id=3628 import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; public class Main { static int n, b; static int[] h; static boolean[] used; static int min = Integer.MAX_VALUE; public static void main(String[] args) throws Exception { BufferedReader read = new BufferedReader(new InputStreamReader( … Continue reading

Posted in poj | Leave a comment

Poj Solution 3627

http://poj.org/problem?id=3627 //* @author import java.io.*; import java.util.*; import java.math.*; public class Main { static int[] bookHeight; static int n; static BigInteger b; public static void main(String[] args) throws Exception { readFile(); } public static void readFile() throws Exception { BufferedReader … Continue reading

Posted in poj | Leave a comment

Poj Solution 3626

http://poj.org/problem?id=3626 //* @author: import java.io.BufferedInputStream; import java.util.LinkedList; import java.util.Scanner; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ public class Main { static int[][] field = new int[1001][1001]; static int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3625

http://poj.org/problem?id=3625 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader( System.in)); String[] s = read.readLine().split(" "); int n = Integer.parseInt(s[0]); int m = Integer.parseInt(s[1]); int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3624

http://poj.org/problem?id=3624 //* @author: 82638882@163.com import java.io.*; public class Main { static int[] p,q,d; static int a,b; public static void main(String[] args) throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); String[] ss=in.readLine().split(" "); a=Integer.parseInt(ss[0]); b=Integer.parseInt(ss[1]); p=new int[a+1]; q=new int[a+1]; for(int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3619

http://poj.org/problem?id=3619 import java.util.*; import java.io.*; /* * n ����; * s[i] ÿ���ӿ���ɵĹ��� * t[i] һ����l��������ֵ�ʱ�� * r[i] һ��l�������Ҫ��Ϣ��ʱ�� */ public class Main{ public static void main(String rgs[]) throws Exception { BufferedReader stdin = new BufferedReader( new InputStreamReader(System.in)); String line = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3601

http://poj.org/problem?id=3601 //* @author popop0p0popo import java.util.*; import java.io.*; public class Main{ public static int step; public static int[] h; public static void main(String[] args){ Scanner scanner=new Scanner(new BufferedReader(new InputStreamReader(System.in))); int n,m; while (scanner.hasNext()){ n=scanner.nextInt(); m=scanner.nextInt(); step=0; h=new int[n]; for (int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3589

http://poj.org/problem?id=3589 //* @author ������&lt;hongxp11@163.com&gt; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = Integer.parseInt(in.nextLine()); for(int j = 0; j< n; j++) { String first = in.next(); String second = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3536

http://poj.org/problem?id=3536 //* @author: 82638882@163.com import java.util.*; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); while(in.hasNext()) { int a=in.nextInt(); int x=1,y=1,z=a,m=1,n=1,q=a; for(int i=(int)Math.pow(a,1.0/3)+1;i>0;i–) { if(a%i==0) { x=i; for(int j=(int)Math.sqrt(a/x)+1;j>0;j–) { if((a/x)%j==0) { y=j; z=a/x/j; if(x*y+y*z+z*x< m*n+n*q+q*m) … Continue reading

Posted in poj | Leave a comment

Poj Solution 3522

http://poj.org/problem?id=3522 //* @author: import java.io.*; import java.util.*; /*�����������Ȩֵ����СȨֵ����С��: *��˼��:�ȶԱ�����. ���������ڵ�һ����������,��¼���Ȩֵ����СȨֵ����С��,ö��������� *��α�֤�������������Ž���,��Ϊ���Ѿ���Ȩֵ��������,���ڵ�һ�����ɵ����Ȼ����С��(�Ͻ���½�֮����С) */ class cin { static BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); static int a,c; static int nextInt() throws IOException { c=in.read(); a=0; while(c==’ ‘||c==’r’||c==’n’)c=in.read(); while(c!=’ ‘&&c!=’r’&&c!=’n’) { a=a*10+c-‘0’; c=in.read(); } return … Continue reading

Posted in poj | Leave a comment