Author Archives: toad, die

Poj Solution 1612

http://poj.org/problem?id=1612 #include<iostream> using namespace std; int dis[50][50],n; void init() { char c; int i,j,k; cin>>n; for(i=0;i<n;i++) { for(j=0;j<n;j++) dis[i][j]=9999; dis[i][i]=0; } for(i=0;i<n;i++) { cin.get(c); while(cin.peek()!=’n’) { cin>>j; dis[i][j-1]=1; dis[j-1][i]=1; } } for(k=0;k<n;k++) for(i=0;i<n;i++) for(j=0;j<n;j++) if(dis[i][k]<9999&&dis[k][j]<9999&&dis[i][k]+dis[k][j]<dis[i][j]) dis[i][j]=dis[i][k]+dis[k][j]; } void doit() { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1611

http://poj.org/problem?id=1611 import java.util.Arrays; import java.util.Scanner; public class Main { static int[] student; static int[] ans; public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); int m = sc.nextInt(); if (n == … Continue reading

Posted in poj | Leave a comment

Poj Solution 1609

http://poj.org/problem?id=1609 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { static final int N = 100+10; static int point[][] = new int[N][N],DP[][] = new int[N][N]; static void init(){ for(int i=0;i< N;++i) for(int j=0;j< N;++j) point[i][j] = 0; } … Continue reading

Posted in poj | Leave a comment

Poj Solution 1607

http://poj.org/problem?id=1607 //* @author popop0p0popo import java.util.*; import java.io.*; public class Main{ public static void main(String[] args) throws Exception{ Scanner scanner=new Scanner(new BufferedReader(new InputStreamReader(System.in))); System.out.printf("Cards Overhangn"); int n; double d; while (scanner.hasNext()){ n=scanner.nextInt(); d=0; for (int i=1;i<=n ;i++ ){ d=d+1.0/(2*i); } … Continue reading

Posted in poj | Leave a comment

Poj Solution 1604

http://poj.org/problem?id=1604 //* @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}; while(in.hasNext()) { int n=in.nextInt(); int e,a2=0,a3=0,a5=0,a7=0,a9=0; e=n;while((e=e/2)!=0) a2+=e; e=n;while((e=e/5)!=0) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1603

http://poj.org/problem?id=1603 //* @author: 82638882@163.com import java.util.Scanner; public class Main { static int[][] w=new int[21][21]; static final int n=20; public static void main(String[] args) { Scanner in=new Scanner(System.in); int cnt=0; while(in.hasNext()) { cnt++; for(int i=0;i< n;i++) for(int j=0;j< n;j++) w[i][j]=9999999; for(int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1598

http://poj.org/problem?id=1598 //* @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))); String[] kws; String[] exs,exsk; int[] kn; String fl; int n,m,max; int index=1; while (scanner.hasNext()){ fl=scanner.nextLine(); String[] t=fl.split(" "); n=Integer.parseInt(t[0]); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1597

http://poj.org/problem?id=1597 //* @author mekarlos@gmail.com import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan=new Scanner(System.in); int s=0,m=0,ac=0; boolean[] bands; boolean flaj; while(scan.hasNext()){ s=scan.nextInt(); m=scan.nextInt(); bands=new boolean[m+1]; flaj=true; ac=0; for(int i=0;i< m;i++){ if(bands[ac]){ flaj=false; break; } bands[ac]=true; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1595

http://poj.org/problem?id=1595 //* @author: 82638882@163.com import java.util.Scanner; public class Main { public static void main(String[] args) { int[] arr=new int[]{ 1,2,3,5,7,11,13,17,19,23,29,31,37,41, 43,47,53,59,61,67,71,73,79,83,89,97,101,103,107, 109,113,127,131,137,139,149,151,157,163,167,173,179,181,191, 193,197,199,211,223,227,229,233,239,241,251,257,263,269,271, 277,281,283,293,307,311,313,317,331,337,347,349,353,359,367, 373,379,383,389,397,401,409,419,421,431,433,439,443,449,457, 461,463,467,479,487,491,499,503,509,521,523,541,547,557,563, 569,571,577,587,593,599,601,607,613,617,619,631,641,643,647, 653,659,661,673,677,683,691,701,709,719,727,733,739,743,751, 757,761,769,773,787,797,809,811,821,823,827,829,839,853,857, 859,863,877,881,883,887,907,911,919,929,937,941,947,953,967, 971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061, 1063,1069,1087,1091,1093,1097 }; Scanner in=new Scanner(System.in); while(in.hasNext()) { int a=in.nextInt(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1591

http://poj.org/problem?id=1591 //* @author: SmilingWang import java.util.*; public class Main{ public static void main(String[] args){ LinkedList< Integer> list; Scanner in = new Scanner(System.in); int n; int left; int i, j; int count = 1; while(in.hasNext()){ n = in.nextInt(); left = in.nextInt(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1590

http://poj.org/problem?id=1590 //* @author: <strong>Yeming&nbsp;Hu</strong>&quot;cslittleye@gmail.com&quot; import java.util.Scanner; import java.util.Map; import java.util.HashMap; import java.io.BufferedInputStream; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(new BufferedInputStream(System.in)); Map<Character,Character> map = new HashMap<Character,Character>(); map.put(‘A’,’A’); map.put(‘E’,’3′); map.put(‘H’,’H’); map.put(‘I’,’I’); map.put(‘J’,’L’); map.put(‘L’,’J’); map.put(‘M’,’M’); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1581

http://poj.org/problem?id=1581 //* @author mekarlos@gmail.com import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in)); int n=new Integer(stdin.readLine()); String nombre="",winner=""; int sub,pena,solved,time; int maxsolved=0,mintime=0; StringTokenizer tokens; for(int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1580

http://poj.org/problem?id=1580 //* @author: 82638882@163.com import java.util.*; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); while(true) { String s1=in.next(); if(s1.equals("-1"))break; String s2=in.next(); int max=0; for(int i=0;i< s1.length();i++) { int count =0; for(int j=0;j< s2.length();j++) { boolean … Continue reading

Posted in poj | Leave a comment

Poj Solution 1577

http://poj.org/problem?id=1577 //* @author: SmilingWang import java.util.*; public class Main { public static void main(String[] args){ Scanner in =new Scanner(System.in); BinarySearchTree< Character> bt = new BinarySearchTree< Character>(); boolean stop = false; while(true){ String input = in.next(); LinkedList< String> list = new … Continue reading

Posted in poj | Leave a comment

Poj Solution 1576

http://poj.org/problem?id=1576 /* @author:����acmilan_fan@yahoo.cn */ import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s,board; String[] ss; int n; int[] p; boolean flag=false; while((s=br.readLine())!=null&&!s.startsWith("0")){ ss=s.split(" ",3); p=new int[parseInt(ss[0])]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1575

http://poj.org/problem?id=1575 //* @author: 82638882@163.com import java.io.*; public class Main { static int[][] sorce; public static void main(String[] args) throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); while(true) { String s=in.readLine(); if(s.equals("end"))break; boolean bb=true,b1=false,b2; for(int i=0;i< s.length();i++) { if(isv(s.charAt(i))) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1574

http://poj.org/problem?id=1574 /* @author: */ import java.util.*; public class Main { private int x[]; private int y[]; private int z[]; private int a[]=new int[7],b[]=new int[7],c[]=new int[7],ax[]=new int[7],use[]=new int[7]; private int max; public Main(int x[],int y[],int z[]){ this.x=x; this.y=y; this.z=z; max=0; for(int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1566

http://poj.org/problem?id=1566 //* @author: <strong>Yeming&nbsp;Hu</strong>&quot;cslittleye@gmail.com&quot; import java.util.*; import java.io.BufferedInputStream; public class Main { public static int[] numbers = {5,7,5}; public static void main(String[] args) { Scanner sc = new Scanner(new BufferedInputStream(System.in)); sc.useDelimiter("n"); while(true) { String line = sc.next(); line = line.trim(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1564

http://poj.org/problem?id=1564 /* @author: */ import java.util.Scanner; public class Main{ static int sum,n; static int arr[]=new int[20]; static int j,FLAG; static boolean used[]=new boolean[20]; static void f(int now,int total) { int i; if(total==sum) { FLAG=1; for(i=0;i< n;i++) if(used[i]) { System.out.printf("%d",arr[i]); break; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1562

http://poj.org/problem?id=1562 //* @author: 82638882@163.com import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); while(true) { int a=in.nextInt(); int b=in.nextInt(); if(a==0&&b==0)break; int count=0; int[][] arr=new int[a+2][b+2]; for(int i=1;i<=a;i++){ String s=in.next(); for(int j=1;j<=b;j++) arr[i][j]=s.charAt(j-1); } for(int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1555

http://poj.org/problem?id=1555 //* @author: 82638882@163.com import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); while(in.hasNext()) { StringBuffer bb=new StringBuffer(); int[] a=new int[9]; boolean b=true; for(int i=0;i< 9;i++) a[i]=in.nextInt(); for(int i=0;i< 8;i++) { if(a[i]!=0) { if(b){ … Continue reading

Posted in poj | Leave a comment

Poj Solution 1552

http://poj.org/problem?id=1552 import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); while(true) { String temp = cin.nextLine(); if(temp.equals("-1")) break; temp = temp.substring(0, temp.length()-1).trim(); int[] num = new int[15]; String[] str = temp.split(" "); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1548

http://poj.org/problem?id=1548 /* @author: */ import java.util.*; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int x[]=new int[1000], y[]=new int[1000]; boolean sign[]=new boolean[1000]; int a, b, n, m, i, ans; while( true ) { n … Continue reading

Posted in poj | Leave a comment

Poj Solution 1547

http://poj.org/problem?id=1547 import java.util.*; class Clay { private int l = 0; private int w = 0; private int h = 0; private String name; private int size = 0; public Clay(String l, String w, String h, String name) { this.l … Continue reading

Posted in poj | Leave a comment

Poj Solution 1546

http://poj.org/problem?id=1546 import java.io.*; import java.util.*; import java.math.*; /** * * @author gongshaoqing */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner cin=new … Continue reading

Posted in poj | Leave a comment

Poj Solution 1543

http://poj.org/problem?id=1543 //* @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(); for(int i=6;i<=a;i++) { for(int j=2;j< a;j++) for(int m=j;m< a;m++) for(int n=m;n< a;n++) { if((n*n*n+m*m*m+j*j*j)==i*i*i) System.out.println("Cube = "+i+", Triple = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1528

http://poj.org/problem?id=1528 //* @author: 82638882@163.com import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); System.out.println("PERFECTION OUTPUT"); while(true) { int a=in.nextInt(); if(a==0) break; double w=Math.sqrt(a); int total=1; for(int i=2;i< w;i++) { if(a%i==0) total+=(a/i+i); } if(a%w==0) total+=w; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1522

http://poj.org/problem?id=1522 /* @author:zeropinzuo */ import java.io.*; import java.util.*; public class Main{ static Scanner cin; static int count=0; public static void main(String args[]){ cin = new Scanner(System.in); int n; while((n=cin.nextInt())!=0) run(n); } static void run(int n){ Point start,end; start = new … Continue reading

Posted in poj | Leave a comment

Poj Solution 1521

http://poj.org/problem?id=1521 import java.io.BufferedReader; import java.io.InputStreamReader; import java.math.BigDecimal; import java.math.RoundingMode; /** * Accepted. * * * @author hong * */ public class Main { private static Node[] nodes = new Node[1000]; private static boolean[] used = new boolean[1000]; private static int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1520

http://poj.org/problem?id=1520 //* @author: 82638882@163.com import java.util.*; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); while(true) { String s=in.nextLine(); if(s.equals("."))break; s=s.substring(0,s.length()-1); String[] arr=s.split(", "); int l=arr.length; int[] kk=new int[l]; ArrayList< Integer> arrI=new ArrayList< Integer>(); TreeMap< String,String> … Continue reading

Posted in poj | Leave a comment

Poj Solution 1519

http://poj.org/problem?id=1519 //* @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); while (true) { String number = in.next(); if (number.equals("0")) { break; } int len = number.length(); int sum = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1517

http://poj.org/problem?id=1517 //* @author: 82638882@163.com public class Main { public static void main(String[] args) { int i, n, j; double e = 0; System.out.printf("n en- ———–n"); for (n = 0; n <= 9; ++n) { i = 1; for (j = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1515

http://poj.org/problem?id=1515 #include <stdio.h> #include <memory.h> bool e[1000][1000]; int low[1000]; int visit[1000]; int vs,n; void print( int a, int b) { printf( "%d %dn", a+1, b+1 ); } void search( int s, int f ) { int i; visit[s] = vs++; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1511

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

Posted in poj | Leave a comment

Poj Solution 1509

http://poj.org/problem?id=1509 /* @author: */ import java.util.Scanner; public class Main{ public static int minP(String s) { int i = 0, j = 1, k = 0; int l = s.length(); while (true) { if (i + k >= l || j … Continue reading

Posted in poj | Leave a comment

Poj Solution 1505

http://poj.org/problem?id=1505 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { static final int N = 500+10; static int n,m; static boolean flag[] = new boolean[N]; static long sum[] = new long[N],num[] = new long[N]; public static void main(String[]args) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1504

http://poj.org/problem?id=1504 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[] str = new String[2]; String rawA, rawB; int a, b, sum = 0; for(int i = 0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1503

http://poj.org/problem?id=1503 import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); BigDecimal bd1 = BigDecimal.valueOf(0); BigDecimal bd2 = BigDecimal.valueOf(0); String str; while(cin.hasNext()) { str = cin.nextLine(); if(str.equals("0")) break; else { bd2 … Continue reading

Posted in poj | Leave a comment

Poj Solution 1496

http://poj.org/problem?id=1496 //* @author: 82638882@163.com import java.util.*; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); while(in.hasNext()) { String s=in.next(); boolean bb=true; for(int i=0;i< s.length()-1;i++) { if(s.charAt(i)-s.charAt(i+1)>=0) { System.out.println(0); bb=false; break; } } if(!bb)continue; int l=s.length(); long … Continue reading

Posted in poj | Leave a comment

Poj Solution 1493

http://poj.org/problem?id=1493 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { static final int N = 100000; static String str[] = new String[N]; static int n; static void start(){ for(int i=0;i< n;++i) str[i] = new String(); } public static … Continue reading

Posted in poj | Leave a comment

Poj Solution 1491

http://poj.org/problem?id=1491 //* @author ������&lt;hongxp11@163.com&gt; import java.text.DecimalFormat; import java.util.Scanner; import java.util.Vector; public class Main { public static int factor(int a, int b) { if (b == 0) return a; else return factor(b, a % b); } public static void main(String[] args) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1488

http://poj.org/problem?id=1488 #include<stdio.h> int main() { char c; int q=1; while((c=getchar())!=EOF) { if(c == ‘"’) { printf(q ? "“":"”"); q=!q; } else printf("%c",c); } return 0; }

Posted in poj | Leave a comment

Poj Solution 1485

http://poj.org/problem?id=1485 #include <iostream> #define MAX 200000000 using namespace std; long r[300],sum[300][40],one[300][300]; long from[300][40],to[300][40],at[300][40]; long printDetail(long i, long j)//递归输出 { if(j<=0||i<=0) return 1; long num=printDetail(from[i][j]-1,j-1); cout<<"Depot "<<num<<" at restaurant "<<at[i][j]<<" serves ";; if(from[i][j]==to[i][j]) cout<<"restaurant "<<from[i][j]<<endl; else cout<<"restaurants "<<from[i][j]<<" to "<<to[i][j]<<endl; return … Continue reading

Posted in poj | Leave a comment

Poj Solution 1484

http://poj.org/problem?id=1484 //* @author: SmilingWang import java.util.LinkedList; import java.util.Scanner; public class Main { public static void main(String[] args){ int n, m, c; int i, j = 1, k; Scanner scanner = new Scanner(System.in); boolean blowFuse = false; int sumOfPower = 0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1477

http://poj.org/problem?id=1477 //* @author: 82638882@163.com import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); int c=0; while(true) { int a=in.nextInt(); if(a==0)break; c++; int[] arr=new int[a]; int total=0; for(int i=0;i< a;i++) { arr[i]=in.nextInt(); total+=arr[i]; } total/=a; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1476

http://poj.org/problem?id=1476 #include<stdio.h> #define debug 0 #define NMAX 20 #define DMAX 30 #define INF 1000000000 #define KMAX 1001 long d[KMAX][NMAX]; int main() { #if debug freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int T=1,N,K,i,j,k; long c[NMAX+1][NMAX+1][DMAX+1]; int t[NMAX+1][NMAX+1]; scanf("%d%d",&N,&K); while(N&&K) { for(i=1;i<=N;i++) for(j=1;j<=N;j++) { if(i!=j) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1474

http://poj.org/problem?id=1474 #include<iostream> using namespace std; int xmin,ymin,xmax,ymax,n; int main() {int i,xn,yn,xp,yp,dx,dy,c_n=0; while(1) {cin>>n; if(!n)break; xmin=-32000;ymax=32000; xmax=-xmin;ymin=-ymax; cin>>xp>>yp; dx=xp;dy=yp; for(i=0;i<n;i++) {if(i<n-1)cin>>xn>>yn;else {xn=dx;yn=dy;} if(yn==yp){if(xn>xp){if(yp<ymax)ymax=yn;} else if(yp>ymin)ymin=yn; } else {if(yn>yp){if(xn>xmin)xmin=xn;} else if(xn<xmax)xmax=xn; } xp=xn;yp=yn; } cout<<"Floor #"<<++c_n<<endl; if(xmin<=xmax&&ymin<=ymax)cout<<"Surveillance is possible."<<endl<<endl; else cout<<"Surveillance is … Continue reading

Posted in poj | Leave a comment

Poj Solution 1473

http://poj.org/problem?id=1473 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<string.h> #include<math.h> #define sq2 0.70710678118654752440084436210485 #define INF 30000 #define NMAX 52 int p[10]={0}; int as[10]={0}; double xd[8]={0,sq2,1,sq2,0,-sq2,-1,-sq2}; double yd[8]={1,sq2,0,-sq2,-1,-sq2,0,sq2}; double cx,cy; void findpos(char *s) { s[strlen(s)-1]=0; int len; char direct[4]; sscanf(s,"%d%s",&len,direct); int d; if(!strcmp("NE",direct)) d=1; else … Continue reading

Posted in poj | Leave a comment

Poj Solution 1472

http://poj.org/problem?id=1472 /* @author: */ import java.io.BufferedInputStream; import java.util.Scanner; import java.util.Arrays; class Main { public static Scanner cin=new Scanner(new BufferedInputStream(System.in)); public static int [] coef=new int[11]; public static String temp; public static void work(int con,int expo) { while (true) { temp=cin.next(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1471

http://poj.org/problem?id=1471 #include<iostream> #include<stdlib.h> #include<stdio.h> using namespace std; #define MAXNO 102 int tr[MAXNO][2*MAXNO-1]={0}; int maxtr[MAXNO][2*MAXNO-1]={0}; int curmax=0; int min(int a,int b) { if(a>b) return b; else return a; } int sum(int a1,int an,int n) { return (a1+an)*n/2; } int ln(int n) … Continue reading

Posted in poj | Leave a comment