Category Archives: poj

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

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

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

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

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

Poj Solution 3340

http://poj.org/problem?id=3340 //* @author ������<hongxp11@163.com> 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 | Comments Off on Poj Solution 3340

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Poj Solution 3219

http://poj.org/problem?id=3219 //* @author: import java.util.*; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=0; int k=0; int m=0; while(sc.hasNext()){ int a=0; int b=0; int c=0; n=sc.nextInt(); k=sc.nextInt(); m=n-k; while((n=n>>1)!=0) //��n�ĸ������λ����һλ�����൱�ڳ���2 a+=n; while((m=m>>1)!=0) b+=m; while((k=k>>1)!=0) c+=k; if(a-b>c) … Continue reading

Posted in poj | Comments Off on Poj Solution 3219

Poj Solution 3217

http://poj.org/problem?id=3217 #include <stdio.h> #include <memory.h> #include <vector> using namespace std; vector<int> ch[101]; int father[101], mother[101]; bool gender[101]; int A, B; void input( ) { int i, h, t; scanf( "%d%d", &A, &B ); for( i=0; i<101; i++ ) ch[i].clear( ); … Continue reading

Posted in poj | Comments Off on Poj Solution 3217

Poj Solution 3214

http://poj.org/problem?id=3214 #include <stdio.h> #include <memory.h> #include <vector> #include <algorithm> using namespace std; vector<int> v[20]; int a[2100000]; int t[2100000]; int n, m, h; int vn[20]; void input( ) { int i, j; scanf( "%d", &m ); for( i=0; i<m; i++ ) … Continue reading

Posted in poj | Comments Off on Poj Solution 3214

Poj Solution 3212

http://poj.org/problem?id=3212 #include <stdio.h> #include <memory.h> #include <vector> #include <algorithm> using namespace std; #define __int64 long long const int size = 100010; __int64 s[size]; int ss[size]; int m; int pos[100100]; //��� void clear( ) { memset( s, 0, sizeof s ); … Continue reading

Posted in poj | Comments Off on Poj Solution 3212

Poj Solution 3211

http://poj.org/problem?id=3211 #include <stdio.h> #include <vector> #include <string> #include <set> using namespace std; vector<int> v[10]; string color[10]; set<int> s; int main( ) { int n, m, i, j, ans, sum, t, best; char w[100]; while( scanf( "%d%d", &m, &n ) == … Continue reading

Posted in poj | Comments Off on Poj Solution 3211

Poj Solution 3210

http://poj.org/problem?id=3210 //* @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; while (true){ n=scanner.nextInt(); if (n==0){ break; } if (n%2==0){ System.out.println("No Solution!"); } else{ System.out.println(n-1); } } } … Continue reading

Posted in poj | Comments Off on Poj Solution 3210

Poj Solution 3208

http://poj.org/problem?id=3208 /* @author: */ import java.util.Scanner; public class Main { static int s[][]=new int[14][4]; static int to[][]=new int[4][10]; static void doit( ) { int i, j, k; for( i=0; i< 3; i++ ) for( j=0; j< 10; j++ ) to[i][j] … Continue reading

Posted in poj | Comments Off on Poj Solution 3208

Poj Solution 3199

http://poj.org/problem?id=3199 import java.io.BufferedInputStream; import java.math.BigDecimal; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(new BufferedInputStream(System.in)); while (scan.hasNext()) { BigDecimal n = scan.nextBigDecimal(); int d = scan.nextInt(); if (d == 0 && n.equals(BigDecimal.ZERO)) … Continue reading

Posted in poj | Comments Off on Poj Solution 3199

Poj Solution 3198

http://poj.org/problem?id=3198 /* @author: */ import java.math.BigInteger; import java.util.*; public class Main { public static BigInteger get( BigInteger h ) { BigInteger s = h.shiftLeft(1); BigInteger a = BigInteger.ONE.shiftLeft( s.bitLength()/2-1 ).subtract( BigInteger.ONE ); BigInteger b = BigInteger.ONE.shiftLeft( s.bitLength()/2+1 ), c; while( … Continue reading

Posted in poj | Comments Off on Poj Solution 3198

Poj Solution 3194

http://poj.org/problem?id=3194 /* @author: */ import java.util.Scanner; import java.util.Arrays; public class Main{ static int p[][]=new int[105][105]; static int q[][]=new int[101][101]; static int n,cnt; static void dfs(int i,int j) { if(i>n||j>n||i< 1||j< 1) return; q[i][j]=cnt; if(q[i][j+1]==0&&p[i][j]==p[i][j+1]) dfs(i,j+1); if(q[i][j-1]==0&&p[i][j]==p[i][j-1]) dfs(i,j-1); if(q[i+1][j]==0&&p[i][j]==p[i+1][j]) dfs(i+1,j); if(q[i-1][j]==0&&p[i][j]==p[i-1][j]) … Continue reading

Posted in poj | Comments Off on Poj Solution 3194

Poj Solution 3193

http://poj.org/problem?id=3193 //* @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); String mn = sc.nextLine(); Scanner lmn = new Scanner(mn); int m = lmn.nextInt(); int n = lmn.nextInt(); String[] phrases … Continue reading

Posted in poj | Comments Off on Poj Solution 3193

Poj Solution 3192

http://poj.org/problem?id=3192 #include <stdio.h> #include <algorithm> #include <string> #include <string.h> using namespace std; int index[7]; char sum[100]; char str[7][10]; int len[7]; int merge( int len, char *w, int l ) { int i = len-l, j; if( i<0 ) i = … Continue reading

Posted in poj | Comments Off on Poj Solution 3192

Poj Solution 3191

http://poj.org/problem?id=3191 /* @author: */ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int i, n, h; boolean s[]=new boolean[100]; n=sc.nextInt(); if( n == 0 ) { System.out.printf( "0n" ); return ; … Continue reading

Posted in poj | Comments Off on Poj Solution 3191

Poj Solution 3190

http://poj.org/problem?id=3190 #include <stdio.h> #include <algorithm> #include <string> #include <string.h> using namespace std; int empty[50000]; int use[50000]; int a[50000], b[50000]; typedef pair<int,int> p_i; p_i p[100000]; int main( ) { int i, n, m, ans=0; scanf( "%d", &n ); for( i=0; i<n; … Continue reading

Posted in poj | Comments Off on Poj Solution 3190

Poj Solution 3189

http://poj.org/problem?id=3189 #include <vector> #define min(a,b) (((a)<(b))?(a):(b)) using namespace std; class ff { public: typedef int type; // ��Ȩ���� enum { size = 1110 }; // �����ģ enum { max = ( 1<<30 ) }; // ����������� // ��ʼ�� void init(); … Continue reading

Posted in poj | Comments Off on Poj Solution 3189

Poj Solution 3188

http://poj.org/problem?id=3188 #include <stdio.h> #include <algorithm> using namespace std; char w[1000][11]; int button[26]; __int64 a[1000]; int n, B, L; int flag[26]; void clac( int &s1, int &s2 ) { int i, j; s1 = 0, s2 = 0; flag[B] = 100; … Continue reading

Posted in poj | Comments Off on Poj Solution 3188

Poj Solution 3187

http://poj.org/problem?id=3187 //* @author: 82638882@163.com import java.io.*; import java.util.Arrays; public class Main { static int[] p,arr; static int a; 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]); int sum=Integer.parseInt(ss[1]); p=new int[a]; … Continue reading

Posted in poj | Comments Off on Poj Solution 3187

Poj Solution 3186

http://poj.org/problem?id=3186 //* @author: 82638882@163.com import java.io.*; public class Main { public static void main(String[] args) throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); String s=in.readLine(); int a=Integer.parseInt(s); int[] arr=new int[a]; int[][] ds=new int[a][a]; for(int i=0;i< a;i++) { s=in.readLine(); arr[i]=Integer.parseInt(s); … Continue reading

Posted in poj | Comments Off on Poj Solution 3186