Author Archives: toad, die

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 | Comments Off on Poj Solution 3652

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 | Comments Off on Poj Solution 3650

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 | Comments Off on Poj Solution 3646

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 | Comments Off on Poj Solution 3641

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 | Comments Off on Poj Solution 3640

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 | Comments Off on Poj Solution 3639

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 | Comments Off on Poj Solution 3637

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 | Comments Off on Poj Solution 3633

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 | Comments Off on Poj Solution 3632

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 | Comments Off on Poj Solution 3630

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 | Comments Off on Poj Solution 3628

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 | Comments Off on Poj Solution 3627

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 | Comments Off on Poj Solution 3626

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 | Comments Off on Poj Solution 3625

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 | Comments Off on Poj Solution 3624

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 | Comments Off on Poj Solution 3619

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 | Comments Off on Poj Solution 3601

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 | Comments Off on Poj Solution 3589

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 | Comments Off on Poj Solution 3536

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 | Comments Off on Poj Solution 3522

Poj Solution 3518

http://poj.org/problem?id=3518 //* @author popop0p0popo import java.util.*; import java.io.*; public class Main{ public static void main(String rgs[]) throws Exception { boolean[] prime=new boolean[1299710]; Arrays.fill(prime,true); prime[1] = false; prime[0] = false; for(int i=2; i<=10000; ++i){ if(prime[i]) for (int j=i; i*j< 1299710; ++j) … Continue reading

Posted in poj | Comments Off on Poj Solution 3518

Poj Solution 3517

http://poj.org/problem?id=3517 //* @author: 82638882@163.com import java.io.*; class Main { static int n,k,m; public static void main(String[] args) throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); while(true) { String[] ss=in.readLine().split(" "); n=Integer.parseInt(ss[0]); k=Integer.parseInt(ss[1]); m=Integer.parseInt(ss[2]); if(n==0) break; System.out.println((f(n-1)+m)%n+1); } } static … Continue reading

Posted in poj | Comments Off on Poj Solution 3517

Poj Solution 3516

http://poj.org/problem?id=3516 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; class Queue{ int pre; int cnt_posi; int cnt_num; int cnt_sum; void set(int pre_t,int cnt_num_t,int cnt_sum_t,int cnt_posi_t){ this.pre = pre_t; this.cnt_num = cnt_num_t; this.cnt_sum = cnt_sum_t; this.cnt_posi = cnt_posi_t; } } class node{ … Continue reading

Posted in poj | Comments Off on Poj Solution 3516

Poj Solution 3512

http://poj.org/problem?id=3512 //* @author: 82638882@163.com import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); String[] ss; String s; int count=0; while(true) { count++; node[] arr=new node[1001]; node[] pp=new … Continue reading

Posted in poj | Comments Off on Poj Solution 3512

Poj Solution 3511

http://poj.org/problem?id=3511 //* @author mekarlos@gmail.com import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String args[]) throws IOException{ BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tokens; int[] prims=new int[1000001]; int[] ferms=new int[1000001]; for(int i=3;i< 1000000;i+=2) prims[i]=1; prims[2]=1; … Continue reading

Posted in poj | Comments Off on Poj Solution 3511

Poj Solution 3510

http://poj.org/problem?id=3510 //* @author: 82638882@163.com import java.util.*; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); while(true) { String s=in.nextLine(); StringBuffer sb=new StringBuffer(""); int l=s.length(); boolean bb=false; for(int i=0;i< l;i++) { char c=s.charAt(i); if(i< l-1&&c==’d’&&s.charAt(i+1)==’d’){ sb.append(‘p’); i++; … Continue reading

Posted in poj | Comments Off on Poj Solution 3510

Poj Solution 3508

http://poj.org/problem?id=3508 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)); int num = 1; int flg, tt, last; while (true) { char[] c = … Continue reading

Posted in poj | Comments Off on Poj Solution 3508

Poj Solution 3507

http://poj.org/problem?id=3507 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); float[] input = new float[6]; while(true) { input[0] = in.nextFloat(); float max = input[0]; float min = input[0]; float sum = input[0]; … Continue reading

Posted in poj | Comments Off on Poj Solution 3507

Poj Solution 3505

http://poj.org/problem?id=3505 //* @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 nn,n,m,ans; nn=sc.nextInt(); while((nn–)!=0) { n=sc.nextInt(); m=sc.nextInt(); int a[][]=new int[n+1][m+1]; ans=0; for (int i=1;i<=n;i++) { for (int j=1;j<=m;j++) a[i][j]=sc.nextInt(); int tp=0,now=1,t1,t2; for … Continue reading

Posted in poj | Comments Off on Poj Solution 3505

Poj Solution 3504

http://poj.org/problem?id=3504 //* @author:alpc12 import java.util.*; public class Main { public static Scanner in=new Scanner(System.in).useLocale(Locale.US); public void run() { boolean[] singles=new boolean[26]; Map< String,String>[][] words=new Map[26][26]; for(int i=0;i< 26;++i) for(int j=0;j< 26;++j) words[i][j]=new HashMap< String,String>(); Set< String>[][] doublewords=new Set[26][26]; for(int i=0;i< … Continue reading

Posted in poj | Comments Off on Poj Solution 3504

Poj Solution 3488

http://poj.org/problem?id=3488 //* @author: import java.util.*; import java.math.*; import java.io.FileReader; public class Main { public static void main(String[] args) throws Exception{ Scanner in=new Scanner(System.in); while (true) { int n; try { n=in.nextInt(); } catch(Exception e) {return;} String []s=new String [n]; for … Continue reading

Posted in poj | Comments Off on Poj Solution 3488

Poj Solution 3486

http://poj.org/problem?id=3486 /* @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 n,c; int m[][]=new int[1003][1003]; int f[]=new int[1003]; while(sc.hasNext()){ c=sc.nextInt(); n=sc.nextInt(); for(int i=0;i< m.length;i++) Arrays.fill( m[i],0); for(int … Continue reading

Posted in poj | Comments Off on Poj Solution 3486

Poj Solution 3485

http://poj.org/problem?id=3485 //* @author: import java.util.*; import java.math.*; import java.io.FileReader; class SEG implements Comparable<SEG> { double b,e; SEG(double x,double y) { b=x;e=y; } public int compareTo(SEG other) { if (b< other.b) return -1; else if (b==other.b) { if (e< other.e) return … Continue reading

Posted in poj | Comments Off on Poj Solution 3485

Poj Solution 3484

http://poj.org/problem?id=3484 //* @author: import java.util.*; import java.math.*; import java.io.FileReader; class node{ int x,y,z; node(String s) { int t=0,cnt=0; for (int i=0;i<=s.length();i++) { if (i!=s.length()&&s.charAt(i)>=’0’&&s.charAt(i)<=’9′) { t=t*10+s.charAt(i)-‘0’; } else { if (cnt==0) x=t; else if (cnt==1) y=t; else if (cnt==2) z=t; … Continue reading

Posted in poj | Comments Off on Poj Solution 3484

Poj Solution 3483

http://poj.org/problem?id=3483 //* @author:alpc12 import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) throws FileNotFoundException { new Main().run(); } int[] f; int[] dp; int Root(int x) { if(f[x] == x) return … Continue reading

Posted in poj | Comments Off on Poj Solution 3483

Poj Solution 3482

http://poj.org/problem?id=3482 //* @author: import java.util.*; import java.io.FileReader; import java.math.*; public class Main { public static void main(String[] args) throws Exception{ int n=0; int [] dx=new int[1000]; Scanner in=new Scanner(System.in); int fir=1; while (true) { String s; try { while (true) … Continue reading

Posted in poj | Comments Off on Poj Solution 3482

Poj Solution 3481

http://poj.org/problem?id=3481 //* @author: <strong>Yeming&nbsp;Hu</strong>&quot;cslittleye@gmail.com&quot; import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(new BufferedInputStream(System.in)); BinaryMinimumHeap minHeap = new BinaryMinimumHeap(); BinaryMaximumHeap maxHeap = new BinaryMaximumHeap(); while(true) { int request = sc.nextInt(); … Continue reading

Posted in poj | Comments Off on Poj Solution 3481

Poj Solution 3480

http://poj.org/problem?id=3480 //* @author: import java.util.*; import java.math.*; public class Main { public static void main(String[] args) throws Exception{ int nn; Scanner in=new Scanner(System.in); nn=in.nextInt(); while ((nn–)!=0) { int n=in.nextInt(); long ans=0,max=0; for (int i=1;i<=n;i++) { long j=in.nextLong(); if (j>max) max=j; … Continue reading

Posted in poj | Comments Off on Poj Solution 3480

Poj Solution 3476

http://poj.org/problem?id=3476 //* @author: <strong>Yeming&nbsp;Hu</strong>&quot;cslittleye@gmail.com&quot; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); BallSeq head, tail; BinaryHeap pq = new BinaryHeap(); String s = sc.next(); char previousChar = s.charAt(0); Ball ball = … Continue reading

Posted in poj | Comments Off on Poj Solution 3476

Poj Solution 3475

http://poj.org/problem?id=3475 //* @author: <strong>Yeming&nbsp;Hu</strong>&quot;cslittleye@gmail.com&quot; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()) { long a = sc.nextLong(); long b = sc.nextLong(); double c = sc.nextDouble(); double d = sc.nextDouble(); int … Continue reading

Posted in poj | Comments Off on Poj Solution 3475

Poj Solution 3472

http://poj.org/problem?id=3472 //* @author import java.util.*; import java.io.*; import java.math.*; public class Main { /** * @param args the command line arguments */ static BigInteger []a=new BigInteger[10005]; public static void main(String[] args) { // TODO code application logic here int n; … Continue reading

Posted in poj | Comments Off on Poj Solution 3472

Poj Solution 3468

http://poj.org/problem?id=3468 //* @author import java.util.*; import java.io.*; public class Main { public static void main(String []args) { SegmentTree segmentTree=new SegmentTree(); } }; class SegmentTree { public SegmentTree() { tot=0; int n,m,left,right,value; String str; Scanner input=new Scanner(System.in); n=input.nextInt(); m=input.nextInt(); for(int i=1;i<=n;i++) … Continue reading

Posted in poj | Comments Off on Poj Solution 3468

Poj Solution 3461

http://poj.org/problem?id=3461 //* @author: 82638882@163.com import java.io.*; public class Main { static int[] next; static String s1,s2; static int l1,l2,cnt; public static void main(String[] args) throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); int a=Integer.parseInt(in.readLine()); while((a–)!=0) { s1=in.readLine(); s2=in.readLine(); l1=s1.length(); … Continue reading

Posted in poj | Comments Off on Poj Solution 3461

Poj Solution 3444

http://poj.org/problem?id=3444 //* @author mekarlos@gmail.com import java.util.Scanner; /** * * @author usuario */ public class Main { public static void main(String[] args) { Scanner scan=new Scanner(System.in); int n; int[] m,o; while (scan.hasNext()){ n=scan.nextInt(); if (n==0) { break; } m=new int[n]; o=new … Continue reading

Posted in poj | Comments Off on Poj Solution 3444

Poj Solution 3438

http://poj.org/problem?id=3438 import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int num = Integer.valueOf(cin.nextLine()).intValue(); String rawStr = null; char repeatChar = ‘n’; int repeat = 0; char temp = ‘n’; int newLineFlag … Continue reading

Posted in poj | Comments Off on Poj Solution 3438

Poj Solution 3435

http://poj.org/problem?id=3435 /* @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 n,i,j,k1,k2,p[][]=new int[101][101]; n=sc.nextInt(); int len=n*n; for(i=0;i< len;i++) for(j=0;j< len;j++) p[i][j]=sc.nextInt(); boolean bb[]=new boolean[101],is=true; //memset(bb,0,sizeof(bb)); for(i=0;i< len;i++) { Arrays.fill(bb,false); for(j=0;j< … Continue reading

Posted in poj | Comments Off on Poj Solution 3435

Poj Solution 3429

http://poj.org/problem?id=3429 //* @author:alpc12 import java.util.*; import java.math.*; public class Main { int n; BigInteger[] x = new BigInteger[115]; BigInteger[] y = new BigInteger[115]; public class Line { BigInteger a, b, c; } void run() { Scanner cin = new Scanner(System.in); … Continue reading

Posted in poj | Comments Off on Poj Solution 3429

Poj Solution 3427

http://poj.org/problem?id=3427 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,L,v; n=sc.nextInt(); L=sc.nextInt(); int m=0; while((n–)!=0) { v=sc.nextInt(); if(v%L==0)continue; int u=L-v%L; if(u>m)m=u; } System.out.printf("%d",m); } }

Posted in poj | Comments Off on Poj Solution 3427

Poj Solution 3425

http://poj.org/problem?id=3425 //* @author: <strong>Yeming&nbsp;Hu</strong>&quot;cslittleye@gmail.com&quot; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); Call[] calls = new Call[n]; for(int i = 0; i < n; i++) { int … Continue reading

Posted in poj | Comments Off on Poj Solution 3425

Poj Solution 3414

http://poj.org/problem?id=3414 //* @author: import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.Scanner; public class Main{ private static final String[] status = new String[] { "", "FILL(1)", "FILL(2)", "DROP(1)", "DROP(2)", "POUR(1,2)", "POUR(2,1)" }; private static boolean[][] visted = new boolean[101][101]; private static … Continue reading

Posted in poj | Comments Off on Poj Solution 3414