Author Archives: toad, die

Poj Solution 1468

http://poj.org/problem?id=1468 //* @author mekarlos@gmail.com import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan=new Scanner(System.in); int n=0,k=0; boolean band; int M[][]=new int[5000][4]; while(scan.hasNext()){ n=scan.nextInt(); for(int i=0;i< n;i++){ for(int j=0;j< 4;j++){ M[i][j]=scan.nextInt(); } } k=0; for(int i=0;i< … Continue reading

Posted in poj | Leave a comment

Poj Solution 1466

http://poj.org/problem?id=1466 import java.util.*; /** * * @author yeming */ public class Main { static int n; static LinkedList< Integer>[] matrix; static int[] result; static boolean[] state; static int ans; /** * @param args the command line arguments */ public static … Continue reading

Posted in poj | Leave a comment

Poj Solution 1465

http://poj.org/problem?id=1465 //* @author: 82638882@163.com import java.io.*; import java.util.*; public class Main { static int[] p,q; static int m,n; static Queue< mye> qu; public static void main(String[] args) throws IOException { Scanner in=new Scanner(System.in); qu=new LinkedList< mye>(); while(in.hasNext()) { qu.clear(); n=in.nextInt(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1463

http://poj.org/problem?id=1463 #include <stdio.h> #include <memory.h> #define min(a,b) ((a)<(b)?(a):(b)) int e[2000][20]; int en[2000]; int ans[2000][2], n; void calc( int k, int f ) { int i; ans[k][0] = 0, ans[k][1] = 1; for( i=0; i<en[k]; i++ ) { if( e[k][i] != … Continue reading

Posted in poj | Leave a comment

Poj Solution 1458

http://poj.org/problem?id=1458 import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); while(in.hasNext()){ String str1 = in.next(); String str2 = in.next(); int[][] DP = new int[str1.length()+1][str2.length()+1]; int i; for(i=0;i<=str1.length();i++) DP[i][0] = 0; for(i=0;i<=str2.length();i++) DP[0][i] = 0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1455

http://poj.org/problem?id=1455 //* @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 ans=0; int c=b/2; if(b%2==0) ans=c*(c-1); else ans=c*c; System.out.println(ans); } } }

Posted in poj | Leave a comment

Poj Solution 1451

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

Posted in poj | Leave a comment

Poj Solution 1450

http://poj.org/problem?id=1450 #include <stdio.h> #include <stdlib.h> #define DEBUG 0 int main(void) { int iCase; if(DEBUG) freopen("in","r",stdin); scanf("%d",&iCase); int number; for ( number = 1; number <=iCase; ++number) { int N,M; scanf("%d%d",&M,&N); printf("Scenario #%d:n",number); printf("%d.",M*N); if(M%2&&N%2)printf("41"); else printf("00"); printf("nn"); } return 0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1430

http://poj.org/problem?id=1430 #include<iostream> using namespace std; const long big=1024*1024*1024; long b; long n,m; char a[16][34]={ ". . . . . . . . . . . . . . . 1", ". . . . . . . . . . … Continue reading

Posted in poj | Leave a comment

Poj Solution 1426

http://poj.org/problem?id=1426 //* @author mekarlos@gmail.com import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; public class Main { public static void main(String[] args) throws IOException { BigInteger a; BigInteger b; BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in)); long c=0,d=0; long n=0; while((n=Long.parseLong(stdin.readLine()))!=0){ //for(n=1;n<=200;n++) { b=new … Continue reading

Posted in poj | Leave a comment

Poj Solution 1423

http://poj.org/problem?id=1423 import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n = cin.nextInt(); while(n > 0) { int test = cin.nextInt(); if(test <= 3) System.out.println(1); else { double result = 0.5*Math.log10(2*test*Math.PI)+ … Continue reading

Posted in poj | Leave a comment

Poj Solution 1422

http://poj.org/problem?id=1422 //* @author: import java.io.*; import java.util.*; import java.math.*; public class Main { static int n,m,match[]=new int[201]; static boolean mat[][]=new boolean[201][201],v[]=new boolean[201]; static boolean findmatch(int pre) { int i; for(i=0;i< m;i++) { if(mat[pre][i]&&!v[i]) { v[i]=true; int buf=match[i]; match[i]=pre; if(buf==-1||findmatch(buf))return true; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1419

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

Posted in poj | Leave a comment

Poj Solution 1418

http://poj.org/problem?id=1418 #include<iostream> #include"math.h" using namespace std; #define MSIZE 1000 const double pi=3.14159265358979324; const double eps=1e-15; struct point {double x,y;}; struct typearc {double a,b;}; struct typecir {point ct; double r; typearc arc[360]; int n; }; int cmp(double a,double b) {if(fabs(a-b)<eps)return 0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1416

http://poj.org/problem?id=1416 /* @author: */ import java.util.*; public class Main { private int target; private char num[]; private int max; private StringBuffer s; private StringBuffer result; boolean check; public Main(int target,char num[]){ this.target=target; this.num=num; max=0; s=new StringBuffer(""); result=new StringBuffer(""); } public … Continue reading

Posted in poj | Leave a comment

Poj Solution 1411

http://poj.org/problem?id=1411 import java.util.*; /** * * @author leo */ public class Main { /** * @param args the command line arguments */ public static boolean prime(int n) { for (int i = 2; i * i <= n; i++) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1410

http://poj.org/problem?id=1410 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(); double dx1,dx2,dy1,dy2; double x1,x2,y1,y2; double k,b; double d1,d2,d3,d4; for (int i=0;i<n ;i++ ){ x1=scanner.nextDouble(); y1=scanner.nextDouble(); x2=scanner.nextDouble(); y2=scanner.nextDouble(); dx1=scanner.nextDouble(); dy1=scanner.nextDouble(); dx2=scanner.nextDouble(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1408

http://poj.org/problem?id=1408 /* @author:����acmilan_fan@yahoo.cn */ import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { static double[][][] mesh=new double[32][32][2]; public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s; String[] ss; int n,i,j; double max=0d,t; while((s=br.readLine())!=null&&!"0".equals(s)){ n=parseInt(s); s=br.readLine(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1406

http://poj.org/problem?id=1406 import java.util.*; /** * * @author leo */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int total, left; while (true) { total … Continue reading

Posted in poj | Leave a comment

Poj Solution 1405

http://poj.org/problem?id=1405 import java.io.BufferedInputStream; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(new BufferedInputStream(System.in)); if (scan.hasNext()) { int n = scan.nextInt(); ArrayList<BigDecimal> results = new ArrayList(18); results.add(0, new BigDecimal(2)); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1404

http://poj.org/problem?id=1404 //* @author: import java.util.*; public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); int K,L; char key[]=new char[100]; char letter[]=new char[100]; int F[]=new int[100]; int p[]=new int[100]; int best; int map[][][]=new int[100][100][100]; int father[][]=new … Continue reading

Posted in poj | Leave a comment

Poj Solution 1401

http://poj.org/problem?id=1401 #include <iostream> using namespace std; int calc(int z) { int i, count = 0; for (i = 5; i <= z; i *= 5) { count += z / i; } return count; } int main() { int n, … Continue reading

Posted in poj | Leave a comment

Poj Solution 1389

http://poj.org/problem?id=1389 #include<iostream> #include"memory.h" #include"algorithm" using std::sort; using namespace std; int x[2010],y[2010]; int n,index_y[2010],index_x[2010],to_y[2010]; int tree[2048*2],cover[2048*2]; int cmp_x(int a,int b) {return x[a]<x[b];} int cmp_y(int a,int b) {return y[a]<y[b];} int init() {int i; for(i=0;;i++) {cin>>x[2*i]>>y[2*i]>>x[2*i+1]>>y[2*i+1]; if(x[2*i]==-1)break; index_x[2*i]=2*i;index_x[2*i+1]=2*i+1; index_y[2*i]=2*i;index_y[2*i+1]=2*i+1; } n=i; if(n==0)return 0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1386

http://poj.org/problem?id=1386 //* @author: 82638882@163.com import java.io.*; public class Main { static int[] arr=new int[26]; static int[] cin=new int[26]; static int[] cout=new int[26]; static boolean[] used=new boolean[26]; public static void main(String[] args) throws NumberFormatException, IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new … Continue reading

Posted in poj | Leave a comment

Poj Solution 1385

http://poj.org/problem?id=1385 #include<iostream> #include"stdio.h" #include"memory.h" using namespace std; double x,y,x1,y1,xb,yb; double area,x_sum,y_sum,temp; int main() { int t,n,i; cin>>t; while(t–) { cin>>n; cin>>x1>>y1; xb=x1,yb=y1; area=x_sum=y_sum=0; for(i=1;i<=n;i++) { if(i<n)cin>>x>>y; else x=xb,y=yb; temp=x*y1-y*x1; x_sum+=temp*(x+x1); y_sum+=temp*(y+y1); area+=temp; x1=x,y1=y; } printf("%.2lf %.2lfn",(double)((long)(x_sum/area/3*100))/100,(double)(long)(y_sum/area/3*100)/100); } return 0; }

Posted in poj | Leave a comment

Poj Solution 1384

http://poj.org/problem?id=1384 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; class Coin{ int price,weight; } public class Main { static final int N = 500+10,M = 10000+10; static int DP[] = new int[M],n,m; static Coin coin[] =new Coin[N]; static void start(){ for(int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1383

http://poj.org/problem?id=1383 #include"stdio.h" #include"memory.h" char map[1100][1100]; bool sign[1100][1100]; int max,bx,by,n,m; void init_sign() { int i,j; for(i=0;i<n;i++) for(j=0;j<m;j++) sign[i][j]=0; } void init() { scanf("%d %d",&m,&n); for(int i=0;i<n;i++) scanf("%s",map[i]); } inline int inmap(int x,int y) { return x>=0&&y>=0&&x<n&&y<m; } const int dx[]={0,0,1,-1},dy[]={1,-1,0,0}; void … Continue reading

Posted in poj | Leave a comment

Poj Solution 1371

http://poj.org/problem?id=1371 #include <iostream> #include <algorithm> #include <memory.h> using namespace std; int x[200], y[200], xn, yn, n, m; struct { int x1, x2, y1, y2; }ln[100]; char map[414][414]; bool init() { int i, j, l, r, u, d, k; cin >> … Continue reading

Posted in poj | Leave a comment

Poj Solution 1368

http://poj.org/problem?id=1368 #include<iostream> #include"memory.h" using namespace std; int set[3][3][3][3]; int map[7][7][4]; int n,m; int div(char c) {switch(c) {case ‘O’:return 0; case ‘F’:return 1; case ‘I’:return 2; default:return -1; } } void init() {int i,j,a[4];char c; memset(set,0,81*sizeof(int)); for(i=0;i<n*m;i++) {for(j=0;j<4;j++) {cin>>c;a[j]=div(c);} set[a[0]][a[1]][a[2]][a[3]]++; } … Continue reading

Posted in poj | Leave a comment

Poj Solution 1366

http://poj.org/problem?id=1366 //* @author: <strong>Yeming&nbsp;Hu</strong>&quot;cslittleye@gmail.com&quot; import java.util.*; import java.io.*; public class Main { public static BufferedInputStream bis; public static StringBuilder str; public static char[][] rules; public static StringBuilder[] words; public static int k; public static void main(String[] args) throws Exception { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1365

http://poj.org/problem?id=1365 import java.util.*; import java.math.*; public class Main { /** * @param args */ static int pp; static int[] p = new int[30000]; static int[] w = new int[30000]; static boolean[] q = new boolean[35000]; static void init() { int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1363

http://poj.org/problem?id=1363 import java.util.*; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int in[]=new int[1001]; int out[]=new int[1001]; int stack[]=new int[1001]; int n; int i,j; for(i=0;i< 1001;i++) in[i]=i+1; while(sc.hasNext()) { n=sc.nextInt(); if(n==0) break; while(true) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1362

http://poj.org/problem?id=1362 //* @author: <strong>Yeming&nbsp;Hu</strong>&quot;cslittleye@gmail.com&quot; import java.util.*; public class Main { public static final int max = 30; public static void main(String[] args) { int[] weights = new int[max]; int p = 2; for(int i = 0; i < max; i++) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1354

http://poj.org/problem?id=1354 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()) { int n = scan.nextInt(); if (n == -1) { break; } BigDecimal nn = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1353

http://poj.org/problem?id=1353 //* @author: import java.util.*; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int a[]=new int[200],b[]=new int[200]; int n,m,k; while(sc.hasNext()) { String s=sc.nextLine(); Scanner scan=new Scanner(s); scan.useDelimiter(","); n=scan.nextInt(); if(n==-1) break; m=scan.nextInt(); k=scan.nextInt(); for (int i=1;i<=n;i++) { if … Continue reading

Posted in poj | Leave a comment

Poj Solution 1351

http://poj.org/problem?id=1351 /* @author:zeropinzuo */ import java.io.*; import java.util.*; public class Main{ static Scanner cin; static long[] f,g; public static void main(String args[]){ cin = new Scanner(System.in); f = new long[17]; g = new long[17]; g[1]=4; g[2]=14; for(int i=3;i< 17;i++) g[i]=3*g[i-1]+2*g[i-2]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1350

http://poj.org/problem?id=1350 //* @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(true) { String num = sc.next(); if(num.equals("-1")) { break; } System.out.println("N="+num+":"); if(num.length()!=4||(num.charAt(0)==num.charAt(1)&& num.charAt(1)==num.charAt(2)&& num.charAt(2)==num.charAt(3))) { System.out.println("No!!"); }else { int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1344

http://poj.org/problem?id=1344 //* @author: import java.util.*; public class Main { static int value[][]=new int[50][50]; static int ans,n; static void calc() { int i, j, temp, k, s; for( k=0; k< n-2; k++ ) { s = 10000000; for( i = k+1; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1338

http://poj.org/problem?id=1338 //* @author mekarlos@gmail.com import java.util.Scanner; import java.util.Vector; public class Main { public static void main(String[] args) { Scanner scan=new Scanner(System.in); Vector< Long> v=new Vector< Long>(); v.add(new Long(1)); int i=0,j=0,k=0; while(v.size()< 1500){ v.add(Math.min(Math.min(v.get(i)*2, v.get(j)*3), v.get(k)*5)); if(v.get(v.size()-1).equals(v.get(v.size()-2))){v.remove(v.size()-1);} if(v.get(i)*2==v.get(v.size()-1))i++; else if(v.get(j)*3==v.get(v.size()-1))j++; else … Continue reading

Posted in poj | Leave a comment

Poj Solution 1337

http://poj.org/problem?id=1337 //* @author: import java.util.*; public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); int ans[]=new int[300]; int a[]=new int[100],d[]=new int[100],t[]=new int[100]; int cas, i, j, n, temp; boolean key; cas=in.nextInt(); while(( cas– )!=0) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1331

http://poj.org/problem?id=1331 //* @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) { String s1=in.next(); String s2=in.next(); String s3=in.next(); int max=0; for(int i=0;i< s1.length();i++) { char c=s1.charAt(i); int u=c-48; if(max< … Continue reading

Posted in poj | Leave a comment

Poj Solution 1330

http://poj.org/problem?id=1330 import java.util.*; @SuppressWarnings("unchecked") public class Main { int MAX = 10001; Vector< Integer> tree[] = new Vector[MAX + 1];; // 树结构 byte[] flag = new byte[MAX]; // 入度标志,用于寻找根节点 int parent[] = new int[MAX];; int rank[] = new int[MAX];; int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1328

http://poj.org/problem?id=1328 import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; /** * * @author 小e * * 2010-6-12 下午01:48:35 */ public class Main { static class Range implements Comparable<Range>{ double left,right; public Range(double left,double right){ this.left = left; this.right = right; } @Override … Continue reading

Posted in poj | Leave a comment

Poj Solution 1326

http://poj.org/problem?id=1326 import java.util.*; import java.text.*; class FRecord { String from; String to; int miles; String type; public FRecord(String a, String b, int c, String d) { this.from = a; this.to = b; this.miles = c; this.type = d; } } … Continue reading

Posted in poj | Leave a comment

Poj Solution 1325

http://poj.org/problem?id=1325 #include <iostream> #include<cstdio> #include<cstring> using namespace std; #define size 101 int g[size][size]; //ƥ��ͼ int visited[size]; //x�����ʱ�־ int m,n; //n:x������Ŀ��m:y����Ŀ int My[size], Mx[size]; //ƥ���� int Q[size], prev[size]; int BFS_MaxMatch(void) { int res = 0, i, u, v; int head, tail; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1323

http://poj.org/problem?id=1323 #include<iostream> #include<algorithm> using namespace std; const int mMax = 22; const int nMax = 52; struct data{ int num; bool my; bool small; }card[mMax * nMax]; int main(){ int m , n, i, j, t = 1; while(cin >> … Continue reading

Posted in poj | Leave a comment

Poj Solution 1321

http://poj.org/problem?id=1321 #include <iostream> using namespace std; int map[10][10]; int vis[10]; int n,k,ans; void dfs(int col,int cnt) { int i; if(cnt==k) { ans++ ; return ; } if(n-col<k-cnt-1) return ; for(i=1;i<=n;i++) { if(!vis[i]&&map[col][i]) { vis[i]=1; dfs(col+1,cnt+1); vis[i]=0; } } dfs(col+1,cnt); } … Continue reading

Posted in poj | Leave a comment

Poj Solution 1320

http://poj.org/problem?id=1320 /* @author:zeropinzuo */ import java.io.*; import java.util.*; public class Main{ public static void main(String args[]){ int[] array = new int[10]; array[0]=6; array[1]=35; for(int i=2;i< 10;i++) array[i] = 6*array[i-1]-array[i-2]; for(int i=0;i< 10;i++){ //System.out.println(" "+array[i]+" "+(Math.sqrt(8*array[i]*array[i]+1)-1)/2); } System.out.println(" "+6+" "+8); System.out.println(" … Continue reading

Posted in poj | Leave a comment

Poj Solution 1319

http://poj.org/problem?id=1319 //* @author: import java.util.*; public class Main { static final double l = Math.sqrt(3)/2; static int calc( double x, double y ) { int a[]=new int[2], s, i; double h; if( x < 1 ) return 0; a[0] = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1318

http://poj.org/problem?id=1318 import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); List< String> s1 = new ArrayList< String>(); List< String> s2 = new ArrayList< String>(); int indexS1 = 0; int indexS2 = 0; … Continue reading

Posted in poj | Leave a comment