Monthly Archives: March 2013

Poj Solution 2437

http://poj.org/problem?id=2437 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; class POOL implements Comparable{ int left,right; public int compareTo(Object oo){ POOL temp = (POOL) oo; if(temp.left< this.left) return 1; return -1; } } public class Main { static final int N = … Continue reading

Posted in poj | Comments Off on Poj Solution 2437

Poj Solution 2436

http://poj.org/problem?id=2436 //* @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[] ss=in.readLine().split(" "); int n=Integer.parseInt(ss[0]); int d=Integer.parseInt(ss[1]); int k=Integer.parseInt(ss[2]); int[] q=new int[n]; for(int i=0;i< n;i++) { … Continue reading

Posted in poj | Comments Off on Poj Solution 2436

Poj Solution 2435

http://poj.org/problem?id=2435 #include <stdio.h> #include <queue> using namespace std; typedef pair<int,int> point; int dx[] = { 0, 1,-1, 0}; int dy[] = { 1, 0, 0,-1}; char way[] = { ‘-‘,’|’,’|’,’-‘}; char to[] = { ‘E’,’S’,’N’,’W’}; int n,m,bx,by,ex,ey; bool sign[100][100]; char … Continue reading

Posted in poj | Comments Off on Poj Solution 2435

Poj Solution 2431

http://poj.org/problem?id=2431 #include<iostream> #include"algorithm" using namespace std; const int size=10010; struct stop { int f,x; }p[size]; int n,l,h; bool cmp(stop a,stop b) { return a.x>b.x; } void init() { int i; cin>>n; for(i=0;i<n;i++) { cin>>p[i].x>>p[i].f; } cin>>l>>h; p[n+1].x=l;p[n+1].f=0; p[n].x=0;p[n].f=0; n+=2; std::sort(p,p+n,cmp); … Continue reading

Posted in poj | Comments Off on Poj Solution 2431

Poj Solution 2430

http://poj.org/problem?id=2430 #include<iostream> #include"algorithm" using namespace std; const int size=1010; int ans[size][size][4]; int best[size][size]; int n,m,b,nn; enum{both,up,down,sep}; const int inf=99999999; struct point { int y; int x; int s; }pt[size],p[size]; bool cmp(point a,point b) { return a.x<b.x; } void init() { … Continue reading

Posted in poj | Comments Off on Poj Solution 2430

Poj Solution 2428

http://poj.org/problem?id=2428 #include<iostream> #include"stdio.h" #include"math.h" using namespace std; struct point { double x,y,z; }p1[110],p2[110],p3[110]; int n,m; double best[110][110]; double cross(point a,point b,point c) { b.x-=a.x;b.y-=a.y;b.z-=a.z; c.x-=a.x;c.y-=a.y;c.z-=a.z; double s1,s2,s3; s1=b.y*c.z-b.z*c.y; s2=b.z*c.x-b.x*c.z; s3=b.x*c.y-b.y*c.x; return sqrt(s1*s1+s2*s2+s3*s3); } int init(void) { int i;double s1,s2; cin>>n; … Continue reading

Posted in poj | Comments Off on Poj Solution 2428

Poj Solution 2427

http://poj.org/problem?id=2427 //* @author import java.util.*; import java.math.*; public class Main { static BigInteger p1,p2,p3,q1,q2,q3,a1,a2,a0,h1,h2,g1,g2,p,q; static int nn; static void solve(){ p2=BigInteger.ONE; p1=BigInteger.ZERO; q2=BigInteger.ZERO; q1=BigInteger.ONE; a1=BigInteger.valueOf((long)Math.sqrt(nn)); a0=BigInteger.valueOf((long)Math.sqrt(nn)); g1=BigInteger.ZERO;h1=BigInteger.ONE; BigInteger n0=BigInteger.valueOf(nn); while(true){ g2=a1.multiply(h1).subtract(g1); h2=(n0.subtract(g2.multiply(g2))).divide(h1); a2=g2.add(a0).divide(h2); p=p2.multiply(a1).add(p1); q=q2.multiply(a1).add(q1); if(p.multiply(p).subtract(n0.multiply(q.multiply(q))).compareTo(BigInteger.ONE)==0) return ; a1=a2; g1=g2; … Continue reading

Posted in poj | Comments Off on Poj Solution 2427

Poj Solution 2425

http://poj.org/problem?id=2425 #include <vector> #include <iostream> using namespace std; vector<int> edges[1000]; int N,M,GS[1000],ans; int DFS(int n) /* 典型求 SG 函数的办法 */ { if(GS[n]!=-1) return GS[n]; bool used[1000]; memset(used,0,sizeof(used)); for(int i=0;i<edges[n].size();i++) { used[DFS(edges[n][i])]=true; } int i=0; while(used[i]) i++; return GS[n]=i; } int … Continue reading

Posted in poj | Comments Off on Poj Solution 2425

Poj Solution 2424

http://poj.org/problem?id=2424 #include"queue" #include"stdio.h" using namespace std; struct node { int time; int dinners; }; int a[3],ans; queue<node> have[3]; bool init() { char c,t; int u[3],t1,t2,i; node nd,nd1; //cin>>a[0]>>a[1]>>a[2]; scanf("%d%d%d",&a[0],&a[1],&a[2]); if(a[0]==0&&a[1]==0&&a[2]==0) return 0; for(i=0;i<3;i++) { while(!have[i].empty()) have[i].pop(); } ans=0; u[0]=0,u[1]=0,u[2]=0; while(1) … Continue reading

Posted in poj | Comments Off on Poj Solution 2424

Poj Solution 2421

http://poj.org/problem?id=2421 //* @author: 82638882@163.com import java.util.Scanner; public class Main { static int[] bin; public static void main(String[] args) { Scanner in=new Scanner(System.in); int a=in.nextInt(); int[][] p=new int[a][a]; for(int i=0;i< a;i++) for(int j=0;j< a;j++) p[i][j]=in.nextInt(); bin=new int[a]; for(int i=0;i< a;i++) bin[i]=i; … Continue reading

Posted in poj | Comments Off on Poj Solution 2421

Poj Solution 2420

http://poj.org/problem?id=2420 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; import java.math.*; class Point{ double x,y; } public class Main { static int n; static final int N = 100+10; static Point point[] = new Point[N]; static void start(){ for(int i=0;i< N;++i) … Continue reading

Posted in poj | Comments Off on Poj Solution 2420

Poj Solution 2419

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

Posted in poj | Comments Off on Poj Solution 2419

Poj Solution 2418

http://poj.org/problem?id=2418 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static class TreeNode{ private String species; private TreeNode left; private TreeNode right; private int count; } public static class Tree{ private int total; private TreeNode root=new TreeNode(); public … Continue reading

Posted in poj | Comments Off on Poj Solution 2418

Poj Solution 2415

http://poj.org/problem?id=2415 #include<iostream> #include"queue" #include"algorithm" using namespace std; char edge[51][51]; int sign[51][51][51],n,p1,p2,p3; struct node { int p[3]; int steps; }; queue<node> q; bool init() { int i,j,k; cin>>n>>p1>>p2>>p3; if(n==0)return 0; for(i=0;i<n;i++) for(j=0;j<n;j++) cin>>edge[i][j]; for(i=0;i<n;i++) for(j=0;j<n;j++) for(k=0;k<n;k++) sign[i][j][k]=0; while(!q.empty()) q.pop(); return 1; … Continue reading

Posted in poj | Comments Off on Poj Solution 2415