Author Archives: toad, die

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

Poj Solution 3365

http://poj.org/problem?id=3365 /* @author: */ //����һ�ų�ΪH��Ϊw��ֽ��Ҫ����һ���������Բ����ʹ����Բ�İ뾶���� //���}�����һ����wΪ����Բ���ܳ���һ����H-2RΪ����Բ���ܳ���Ȼ��ȡ���ֵ�ͺ��� import java.util.Scanner; import java.util.Arrays; public class Main{ static double pi=Math.PI; static double epx=1e-6; public static void main(String args[]){ Scanner sc=new Scanner(System.in); double w,h,v1,v2,temp,r,d; while(sc.hasNext()){ w=sc.nextDouble(); h=sc.nextDouble(); if(w==0&&h==0) break; if(h>w){temp=h;h=w;w=temp;} v1=h*h*(w-h/pi)/(4.0*pi); d=w/(pi+1); if(d>h+epx){/*�ж�d�Ƿ������*/ r=h/2.0; v2=pi*r*r*h; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3364

http://poj.org/problem?id=3364 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,m,c; while(sc.hasNext()){ n=sc.nextInt(); if(n==0) break; m=sc.nextInt(); c=sc.nextInt(); int t=(m-7)*(n-7); int t1=(t+1)/2; if (c==0) System.out.printf("%dn",t-t1); else System.out.printf("%dn",t1); } } }

Posted in poj | Leave a comment

Poj Solution 3356

http://poj.org/problem?id=3356 import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main{ public static void main(String[] args) throws Exception{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String str ; while((str=in.readLine())!=null){ StringTokenizer toke1 = new StringTokenizer(str); StringTokenizer toke2 = new StringTokenizer(in.readLine()); int m = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3352

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

Posted in poj | Leave a comment

Poj Solution 3349

http://poj.org/problem?id=3349 //* @author: import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; class Node { int index; Node next; } public class Main { static BufferedReader cin = new BufferedReader(new InputStreamReader(System.in)); final int N=9997; int [][]snow=new int[100010][6]; boolean check(int s1,int s2) … Continue reading

Posted in poj | Leave a comment

Poj Solution 3340

http://poj.org/problem?id=3340 //* @author ������&lt;hongxp11@163.com&gt; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { /** * @param args * @throws IOException */ public static int count(String a, String b) { int len = a.length(); int result = 1; for (int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3332

http://poj.org/problem?id=3332 import java.util.regex.*;import java.util.*; public class Main { public static void main(String[] args){ String str; int n; Scanner cin = new Scanner(System.in); n=cin.nextInt(); str=cin.nextLine(); Pattern pattern = Pattern.compile("(\s)*(\+|\-)?(\d)+(\.(\d)+)?((e|E)(\+|\-)?(\d)+)?"); int i; for(i=0;i< n;++i){ str=cin.nextLine(); Matcher matcher = pattern.matcher(str); if(matcher.matches()){ System.out.println("LEGAL"); } … Continue reading

Posted in poj | Leave a comment

Poj Solution 3331

http://poj.org/problem?id=3331 import java.io.BufferedInputStream; import java.math.BigDecimal; import java.util.Scanner; /** * * poj3331 * @author NC */ public class Main { public static void main(String[] args) { Scanner scan = new Scanner(new BufferedInputStream(System.in)); while (scan.hasNext()) { int n = scan.nextInt(); for (int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3325

http://poj.org/problem?id=3325 import java.util.*; import java.text.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); while(true) { int num = cin.nextInt(); if(num == 0) break; int[] list = new int[num]; int max = 0; int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3324

http://poj.org/problem?id=3324 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; import java.math.*; public class Main { public static void main(String args[]) throws Exception { Scanner cin=new Scanner(System.in); BigInteger s,M; int p,i; while(cin.hasNext()) { p=cin.nextInt(); s=BigInteger.valueOf(4); M=BigInteger.ONE; M=M.shiftLeft(p).subtract(BigInteger.ONE); for(i=0;i< p-2;++i) { s=s.multiply(s).subtract(BigInteger.valueOf(2)); while(s.bitLength()>p) … Continue reading

Posted in poj | Leave a comment

Poj Solution 3321

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

Posted in poj | Leave a comment

Poj Solution 3307

http://poj.org/problem?id=3307 //* @author import java.util.*; public class Main{ public static void main(String args[]){ int k,n; Scanner in=new Scanner(System.in); k=in.nextInt(); init(); while(k–>0){ n=in.nextInt(); System.out.printf("%dn",s[n]); } } static int MAX=80000; static long s[]=new long[MAX]; //���ڴ洢������� static long d2[]=new long[MAX]; //�洢���к���������2�ҷ��������� static long … Continue reading

Posted in poj | Leave a comment

Poj Solution 3302

http://poj.org/problem?id=3302 //* @author ������&lt;hongxp11@163.com&gt; import java.util.Scanner; public class Main { /** * @param args */ public static boolean isSubsequence(String s1, String s2) { int len = s2.length(); int index = -1; int i = 0; for (i = 0; i … Continue reading

Posted in poj | Leave a comment

Poj Solution 3300

http://poj.org/problem?id=3300 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { static final int N = 20; static int n,m; static double front[] = new double[N],rear[] = new double[N],cnt[]=new double[N*N]; static double Get_Num(StreamTokenizer cin)throws Exception{ cin.nextToken(); return cin.nval; } … Continue reading

Posted in poj | Leave a comment

Poj Solution 3299

http://poj.org/problem?id=3299 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); while (scan.hasNext()) { double temperature = 0, dewpoint = 0, humidex = 0; String[] ss = scan.nextLine().split(" "); String sa = ss[0]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3298

http://poj.org/problem?id=3298 // author:M.J import java.util.*; import java.io.*; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(new BufferedInputStream(System.in)); int T = in.nextInt(); while(T > 0){ T–; int n = in.nextInt(); int k = in.nextInt(); n–; int curr … Continue reading

Posted in poj | Leave a comment

Poj Solution 3295

http://poj.org/problem?id=3295 //* @author: import java.util.Scanner; import java.util.Stack; public class Main { public static void main(String[] args) { new Main().init(); } public void init() { Scanner sc = new Scanner(System.in); char[] s; boolean flag; while (!sc.hasNextInt()) { flag = true; s … Continue reading

Posted in poj | Leave a comment

Poj Solution 3286

http://poj.org/problem?id=3286 //* @author: 82638882@163.com import java.io.*; public class Main { static long[] a=new long[]{ 1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000 }; static long[] b=new long[]{ 0,1,11,192,2893,38894,488895,5888896,68888897,788888898 }; static long[] c=new long[]{ 0,1,20,300,4000,50000,600000,7000000,80000000,900000000 }; public static void main(String[] args) throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader … Continue reading

Posted in poj | Leave a comment

Poj Solution 3282

http://poj.org/problem?id=3282 //* @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 sl,sr,left,right; int nn=sc.nextInt(); while((nn–)!=0) { int l=sc.nextInt(); int n=sc.nextInt(); l*=100;sl=0;sr=0;left=0;right=0; for (int i=1;i<=n;i++) { int t=sc.nextInt(); char s[]=sc.next().toCharArray(); if (s[0]==’l’) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 3278

http://poj.org/problem?id=3278 import java.io.BufferedInputStream; import java.util.LinkedList; import java.util.Scanner; public class Main { public static final int MAX = 200000; public static void main(String[] args) { Scanner scan = new Scanner(new BufferedInputStream(System.in)); if (scan.hasNext()) { int n = scan.nextInt(); int k = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3273

http://poj.org/problem?id=3273 //* @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(); int[] c=new int[a]; int total=0; int min=0; for(int i=0;i< a;i++) { c[i]=in.nextInt(); total+=c[i]; if(c[i]>min) min=c[i]; } int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3268

http://poj.org/problem?id=3268 import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int x = sc.nextInt(); int[][] map1 = new int[n + 1][n + … Continue reading

Posted in poj | Leave a comment

Poj Solution 3267

http://poj.org/problem?id=3267 import java.util.*; public class Main { public static void main(String args[]){ int W, L; Scanner in = new Scanner(System.in); W = in.nextInt(); L = in.nextInt(); String msg = in.next(); String[] words = new String[W]; int i, j; for(i = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3264

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

Posted in poj | Leave a comment

Poj Solution 3259

http://poj.org/problem?id=3259 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; class edge{ int s,t,l; public void set(int _s,int _t,int _l){ this.s = _s; this.t = _t; this.l = _l; } } public class Main { static int M = 6000,N = 500+20,Inf … Continue reading

Posted in poj | Leave a comment

Poj Solution 3256

http://poj.org/problem?id=3256 //* @author: SmilingWang import java.util.*; public class Main { static LinkedList< Integer> set = new LinkedList< Integer>(); static TreeSet< Integer> tmset = new TreeSet< Integer>(); static int[][] path; static boolean[][] use; static ArrayList[] table; public static void main(String[] args){ … Continue reading

Posted in poj | Leave a comment

Poj Solution 3253

http://poj.org/problem?id=3253 import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] nodes = new int[n]; for (int i = 0; i < n; i++) { nodes[i] … Continue reading

Posted in poj | Leave a comment

Poj Solution 3252

http://poj.org/problem?id=3252 import java.io.BufferedReader; import java.io.InputStreamReader; import java.math.BigInteger; public class Main { static long[] arr = new long[] { 0, 0, 1, 2, 6, 11, 27, 49, 113, 206, 462, 848, 1872, 3458, 7554, 14030, 30414, 56747, 122283, 229045, 491189, 923099, … Continue reading

Posted in poj | Leave a comment

Poj Solution 3250

http://poj.org/problem?id=3250 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; int p[]=new int[80010],q[]=new int[80010]; n=sc.nextInt(); for(i=0;i< n;i++) p[i]=sc.nextInt(); for(i=0;i< n;i++) q[i]=1; p[n]=1000000010; for(i=n-1;i>=0;i–) { int u=p[i+1]; while(p[i]>p[i+q[i]]) q[i]+=q[i+q[i]]; } long total=0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3233

http://poj.org/problem?id=3233 //* @author: import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; public class Main{ static int n, k, m; static int[][] matrix; static int[][] result; /** * ������a��Ԫ�ظ��Ƶ�����һ������ * * @param a * @return */ static int[][] copy(int[][] a) { int[][] re … Continue reading

Posted in poj | Leave a comment

Poj Solution 3226

http://poj.org/problem?id=3226 //* @author:alpc12 import java.io.*; import java.util.*; import java.math.*; public class Main { BigInteger[][] Ank = new BigInteger[27][27]; void pre() { BigInteger i, j; for(i = BigInteger.ONE; i.compareTo(new BigInteger("27")) != 0; i = i.add(BigInteger.ONE)) { Ank[i.intValue()][0] = BigInteger.ONE; Ank[i.intValue()][1] = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3224

http://poj.org/problem?id=3224 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(); int[][] array = new int[num][num]; int max = 0; int index = 0; for(int i = 0; i … Continue reading

Posted in poj | Leave a comment