Monthly Archives: January 2014

Poj Solution 2635

http://poj.org/problem?id=2635 //* @author import java.io.*; import java.util.*; import java.math.*; public class Main { static boolean h[]; public static void main(String[] args) { int m,i,j=2; h=new boolean[1000005]; BigInteger n,p,q,nn; for(i=1;i<=1000001;i++) h[i]=true; for(i=2;i<=1000001;i+=2) h[i]=false; h[1]=false;h[2]=true; for(i=3;i<=1000;i+=2) { if(h[i]==true) { j=2; while(i*j<=1000000) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 2632

http://poj.org/problem?id=2632 import java.util.Scanner; enum Direction { N, S, W, E } class Robot { int id; int x; int y; Direction direction; public Robot(int i, int x, int y, String direction) { this.id = i; this.x = x; this.y = … Continue reading

Posted in poj | Leave a comment

Poj Solution 2629

http://poj.org/problem?id=2629 //* @author mekarlos@gmail.com import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in)); String s=""; int[] l1,l2; while(stdin.ready()){ l1=new int[26];l2=new int[26]; s=stdin.readLine().trim(); for(int i=0;i< s.length();i++){ l1[(int)(s.charAt(i)-‘a’)]++; } … Continue reading

Posted in poj | Leave a comment

Poj Solution 2624

http://poj.org/problem?id=2624 /* @author: */ import java.util.Scanner; import java.util.Arrays; public class Main{ public static void main(String args[]) { Scanner sc=new Scanner(System.in); double x1,y1,x2,y2,x3,y3,x4,y4,x5=0,y5=0; while(sc.hasNext()) { x1=sc.nextDouble(); y1=sc.nextDouble(); x2=sc.nextDouble(); y2=sc.nextDouble(); x3=sc.nextDouble(); y3=sc.nextDouble(); x4=sc.nextDouble(); y4=sc.nextDouble(); if(x1==x3&&y1==y3) { x5=x4-x3+x2; y5=y4-y3+y2; } else if(x1==x4&&y1==y4) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 2623

http://poj.org/problem?id=2623 //* @author: 82638882@163.com import java.io.*; import java.util.*; public class Main {//1979 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()); int[] arr=new int[a+1]; for(int i=1;i<=a;i++) arr[i]=Integer.parseInt(in.readLine()); Arrays.sort(arr); double t; if(a%2==0)t=arr[a/2]/2.0+arr[a/2+1]/2.0; else t=arr[(a+1)/2]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2619

http://poj.org/problem?id=2619 /* @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 a,b; a=sc.nextInt(); b=sc.nextInt(); int p1,p2,p3,d1,d2,d3; p1=(int)Math.sqrt(a*1.0); if(p1*p1< a) p1++; d1=(int)Math.sqrt(b*1.0); if(d1*d1< b) d1++; int v1=(p1-1)*(p1-1); int v2=(d1-1)*(d1-1); p2=(a-v1+1)/2; d2=(b-v2+1)/2; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2613

http://poj.org/problem?id=2613 /* @author: */ import java.util.Scanner; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int a[]=new int[3],b[]=new int[3],c[]=new int[3],d[]=new int[3],p,q,r,s; int maxn; double sum; int i,flag; maxn=100000001; while(sc.hasNext()) { p=sc.nextInt(); q=sc.nextInt(); r=sc.nextInt(); s=sc.nextInt(); a[0]=p;a[1]=s;a[2]=r-s;b[0]=r;b[1]=q;b[2]=p-q; for(i=0;i< 3;i++)c[i]=d[i]=2; sum=1;flag=1; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2612

http://poj.org/problem?id=2612 #include<iostream> #include<string> #include<cstdlib> using namespace std; int main() { char mine[15][15]; char touch[15][15]; char board[15][15]; int i,j,n,num=0; bool flag=false; scanf("%d",&n); for(i=0;i<n;i++) scanf("%s",mine[i]); for(i=0;i<n;i++) scanf("%s",touch[i]); for(i=0;i<n;i++) for(j=0;j<n;j++) { if(touch[i][j]==’x’) { if(mine[i][j]==’*’) { flag=true; board[i][j]=’*’; } else if(mine[i][j]==’.’) { if((j-1)>=0&&mine[i][j-1]==’*’) num++; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2610

http://poj.org/problem?id=2610 //* @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); double x1 = in.nextDouble(); double y1 = in.nextDouble(); double x2 = in.nextDouble(); double y2 = in.nextDouble(); //double r1 = 0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2608

http://poj.org/problem?id=2608 #include<iostream> #include<string> #include<map> #include<cstdlib> #include<algorithm> using namespace std; char ss[21]; int a[21]; int main() { map<char,int>m; m[‘B’]=1; m[‘A’]=0; m[‘F’]=1; m[‘E’]=0; m[‘P’]=1; m[‘I’]=0; m[‘V’]=1; m[‘O’]=0; m[‘C’]=2; m[‘U’]=0; m[‘G’]=2; m[‘H’]=0; m[‘J’]=2; m[‘W’]=0; m[‘K’]=2; m[‘Y’]=0; m[‘Q’]=2; m[‘S’]=2; m[‘Z’]=2; m[‘X’]=2; m[‘D’]=3; m[‘T’]=3; m[‘L’]=4; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2607

http://poj.org/problem?id=2607 #include <cstdio> const int M = 505, INF = 1000000000; int mp[M][M], n, m, f[105]; int main () { int i, j, k, x, y, d, u, ans, Max, Min; while ( scanf("%d %d", &m, &n) != EOF ) … Continue reading

Posted in poj | Leave a comment

Poj Solution 2606

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

Posted in poj | Leave a comment

Poj Solution 2604

http://poj.org/problem?id=2604 #include <iostream> #include <string> #include <vector> using namespace std; typedef vector<string>::size_type VST; vector<string> v; char Stack[1000]; int pos[1000]; int vpos[1000]; int top = 0; void process() { bool bEnd; for (VST i = 0;i < v.size();i++) { if (v[i].empty()) … Continue reading

Posted in poj | Leave a comment