Category Archives: poj

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

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

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 | Leave a comment

Poj Solution 3406

http://poj.org/problem?id=3406 //* @author: 82638882@163.com import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); int[] b2=new int[]{6,2,4,8}; int[] b3=new int[]{1,3,9,7}; int[] b7=new int[]{1,7,9,3}; int[] b9=new int[]{1,9,1,9}; int n=in.nextInt(); int m=in.nextInt(); int w=n-m; int e,a2=0,a3=0,a5=0,a7=0,a9=0; e=n;while((e=e/2)!=0) … Continue reading

Posted in poj | Leave a comment

Poj Solution 3404

http://poj.org/problem?id=3404 //* @author: ccQ.SuperSupper import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { int i,n,ans; int way[] = new int[60]; Scanner cin = new Scanner(System.in); while(cin.hasNext()) { n = cin.nextInt(); for(i=0;i< n;++i) way[i] = cin.nextInt(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 3399

http://poj.org/problem?id=3399 import java.util.*; import java.math.*; public class Main { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner in=new Scanner(System.in); int n=in.nextInt(); int k=in.nextInt(); int k1=0,k2=0,a=0,kk=0; int[] a1=new int[101],a2=new int[101],ans=new int[101]; for(int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3386

http://poj.org/problem?id=3386 #include <iostream> #include <map> #include <algorithm> using namespace std; int main() { int A,a,B,b,P; while (cin>>A>>a>>B>>b>>P) { map<int,int> m; if (a == b) { if (!(A + B <= P)) printf("Non"); else printf("Yesn"); continue; } m[a] = A; m[b] … Continue reading

Posted in poj | Leave a comment

Poj Solution 3378

http://poj.org/problem?id=3378 //* @author: ccQ.SuperSupper import java.util.*; import java.math.*; class Binary { int n,i; long ret; long a[],c[]; void init(int x) { n = x; a = new long [x+10]; c = new long [x+10]; for(i=0;i< x+10;++i) { a[i]=c[i]=0; } } … Continue reading

Posted in poj | Leave a comment

Poj Solution 3372

http://poj.org/problem?id=3372 //* @author: 82638882@163.com<br /> /*��Ŀ���⣺��n��ͬѧ���һ��Բ��һ��ʦ���ǹ��4η����1��2��4��7…��ͬѧ�����Ƿ�ÿ��ͬѧ���ܵõ�����һ���ǡ� *����д�����صij������1~100�������ѷ��֣�ֻ�е�n=2^k��kΪ����ʱ�����YES�� */ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); while(in.hasNext()) { int a=in.nextInt(); while(a%2==0) a=a/2; if(a==1) System.out.println("YES"); else System.out.println("NO"); } } }

Posted in poj | Leave a comment

Poj Solution 3371

http://poj.org/problem?id=3371 import java.io.BufferedInputStream; import java.io.IOException; import java.util.Scanner; import java.text.DecimalFormat; class Main { public static boolean isvowel(char a) { if (a==’a’ || a==’e’ || a==’i’ || a==’o’ || a==’u’ || a==’y’) return true; else return false; } public static boolean isword(char … Continue reading

Posted in poj | Leave a comment

Poj Solution 3368

http://poj.org/problem?id=3368 import java.io.*; import java.util.*; public class Main { static treex[] mytreex=new treex[210000]; static int[] hash=new int[100005]; static int[] left=new int[100005]; static int[] right=new int[100005]; static int[] data=new int[100005]; static boolean build=false; static int k=0; public static void main(String args[]) … Continue reading

Posted in poj | Leave a comment

Poj Solution 3366

http://poj.org/problem?id=3366 //* @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(); int b=in.nextInt(); String[] s1=new String[a]; String[] s2=new String[a]; for(int i=0;i< a;i++) { s1[i]=in.next(); s2[i]=in.next(); } for(int i=0;i< b;i++) { … Continue reading

Posted in poj | Leave a comment