Author Archives: toad, die

Poj Solution 3039

http://poj.org/problem?id=3039 /* @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 a,b,e,min; int c,d,u=0,v=0; a=sc.nextDouble(); b=sc.nextDouble(); a=a/b; c=d=1; min=32768; while(c< 32768&&d<32768) { e=c*1.0/d*1.0; if(e==a){ d++; continue; } if(e>a){ if(e-a< min){ … Continue reading

Posted in poj | Leave a comment

Poj Solution 3036

http://poj.org/problem?id=3036 #include <stdio.h> int ans[20][40][40] = { 0 }; int main( ) { int i, j, k, t; ans[0][20][20] = 1; for( i=0; i<14; i++ ) { for( j=1; j<39; j++ ) for( k=1; k<39; k++ ) { t = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3032

http://poj.org/problem?id=3032 //* @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(); while((a–)!=0) { int b=in.nextInt(); int[] arr=new int[b]; int u=0; for(int i=1;i<=b;i++) { int y=i; while(true) { if(arr[u]==0) y–; if(y==-1) … Continue reading

Posted in poj | Leave a comment

Poj Solution 3030

http://poj.org/problem?id=3030 //* @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=scanner.nextInt(); int r,e,c; for (int i=0;i< n ;i++ ){ r=scanner.nextInt(); e=scanner.nextInt(); c=scanner.nextInt(); if (r< e-c){ System.out.println("advertise"); } else … Continue reading

Posted in poj | Leave a comment

Poj Solution 3027

http://poj.org/problem?id=3027 /* @author:����acmilan_fan@yahoo.cn */ import java.util.*; public class Main { static public void main( String [] str ){ Scanner sc=new Scanner(System.in); int tt=sc.nextInt(); while(( tt–)!=0 ) { int a, b, r1, r2, t, r, s; a=sc.nextInt(); b=sc.nextInt(); r1=sc.nextInt(); r2=sc.nextInt(); for( … Continue reading

Posted in poj | Leave a comment

Poj Solution 3026

http://poj.org/problem?id=3026 import java.io.PrintWriter; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main { static class Point{ int x,y,step; int result = 1; char c; public Point(int x, int y, char c){ this.x = x; this.y = y; this.c = c; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3017

http://poj.org/problem?id=3017 //* @author: <strong>Yeming&nbsp;Hu</strong>&quot;cslittleye@gmail.com&quot; import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(new BufferedInputStream(System.in)); Container cn= new Container(); boolean noSuchCut =false; int n = sc.nextInt(); long m = sc.nextLong(); Wrapper[] … Continue reading

Posted in poj | Leave a comment

Poj Solution 3014

http://poj.org/problem?id=3014 import java.util.*; import java.io.*; public class Main{ static int dp[][]=new int[4501][4501]; public static void main(String args[]){ Scanner scan = new Scanner(new BufferedInputStream(System.in)); while(scan.hasNext()) { int n = scan.nextInt(); int m = scan.nextInt(); System.out.println(f(n, m)); } } public static int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3012

http://poj.org/problem?id=3012 #include <stdio.h> int main( ) { int n, k, m, t, i; __int64 a[32], ans, temp; scanf( "%d", &t ); while( t– ) { scanf( "%d%d%d", &n, &k, &m ); a[0] = 10%m; ans = 1; temp = 1; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3009

http://poj.org/problem?id=3009 //* @author import java.util.*; public class Main { static final int MAX= 30; static int w,h; static int start_x,start_y; static int flag[][] = new int[MAX][MAX]; static int min=11; static int step=1; static void dfs(int x,int y,int step) { if(step>10) … Continue reading

Posted in poj | Leave a comment

Poj Solution 3006

http://poj.org/problem?id=3006 //* @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))); while (true){ int a=scanner.nextInt(); int d=scanner.nextInt(); int n=scanner.nextInt(); if (a+d+n==0){ break; } int index=0; int i=0; while (index< n){ … Continue reading

Posted in poj | Leave a comment

Poj Solution 3002

http://poj.org/problem?id=3002 /* @author: */ import java.util.Scanner; import java.util.Arrays; public class Main{ static long gcd(long a,long b) { if(b==0) return a; return gcd(b,a%b); } public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t,n,i; long p[]=new long[6]; t=sc.nextInt(); while((t–)!=0) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 2996

http://poj.org/problem?id=2996 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class Main { class Compara implements Comparator< String[]> { public int compare(String[] o1, String[] o2) { if (o1[1].charAt(1) == o2[1].charAt(1)) { return o1[1].charAt(0) – … Continue reading

Posted in poj | Leave a comment

Poj Solution 2993

http://poj.org/problem?id=2993 //* @author: 82638882@163.com import java.util.*; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); char[][] arr=new char[8][8]; String s1=in.nextLine(); s1=s1.substring(7); String[] ws=s1.split(","); for(int i=0;i< ws.length;i++) { if(ws[i].length()==3) { int x=8-ws[i].charAt(2)+’0′; int y=ws[i].charAt(1)-‘a’; arr[x][y]=ws[i].charAt(0); } else … Continue reading

Posted in poj | Leave a comment

Poj Solution 2992

http://poj.org/problem?id=2992 //* @author: 82638882@163.com import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); int[] prime=new int[] { 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 }; int[] arr=new int[84]; while(in.hasNext()) { int c=in.nextInt(); int n=in.nextInt(); int … Continue reading

Posted in poj | Leave a comment

Poj Solution 2985

http://poj.org/problem?id=2985 #include "stdio.h" #include "memory.h" int tree[600000]; int k, key; void set( int l, int r, int s ) { int c = (l+r)/2; tree[s] += key; if( r == l+1 ) return; if( k < c ) set( l, … Continue reading

Posted in poj | Leave a comment

Poj Solution 2984

http://poj.org/problem?id=2984 //* @author import java.io.*; import java.util.*; import java.math.*; public class Main { public static int a[]; public static int luckpeople(int n) { if(n==1) return 1; if(n%2==1) return luckpeople((n-1)/2)*2+1; else return luckpeople(n/2)*2-1; } public static int fun(int n) { int … Continue reading

Posted in poj | Leave a comment

Poj Solution 2983

http://poj.org/problem?id=2983 //* @author: import java.io.*; import java.util.Scanner; /* *SPFA �����Լ������.һ��ʼû���Դ��һֱWA….- -!~~~~ */ class Node { int dian,value; Node next; Node(int x,int h) { dian=x; value=h; next=null; } void insert(Node a) { next=a; } } class Point { int dian; Node … Continue reading

Posted in poj | Leave a comment

Poj Solution 2982

http://poj.org/problem?id=2982 #include "stdio.h" #include "memory.h" int cast[111][111]; int a[111], b[111], c[111]; int n, m, k; bool sign[111]; int main() { int i, j, l, s, x, y, h; while( 1 ) { scanf( "%d%d%d", &n, &m, &k ); if( !n … Continue reading

Posted in poj | Leave a comment

Poj Solution 2976

http://poj.org/problem?id=2976 //* @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 i,j,n,k; while (sc.hasNext()) { n=sc.nextInt(); k=sc.nextInt(); if(n==0) break; int num[]=new int[n]; int den[]=new int[n]; double scores[]=new double[n]; for (i=0;i< n;i++) num[i]=sc.nextInt(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 2967

http://poj.org/problem?id=2967 //* @author: 82638882@163.com import java.util.*; 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); int a=Integer.parseInt(in.readLine()); int[] arr=new int[a]; int u,total; for(int i=0;i< a;i++) { total=0; while(true) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 2959

http://poj.org/problem?id=2959 //* @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(); while((a–)!=0) { double D=in.nextDouble(); double d=in.nextDouble(); double s=in.nextDouble(); System.out.printf("%dn", (int)(Math.PI/Math.asin((d+s)/(D-d)))); } } }

Posted in poj | Leave a comment

Poj Solution 2954

http://poj.org/problem?id=2954 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; class Point{ int x,y; } public class Main { static Point triangle[] = new Point[3]; static int GCD(int a,int b){ if(b==0) return a; return GCD(b,a%b); } static int area(Point a,Point b,Point c){ … Continue reading

Posted in poj | Leave a comment

Poj Solution 2945

http://poj.org/problem?id=2945 import java.util.HashMap; import java.util.Scanner; public class Main { 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 == 0 && m == 0) break; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2941

http://poj.org/problem?id=2941 //* @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); while(true) { String s=in.readLine(); int a=Integer.parseInt(s); if(a==0)break; int[][] arr=new int[a][a]; String[] ss; for(int i=0;i< a;i++) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 2940

http://poj.org/problem?id=2940 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { static final int N = 100000+100; static int n; static long num[] = new long[N]; public static double Get_Num(StreamTokenizer cin) throws Exception{ cin.nextToken(); return cin.nval; } public static … Continue reading

Posted in poj | Leave a comment

Poj Solution 2939

http://poj.org/problem?id=2939 #include <algorithm> #include <cstdio> #include <string.h> #include <map> #include <stack> #include <memory.h> #include <math.h> #include <queue> using namespace std; #define count dofudf const int prime = 3374521; int hash[prime] = { 0 }; int num[prime]; int id[prime]; int count … Continue reading

Posted in poj | Leave a comment

Poj Solution 2938

http://poj.org/problem?id=2938 #include <algorithm> #include <cstdio> #include <string> #include <map> #include <stack> #include <memory.h> #include <math.h> #include <queue> using namespace std; string str[1100]; int year[1100]; int ans[1100]; int doit( int l, int r ) { int i, j, b, e; ans[l] … Continue reading

Posted in poj | Leave a comment

Poj Solution 2937

http://poj.org/problem?id=2937 #include <algorithm> #include <cstdio> #include <string.h> #include <map> #include <stack> #include <memory.h> #include <math.h> #include <queue> using namespace std; int main( ) { int n, pos, t, s; char c[2]; while( 1 ) { scanf( "%d", &n ); if( … Continue reading

Posted in poj | Leave a comment

Poj Solution 2935

http://poj.org/problem?id=2935 //* @author: 82638882@163.com import java.io.*; import java.util.*; public class Main { static int x1,y1,x2,y2,l; static boolean[][] p=new boolean[8][8]; static int[] ax1,ay1,ax2,ay2; public static void main(String[] args) throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); String[] ss; while(true) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 2933

http://poj.org/problem?id=2933 #include <algorithm> #include <cstdio> #include <vector> #include <map> #include <stack> #include <memory.h> #include <math.h> using namespace std; int a[30]; int in[15]; int de[15]; int n, maxs; bool search( int k, int im, int dm ) { int i, t; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2930

http://poj.org/problem?id=2930 #include <algorithm> #include <cstdio> #include <string.h> #include <map> #include <stack> #include <memory.h> #include <math.h> #include <queue> using namespace std; #define count asdljflsdka #define for_ii(k) for( ii[(k)]=0; ii[(k)]<m; ii[(k)]++ ) char a[20]; char w[110]; char e[6][4] = { { 1, … Continue reading

Posted in poj | Leave a comment

Poj Solution 2928

http://poj.org/problem?id=2928 #include <algorithm> #include <cstdio> #include <vector> #include <map> #include <stack> #include <memory.h> #include <math.h> using namespace std; __int64 x[100010], y[100010]; int main( ) { int n, m, c, C, i, j; scanf( "%d%d%d%d", &n, &m, &c, &C ); for( … Continue reading

Posted in poj | Leave a comment

Poj Solution 2926

http://poj.org/problem?id=2926 #include <algorithm> #include <cstdio> #include <vector> #include <map> #include <stack> #include <memory.h> #include <math.h> using namespace std; double x[100000][5]; int main( ) { int n, i, k, j; int sign[5]; double best = 0, min, max, t; scanf( "%d", … Continue reading

Posted in poj | Leave a comment

Poj Solution 2924

http://poj.org/problem?id=2924 import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int num = Integer.valueOf(cin.nextLine()).intValue(); for(int i = 0; i < num; i++) { String[] str = cin.nextLine().split(" "); BigInteger a … Continue reading

Posted in poj | Leave a comment

Poj Solution 2909

http://poj.org/problem?id=2909 //* @author ������&lt;hongxp11@163.com&gt; import java.util.Scanner; public class Main { public static boolean isPrime(int n) { int root = (int) Math.sqrt(n); for (int i = 2; i <= root; i++) { if (n % i == 0) return false; } … Continue reading

Posted in poj | Leave a comment

Poj Solution 2907

http://poj.org/problem?id=2907 #include <functional> //#include <algorithm> #include <cstdio> #include <vector> #include <map> #include <stack> #include <memory.h> #include <math.h> using namespace std; int s[11][1<<10][10]; typedef pair<int,int> point; point p; point b[10]; int dis( point &a, point &b ) { return abs(a.first-b.first) + … Continue reading

Posted in poj | Leave a comment

Poj Solution 2897

http://poj.org/problem?id=2897 //* @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[] number=new int[100]; int[] answer=new int[100]; int count=Integer.parseInt(stdin.readLine()),carry, lastIndex,n,k; StringTokenizer token; for(int j=0;j< count;j++){ … Continue reading

Posted in poj | Leave a comment

Poj Solution 2895

http://poj.org/problem?id=2895 #include <iostream> #include <string> #include <cstdlib> using namespace std; int num[26] = {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9}; int order[26] = {1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,4,1,2,3,1,2,3,4}; int main() { int N; while (cin>>N) { for (int z = 0;z < N;z++) { int p,w; cin>>p>>w; string msg; do … Continue reading

Posted in poj | Leave a comment

Poj Solution 2894

http://poj.org/problem?id=2894 //* @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); int t = in.nextInt(); for(int i = 0; i< t; i++) { int n = in.nextInt(); int[] result = new … Continue reading

Posted in poj | Leave a comment

Poj Solution 2893

http://poj.org/problem?id=2893 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { static final int M = 1000+2; static final int N = 1000000+10; static int sort[] = new int[N],map[][] = new int[M][M]; public static void main(String []args) throws Exception{ … Continue reading

Posted in poj | Leave a comment

Poj Solution 2892

http://poj.org/problem?id=2892 #include <functional> #include <algorithm> #include <cstdio> #include <vector> #include <map> #include <stack> #include <memory.h> using namespace std; map< int, int, less<int> > s; int query( int k ) { map<int, int, less<int> >::iterator it; it = s.lower_bound( k ); … Continue reading

Posted in poj | Leave a comment

Poj Solution 2890

http://poj.org/problem?id=2890 #include <functional> //#include <algorithm> #include <cstdio> #include <vector> #include <map> #include <stack> #include <memory.h> using namespace std; vector<int> e[1000]; stack<int> sk; int sign[1000] = { 0 }; int count = 0; int c; int n, m; bool input() { … Continue reading

Posted in poj | Leave a comment

Poj Solution 2887

http://poj.org/problem?id=2887 //* @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); int[] s=new int[1000010]; int size=0; while(true) { int u=in.read(); if(u==’n’)break; s[size++]=u; } int n=Integer.parseInt(in.readLine()); int[] arr=new … Continue reading

Posted in poj | Leave a comment

Poj Solution 2886

http://poj.org/problem?id=2886 #include <functional> #include <algorithm> #include <cstdio> #include <vector> #include <string> #include <iterator> #include <memory.h> using namespace std; int tree[500100*4]; int n; void init( int l, int r, int s ) { tree[s] = r-l; if( r > l+1 ) … Continue reading

Posted in poj | Leave a comment

Poj Solution 2876

http://poj.org/problem?id=2876 //* @author: 82638882@163.com import java.util.*; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); StringBuffer[] sb=new StringBuffer[13]; sb[0]=new StringBuffer("-"); for(int i=1;i< 13;i++) { sb[i]=new StringBuffer(sb[i-1]); int k=(int)Math.pow(3, i-1); for(int w=0;w< k;w++) sb[i].append(" "); sb[i].append(sb[i-1]); } … Continue reading

Posted in poj | Leave a comment

Poj Solution 2871

http://poj.org/problem?id=2871 //* @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 first = in.nextDouble(); while(true) { double second = in.nextDouble(); if(second == 999) { System.out.println("End of Output"); break; } … Continue reading

Posted in poj | Leave a comment

Poj Solution 2864

http://poj.org/problem?id=2864 //* @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)); StringTokenizer tokens; int din,stu; boolean[] st=new boolean[100]; boolean band; while(true){ tokens=new StringTokenizer(stdin.readLine()); … Continue reading

Posted in poj | Leave a comment

Poj Solution 2861

http://poj.org/problem?id=2861 #include <stdio.h> #include <memory.h> bool e[120][120]; int s[120][120]; int n; void input( ) { int i, j, k; char c[2]; scanf( "%d", &n ); for( i=0; i<n; i++ ) { for( j=0; j<n; j++ ) { scanf( "%1s", c … Continue reading

Posted in poj | Leave a comment

Poj Solution 2860

http://poj.org/problem?id=2860 //* @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); int n = in.nextInt(); int m = in.nextInt(); int k = in.nextInt(); int[] initial= new int[k]; int[] finish = … Continue reading

Posted in poj | Leave a comment