Category Archives: poj

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

Poj Solution 2859

http://poj.org/problem?id=2859 #include <vector> #include <algorithm> #include <stdio.h> using namespace std; typedef pair<int,int> point; int n, a, b; point p[500100]; void input( ) { int i; scanf( "%d", &n ); scanf( "%d%d", &a, &b ); for( i=0; i<n; i++ ) scanf( … Continue reading

Posted in poj | Leave a comment

Poj Solution 2858

http://poj.org/problem?id=2858 #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; char w[100100][11]; char *p[11][100100]; int pn[11]; bool cmpw( char *a, char *b ) { return strcmp( a, b ) < 0; } struct tile{ char c[2]; int v; }tiles[10]; bool … Continue reading

Posted in poj | Leave a comment

Poj Solution 2857

http://poj.org/problem?id=2857 import java.util.*; /** * * @author leo */ public class Main { public static int judge(double H,double V,double h,double v,double x,double y,int state){ if((x>H*h&&y< V*v)||(x< H*h&&y>V*v)){ return state; }else{ state++; if(x< h*H&&y< v*V){ return judge(H*h,v*V,h,v,x,y,state); }else{ return judge(H*(1.0-h),V*(1.0-v),h,v,x-H*h,y-V*v,state); } … Continue reading

Posted in poj | Leave a comment

Poj Solution 2853

http://poj.org/problem?id=2853 //* @author: 82638882@163.com import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); int u=in.nextInt(); while((u–)!=0) { int y=in.nextInt(); int a=in.nextInt(); int count=0; int t=1; for(int i=2;i< (Math.sqrt(2*a)+1);i++) { t+=i; if((a-t)%i==0&&a>=t) count++; } System.out.println(y+" … Continue reading

Posted in poj | Leave a comment

Poj Solution 2849

http://poj.org/problem?id=2849 //2849 #include <iostream> #include <cstdio> #include <vector> #include <string> #include <cstring> using namespace std; int Array[32768]; string Program; string input; int index; int inputP; int PromP; int cc; int Programsize; inline void IncP() { index = (index + 1) … Continue reading

Posted in poj | Leave a comment

Poj Solution 2847

http://poj.org/problem?id=2847 //* @author:alpc12 import java.io.*; import java.util.*; import java.math.*; public class Main { String num; boolean ok; void DFS(int dep, String b) { if(b.length() == num.length()) return; int i, j; for(i = 0; i <= 9; ++i) { BigInteger now … Continue reading

Posted in poj | Leave a comment

Poj Solution 2845

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

Posted in poj | Leave a comment

Poj Solution 2842

http://poj.org/problem?id=2842 #include <stdio.h> int an[10], bn[10]; int sa[10], sb[10]; int p[10], n, m, g, h; int S[500000], T[500000]; int get_T( int *a ) { int index = 0, i; for( i=0; i<n; i++ ) index += a[i]*sa[i]; return T[ index … Continue reading

Posted in poj | Leave a comment

Poj Solution 2840

http://poj.org/problem?id=2840 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(); for(int i = 0; i < num; i++) { String[] str = cin.nextLine().split(":"); int hour = Integer.valueOf(str[0]).intValue(); int … Continue reading

Posted in poj | Leave a comment

Poj Solution 2838

http://poj.org/problem?id=2838 #include <stdio.h> struct edge { edge *pri; edge *next; }; edge *e[1010]; edge temp[1010][1010]; void add( int from, int to ) { temp[from][to].next = e[from]; temp[from][to].pri = 0; if( e[from] ) e[from]->pri = temp[from]+to; e[from] = temp[from]+to; } void … Continue reading

Posted in poj | Leave a comment

Poj Solution 2837

http://poj.org/problem?id=2837 #include <stdio.h> int ans[512][512]; int main( ) { int i, j, k, n; ans[0][0] = 1; scanf( "%d", &n ); for( i=1; i<(1<<n); i<<=1 ) { for( j=i; j<i*2; j++ ) for( k=i; k<i*2; k++ ) ans[j][k] = ans[j-i][k-i]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2834

http://poj.org/problem?id=2834 #include <stdio.h> #include <memory.h> #include <algorithm> #include <vector> using namespace std; vector<int> e[10010], dest; int n, m; vector< pair<int,int> > jon, cely; void input( ) { int a, b; scanf( "%d", &n ); scanf( "%d", &m ); while( m– … Continue reading

Posted in poj | Leave a comment

Poj Solution 2833

http://poj.org/problem?id=2833 //* @author: 82638882@163.com import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); StringBuffer buf=new StringBuffer(); try { while(true) { char c; int[] u=new int[3]; for(int i=0;i< 3;i++) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 2823

http://poj.org/problem?id=2823 #include <stdio.h> #include <algorithm> using namespace std; int a[1000100], l[1000100], ans[1000100]; int pt[1000100], st[1000100], n, k, m; bool cmp( int x, int y ) { return a[x] < a[y]; } void calc( ) { int i, j, h, sn; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2818

http://poj.org/problem?id=2818 /* @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 sum,a[]=new int[4],b[]=new int[4],sum1=0; while(true) { a[0]=sc.nextInt(); a[1]=sc.nextInt(); a[2]=sc.nextInt(); a[3]=sc.nextInt(); sum=sc.nextInt(); if(a[0]==0 && a[1]==0 && a[2]==0 &a[3]==0 … Continue reading

Posted in poj | Leave a comment

Poj Solution 2817

http://poj.org/problem?id=2817 #include <stdio.h> #include <memory.h> #include <string.h> int ans[12][1024][10]; int link[10][10]; int len[10]; char w[10][20]; int join_num( int i, int j ) { int k, l, ans = 0, h; for( k=0; w[i][k]; k++ ) { for( l=0, h=0; w[i][k+l] … Continue reading

Posted in poj | Leave a comment

Poj Solution 2816

http://poj.org/problem?id=2816 #include <stdio.h> #include <memory.h> #include <string.h> #include <math.h> char map[200][200]; bool ok[200][200]; int gx, gy, n, m, t, r; const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 }; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2815

http://poj.org/problem?id=2815 #include <stdio.h> #include <memory.h> #include <string.h> #include <math.h> double get_angle( double s, double f, double m ) { if( s >= 12 ) s -= 12; s = ( s+f/60+m/7200 ) / 12 * 360; f = ( f+m/120 … Continue reading

Posted in poj | Leave a comment