Category Archives: poj

Poj Solution 3088

http://poj.org/problem?id=3088 /* @author: */ import java.util.*; import java.io.*; import java.lang.reflect.Array; public class Main { static int a[][] = new int[12][12]; static long ans[] = new long[12]; static public void main( String [] str ) throws Exception{ int n; int m; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3087

http://poj.org/problem?id=3087 /* @author: */ import java.util.*; import java.io.*; import java.lang.reflect.Array; public class Main { static int a[] = new int[200]; static char start[], result[]; static public void main( String [] str ) throws Exception{ int n; int m; Scanner cin … Continue reading

Posted in poj | Leave a comment

Poj Solution 3086

http://poj.org/problem?id=3086 import java.io.BufferedInputStream; import java.util.Scanner; /** * @author NC * Poj3086 */ public class Main { public static void main(String[] args) { Scanner scan = new Scanner(new BufferedInputStream(System.in)); int n = scan.nextInt(); for (int i = 1; i <= n; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3085

http://poj.org/problem?id=3085 //* @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(); for(int i = 0; i < n; i++) { int sum = in.nextInt(); int quarter … Continue reading

Posted in poj | Leave a comment

Poj Solution 3084

http://poj.org/problem?id=3084 /* @author: */ import java.util.*; class ff { static int min( int a, int b ) { return a< b?a:b; } class edge { int to; int c, f; int rev_i; edge( int pa, int pb, int pc ) … Continue reading

Posted in poj | Leave a comment

Poj Solution 3083

http://poj.org/problem?id=3083 /* @author: */ import java.util.*; public class Main { static String map[] = new String[50]; static int q[] = new int[2000]; static int n, m; static boolean inmap( int x, int y ) { return 0<=x&&x< n && 0<=y&&y< … Continue reading

Posted in poj | Leave a comment

Poj Solution 3082

http://poj.org/problem?id=3082 /* @author: */ import java.util.*; class point { int x,y; point(){x=y=0;} }; public class Main { static int cheng(point a,point b,point c) { return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y); } static int dcheng(point a,point b,point c) { return (b.x-a.x)*(c.x-a.x)+(c.y-a.y)*(b.y-a.y); } static int in(point … Continue reading

Posted in poj | Leave a comment

Poj Solution 3080

http://poj.org/problem?id=3080 import java.util.*; public class Main { static String w[] = new String[10]; public static void main(String args[]) { int t, n, i, j = 0, k; Scanner cin = new Scanner( System.in ); t = cin.nextInt(); String p = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3078

http://poj.org/problem?id=3078 import java.math.BigInteger; import java.util.*; public class Main { static String name[] = new String[20]; static int pos[] = new int[20]; public static void main(String args[]) { Scanner cin = new Scanner( System.in ); int t, n, m, a, b; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3077

http://poj.org/problem?id=3077 import java.math.BigInteger; import java.util.*; public class Main { public static void main(String args[]) { int n, s, i; Scanner cin = new Scanner( System.in ); n = cin.nextInt(); while( n– != 0 ) { s = cin.nextInt(); for( i=10; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3070

http://poj.org/problem?id=3070 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader( System.in)); int[] f = new int[15000]; f[0] = 0; f[1] = 1; f[2] = 1; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3068

http://poj.org/problem?id=3068 #include <stdio.h> #include <memory.h> #include <math.h> #include <algorithm> using namespace std; #include <vector> using namespace std; typedef int type; //�������� const int size = 230; //ͼ�Ķ���ģ const type MAX_FEE = (1<<30); //�������� const int MAX = (1<<30); //������� const … Continue reading

Posted in poj | Leave a comment

Poj Solution 3067

http://poj.org/problem?id=3067 //* @author: 82638882@163.com import java.io.*; import java.util.Arrays; public class Main { static long ans=0; 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 cnt=0; while((a–)!=0) { ans=0; cnt++; String[] ss=in.readLine().split(" "); … Continue reading

Posted in poj | Leave a comment

Poj Solution 3066

http://poj.org/problem?id=3066 #include <stdio.h> #include <memory.h> #include <math.h> #include <algorithm> int main( ) { int m, p, a, b, k, i; double sum, q_a, a_p, ans, t; while( scanf( "%d%d%d%d", &m, &p, &a, &b ) == 4 ) { q_a = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3065

http://poj.org/problem?id=3065 #include <stdio.h> #include <memory.h> #include <math.h> #include <algorithm> using namespace std; int p[6000010]; int st[6000010]; void clear( int n ) { memset( p, -1, sizeof(int)*(n+1) ); } void input( int &m, int &sa, int &sb ) { char w[2]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3063

http://poj.org/problem?id=3063 #include <stdio.h> #include <stdlib.h> int m, n; int s0[5000], s1[5000]; int mem[2][10000], *a = mem[0], *b = mem[1]; int w0, w1, b0, b1, sum; #define mine( a, b ) ((a)<(b)?(a):(b)) void fill( ) { int i; int m0 = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3062

http://poj.org/problem?id=3062 import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); while(cin.hasNext()) { System.out.println(cin.nextLine()); } } }

Posted in poj | Leave a comment

Poj Solution 3061

http://poj.org/problem?id=3061 import java.util.Arrays; import java.util.Scanner; public class Main { // private static int ans[] =new int[100000]; private static int index = 0; public static void get(int[] seq, int s , int[]ans) { int sum = 0; int k = 0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3060

http://poj.org/problem?id=3060 #include <stdio.h> #include <memory.h> int m[1000][1000]; int sx[1000], sy[1000]; int main() { int t, n, i, j, d, a, b, best; scanf( "%d", &t ); while( t– ) { scanf( "%d%d", &d, &n ); best = 99999999; memset( m, … Continue reading

Posted in poj | Leave a comment

Poj Solution 3058

http://poj.org/problem?id=3058 #include <stdio.h> #include <algorithm> #include <memory.h> using namespace std; int w1[1000000]; int main() { int t, i, j, m; char c, temp; scanf( "%d", &t ); getchar(); while( t– ) { m = 0; while( 1 ){ c = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3055

http://poj.org/problem?id=3055 #include <stdio.h> int main() { int n, i, j, k; char mm[2][200], *w1 = &mm[0][0], *w2 = &mm[1][0], *t; int a[10], b[10], temp; bool key; scanf( "%d", &n ); while( n– ) { scanf( "%s %s", w1, w2 ); … Continue reading

Posted in poj | Leave a comment

Poj Solution 3051

http://poj.org/problem?id=3051 //* @author: 82638882@163.com import java.io.*; public class Main { static int[][] p; static int a,b,max=0,cnt; public static void main(String[] args) throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); String[] ss=in.readLine().split(" "); a=Integer.parseInt(ss[0]); b=Integer.parseInt(ss[1]); p=new int[b+2][a+2]; for(int i=1;i<=b;i++) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 3050

http://poj.org/problem?id=3050 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashSet; import java.util.Set; public class Main { static Set<Integer> set; static int[][] a; public static void main(String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader( System.in)); a = new int[5][5]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3049

http://poj.org/problem?id=3049 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { static final int N = 20; static int n,l; static String ans; static char word[] = new char[N]; static char ansp[] = new char[N]; public static void main(String … Continue reading

Posted in poj | Leave a comment

Poj Solution 3048

http://poj.org/problem?id=3048 import java.util.Scanner; import java.util.Arrays; public class Main{ public static void main(String args[]) { Scanner sc=new Scanner(System.in); int n,mx=-1,tag=-1,i,v; n=sc.nextInt(); while((n–)!=0) { v=sc.nextInt(); int u=v; int maxx=1; if(v%2==0) { maxx=2; while(v%2==0)v/=2; } for(i=3;i*i<=v;i+=2) { if(v%i==0) { maxx=i; while(v%i==0)v/=i; } } … Continue reading

Posted in poj | Leave a comment

Poj Solution 3047

http://poj.org/problem?id=3047 //* @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[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; String s[]={"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"}; int n,y,m,d,t; y=sc.nextInt(); m=sc.nextInt(); d=sc.nextInt(); t=(y-1)*365; for (int i=1;i< y;i++) if ((i%4==0&&i%100!=0)||(i%400==0)) … Continue reading

Posted in poj | Leave a comment

Poj Solution 3046

http://poj.org/problem?id=3046 #include <stdio.h> #include <memory.h> int c[1001]; int ans[1001][10000]; int main() { int i, j, k, sum, n, a, t, left, right; scanf( "%d%d%d%d", &n, &a, &left, &right ); if( a > 10000 ) while( printf( "asdf" ) ); for( … Continue reading

Posted in poj | Leave a comment

Poj Solution 3045

http://poj.org/problem?id=3045 #include <stdio.h> #include <algorithm> using namespace std; struct cow { int sum, w, s; }c[50000]; int n; bool cmp( cow a, cow b ) { return a.sum < b.sum; }; bool check( int k ) { int sum = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3044

http://poj.org/problem?id=3044 #include <stdio.h> #include <algorithm> using namespace std; int id[50000]; int h[50000]; bool sign[50000]; int temp[2][51000]; int *next = &temp[0][1]; int *pri = &temp[1][1]; bool cmp( int a, int b ) { return h[a] > h[b]; } int main() { … Continue reading

Posted in poj | Leave a comment

Poj Solution 3043

http://poj.org/problem?id=3043 #include <stdio.h> #define max(a,b) ((a)>(b)?(a):(b)) int clac( char *w, int len, char map[32][32], int n, int m ) { int s[5][1000], sn[5] = {0}; int ans[5][1000] = { 0 }, i, j, k, ii, l, sum = 0; for( … Continue reading

Posted in poj | Leave a comment

Poj Solution 3042

http://poj.org/problem?id=3042 #include <stdio.h> #include <algorithm> #include <memory.h> using namespace std; int x[1001]; __int64 ans[1001][1001][2]; int main() { int i, j, n, k; scanf( "%d%d", &n, &k ); for( i=0; i<n; i++ ) { scanf( "%d", &x[i] ); } x[n] = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3041

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

Posted in poj | Leave a comment

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