Meta
-
Recent Posts
Recent Comments
Archives
- May 2024
- April 2023
- February 2023
- January 2023
- December 2022
- November 2022
- September 2022
- June 2022
- July 2021
- January 2021
- February 2020
- September 2019
- March 2018
- February 2018
- August 2016
- July 2016
- June 2016
- May 2016
- April 2016
- March 2016
- February 2016
- January 2016
- December 2015
- November 2015
- October 2015
- September 2015
- August 2015
- July 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- November 2014
- October 2014
- September 2014
- August 2014
- July 2014
- June 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013
- October 2013
- September 2013
- August 2013
- July 2013
- June 2013
- May 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- November 2012
- October 2012
- September 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
Categories

Category Archives: poj
Poj Solution 2054
http://poj.org/problem?id=2054 #include <stdio.h> #include <vector> #include <set> using namespace std; struct node { int id; int num; int cost; int sigma_c; node *father; vector <node *> child; bool colored; }t[1000]; struct cmp { bool operator()( node *a, node *b )const … Continue reading
Posted in poj
Leave a comment
Poj Solution 2051
http://poj.org/problem?id=2051 import java.util.Scanner; public class Main { private static Query[] query = new Query[1002]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int i = 0; while (sc.hasNext()) { String s = sc.nextLine(); if (s.equals("#")) { int … Continue reading
Posted in poj
Leave a comment
Poj Solution 2049
http://poj.org/problem?id=2049 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<string.h> #include<math.h> #define INF 30000 #define NMAX 201 int a[NMAX][NMAX]; int map[NMAX][NMAX][4]; int yp[4]={1,0,-1,0},xp[4]={0,1,0,-1}; int M,N; int x,y,d,t; void init() { for(int i=0;i<=200;i++) { map[0][i][2]=-1; map[200][i][0]=-1; map[i][0][3]=-1; map[i][200][1]=-1; } } typedef struct { int y,x; }DATA; … Continue reading
Posted in poj
Leave a comment
Poj Solution 2042
http://poj.org/problem?id=2042 /* @author: */ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n, s, t1, t2, t; while( sc.hasNext() ) { n=sc.nextInt(); if( n == 0 ) break; s = … Continue reading
Posted in poj
Leave a comment
Poj Solution 2039
http://poj.org/problem?id=2039 import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int num = 0; String str; char[][] array; while(true) { num = Integer.valueOf(cin.nextLine()).intValue(); if(num == 0) break; else { str = cin.nextLine(); … Continue reading
Posted in poj
Leave a comment
Poj Solution 2035
http://poj.org/problem?id=2035 /* @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 c[][]=new int[11][53],p[]=new int[11],r[]=new int[2],d[]=new int[11],count[]=new int[11]; int casen,i,j,k,pn,top,discard,noanswer; casen=sc.nextInt(); for(k=1;k<=casen;k++) { pn=sc.nextInt(); for(i=0;i< pn;i++){count[i]=c[i][0]=0;p[i]=1;} c[0][0]=52;top=0;noanswer=0;r[0]=r[1]=0; for(i=1;i<=52;i++) c[0][i]=sc.nextInt(); while(top< pn&&c[top][0]!=0) … Continue reading
Posted in poj
Leave a comment
Poj Solution 2033
http://poj.org/problem?id=2033 //* @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(); if(s.equals("0")) break; int l=s.length(); int[] arr=new int[l]; int count=0; for(int i=0;i< l-1;i++) … Continue reading
Posted in poj
Leave a comment
Poj Solution 2031
http://poj.org/problem?id=2031 //* @author: 82638882@163.com import java.io.*; import java.util.Arrays; public class Main { static int[] p; public static void main(String[] args) throws NumberFormatException, IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); while(true) { int a=Integer.parseInt(in.readLine()); if(a==0)break; double[][] dd=new double[a][4]; for(int i=0;i< … Continue reading
Posted in poj
Leave a comment
Poj Solution 2029
http://poj.org/problem?id=2029 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { /** * @param args */ static int max(int a,int b) { if(a>b) return a; return b; } public static void main(String[] args) { // TODO Auto-generated method stub … Continue reading
Posted in poj
Leave a comment
Poj Solution 2028
http://poj.org/problem?id=2028 //* @author ������<hongxp11@163.com> import java.awt.Label; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (true) { int n = in.nextInt(); int q … Continue reading
Posted in poj
Leave a comment
Poj Solution 2027
http://poj.org/problem?id=2027 import java.util.Scanner; /** * POJ2027 easy * @author NC */ public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); if (scan.hasNext()) { int n = scan.nextInt(); for (int i = 0; i < … Continue reading
Posted in poj
Leave a comment
Poj Solution 2019
http://poj.org/problem?id=2019 //* @author: 82638882@163.com import java.io.*; import java.util.Arrays; public class Main { public static void main(String[] args) throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); String[] ss=in.readLine().split(" "); int a=Integer.parseInt(ss[0]); int b=Integer.parseInt(ss[1]); int c=Integer.parseInt(ss[2]); int[][] p=new int[a][a]; for(int i=0;i< … Continue reading
Posted in poj
Leave a comment
Poj Solution 2018
http://poj.org/problem?id=2018 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { static int n,k; static final int N = 100000+100,que[] = new int[N]; static double DP[] = new double[N] , sum[] = new double[N]; public static int Get_Num(StreamTokenizer cin) … Continue reading
Posted in poj
Leave a comment
Poj Solution 2017
http://poj.org/problem?id=2017 import java.io.BufferedInputStream; import java.util.Scanner; /** *poj2017 * @author NC */ public class Main { public static void main(String[] args) { Scanner scan = new Scanner(new BufferedInputStream(System.in)); while (scan.hasNext()) { int n = scan.nextInt(); if (n == -1) { break; … Continue reading
Posted in poj
Leave a comment
Poj Solution 2014
http://poj.org/problem?id=2014 //* @author: import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int max_width; while((max_width=cin.nextInt())!=0){ int final_width=0; int final_height=0; int remain=max_width; int cur_height=0; int r_width=cin.nextInt(); int r_height=cin.nextInt(); while(r_width!=-1){ if(r_width<=remain){ remain-=r_width; if(final_width< max_width-remain) … Continue reading
Posted in poj
Leave a comment
Poj Solution 2013
http://poj.org/problem?id=2013 //* @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; String[] s; int index=1; while (true){ n=scanner.nextInt(); if (n==0){ break; } System.out.println("SET "+index); index++; s=new String[n]; for … Continue reading
Posted in poj
Leave a comment
Poj Solution 2011
http://poj.org/problem?id=2011 #include <stdio.h> #include <math.h> #include <algorithm> using namespace std; int ans[20], an; int temp[20]; int get( int num, int s, int &r ) { int g = 0, tg=1, tr=1; bool key = true; r = 0; while( num … Continue reading
Posted in poj
Leave a comment
Poj Solution 2010
http://poj.org/problem?id=2010 #include<stdio.h> #include<vector> #include<queue> #include<algorithm> using namespace std; priority_queue< int ,vector<int> > q; typedef pair< int, int > cow; cow c[1000000]; int money[100000]; int n, m, f; int main() { int i, v; scanf( "%d %d %d", &n, &m, &f … Continue reading
Posted in poj
Leave a comment
Poj Solution 2008
http://poj.org/problem?id=2008 #include <stdio.h> #include <algorithm> #include <queue> using namespace std; pair<int,int> p[1000]; pair<int,int> q[1000]; bool cmp( const pair<int,int> &a, const pair<int,int> &b ) { return a.second < b.second; } int main( ) { int a, b, c, n, i, j, … Continue reading
Posted in poj
Leave a comment
Poj Solution 2007
http://poj.org/problem?id=2007 #include<stdio.h> #include<stdlib.h> #include<math.h> #define debug 0 #define INF 1000 #if debug #define NMAX 10 #else #define NMAX 52 #endif int point[NMAX][2]; int base[2]; int m[5]; int qu(int p[]) { if(p[0]>0&&p[1]>0) return 1; if(p[0]<0&&p[1]>0) return 2; if(p[0]<0&&p[1]<0) return 3; if(p[0]>0&&p[1]<0) … Continue reading
Posted in poj
Leave a comment
Poj Solution 2005
http://poj.org/problem?id=2005 //* @author: <strong> import java.util.*; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int tot[]=new int[12],t[]=new int[4]; char ts[]=new char[5]; int sum,s1,s2,win,tem; while (sc.hasNext()) { int n=sc.nextInt(); if(n==0) break; for (int i=2;i< 10;i++) … Continue reading
Posted in poj
Leave a comment
Poj Solution 2004
http://poj.org/problem?id=2004 //* @author: 82638882@163.com import java.io.*; import java.util.Arrays; import java.util.Comparator; public class Main { static my[] s=new my[10001]; public static void main(String[] args) throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); int l=0,max=-1,rr=-1; while(in.ready()) { String t=in.readLine(); s[l++]=new my(t); … Continue reading
Posted in poj
Leave a comment
Poj Solution 2002
http://poj.org/problem?id=2002 #include <stdio.h> #include <math.h> #include <string.h> #include <algorithm> using namespace std; #define DIFF 20000 #define MAX 1005 #define NUM 40005 #define EP 1e-8 #define LIM 1e-6 #define PI acos(-1.0) struct pt{ int x,y; }; pt p[MAX]; int s[NUM],e[NUM]; int … Continue reading
Posted in poj
Leave a comment
Poj Solution 2001
http://poj.org/problem?id=2001 import java.util.*; public class Main { static int MAX = 1010; static TrieNode root = new TrieNode(); static char[][] result = new char[MAX][22]; static char[][] s = new char[MAX][22]; public static void main(String[] args) { Scanner cin = new … Continue reading
Posted in poj
Leave a comment
Poj Solution 2000
http://poj.org/problem?id=2000 import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); while(true) { int day = Integer.valueOf(cin.nextLine()).intValue(); if(day == 0) break; System.out.println(day + " " + getTotalCoin(day)); } } private static int getTotalCoin(int … Continue reading
Posted in poj
Leave a comment
Poj Solution 1995
http://poj.org/problem?id=1995 //* @author: import java.util.*; public class Main{ //��a^b%n private static int modexp(int a,int b,int n) { int ret=1; int tmp=a; while(b!=0) { if((b&0x1)==1) ret=ret*tmp%n; tmp=tmp*tmp%n; b>>=1; } return ret; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int … Continue reading
Posted in poj
Leave a comment
Poj Solution 1990
http://poj.org/problem?id=1990 //* @author: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Comparator; import java.util.StringTokenizer; /* *�ο���ţ�ij���,��һ��д��״����… *�Ƚ�cows��volumeΪ�ؼ�������.. *}����״����,һ��ά�������,һ��ά��ǰ����С�ڵ�ǰ������֮�� */ class cin { static BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; static int leave=0; static int nextInt() throws IOException { … Continue reading
Posted in poj
Leave a comment
Poj Solution 1989
http://poj.org/problem?id=1989 //* @author: ccQ.SuperSupper import java.util.*; import java.math.*; public class Main { public static void main(String []args) throws Exception{ int i,j,k,n,ans; int way[] = new int[100100]; int flag[] = new int[10100]; Scanner cin = new Scanner(System.in); n = cin.nextInt(); k … Continue reading
Posted in poj
Leave a comment
Poj Solution 1988
http://poj.org/problem?id=1988 /* @author: */ import java.util.Scanner; import java.util.Arrays; public class Main{ static int p[]=new int[30010]; static int d[]=new int[30010]; static int num[]=new int[30010]; static int i=0; static char c[]=new char[5]; static int getup(int a) { int b=a; while(p[b]!=b) b=p[b]; return … Continue reading
Posted in poj
Leave a comment
Poj Solution 1987
http://poj.org/problem?id=1987 #include"stdio.h" #include"algorithm" using namespace std; long use[16]; long father[40010]; long queue[40010]; long lchild[40010][16]; long rchild[40010][16]; long sum[40010][16]; long depth[40010][16]; long value[40010],dist[40010]; long m,n,k,kind,answer; long findit(long key,long s1,long deep) { long &lc=lchild[s1][deep],&rc=rchild[s1][deep],sumnow=sum[s1][deep]; long now=depth[s1][deep]; if(now==key) { if(rc>=0)return sumnow-sum[rc][deep+1]; else return … Continue reading
Posted in poj
Leave a comment
Poj Solution 1981
http://poj.org/problem?id=1981 #include<iostream> #include"math.h" #include"algorithm" using namespace std; struct point { double x,y; }p[310]; double jl(point i,point j) { return sqrt((i.x-j.x)*(i.x-j.x)+(i.y-j.y)*(i.y-j.y)); } bool fzk(point a,point b,double &in,double &out) { double jiao,l,x; if((l=jl(a,b))>2)return 0; jiao=atan2(b.y-a.y,b.x-a.x); x=acos(l/2); in=jiao-x; out=jiao+x; return 1; } int … Continue reading
Posted in poj
Leave a comment
Poj Solution 1978
http://poj.org/problem?id=1978 import java.io.BufferedInputStream; import java.util.LinkedList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(new BufferedInputStream(System.in)); while (scan.hasNext()) { int m = scan.nextInt(); int n = scan.nextInt(); if (m == 0 && n … Continue reading
Posted in poj
Leave a comment
Poj Solution 1977
http://poj.org/problem?id=1977 #include<iostream> #include"string.h" using namespace std; char m[30][100][100]; int n,t,v[100]; char name[100][100][100]; char nm[100][100]; int s[100]; char ans[100][100]; char temp[100][100]; void multiply(char a[100][100],char b[100][100],char c[100][100]) { int i,j,k; for(i=0;i<n;i++) for(j=0;j<n;j++) { c[i][j]=0; for(k=0;k<n;k++) c[i][j]+=a[i][k]*b[k][j]; c[i][j]%=2; } return; } void init() … Continue reading
Posted in poj
Leave a comment
Poj Solution 1976
http://poj.org/problem?id=1976 #include<stdio.h> #include<string.h> #define debug 0 #define NMAX 10002 int a[NMAX]; int s[4][NMAX]; int main() { #if debug freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int i,j,k,t,d,N; scanf("%d",&t); while(t–) { scanf("%d",&N); memset(s,0,sizeof(int)); memset(a,0,sizeof(int)); for(i=1;i<=N;i++) { scanf("%d",&a[i]); a[i]+=a[i-1]; } scanf("%d",&d); for(k=1;k<=3;k++) { for(i=1;i<=N;i++) { j=0>i-d?0:i-d; … Continue reading
Posted in poj
Leave a comment
Poj Solution 1974
http://poj.org/problem?id=1974 #include<stdio.h> #include<stdlib.h> #define debug 0 #define NMAX 1000003 struct data { long x,y; }v[NMAX]; long t,m,n,k; long count; int cmp1(void const *a,void const *b) { if((*(struct data*)a).y==(*(struct data*)b).y) return (*(struct data*)a).x-(*(struct data*)b).x; else return (*(struct data*)a).y-(*(struct data*)b).y; } int … Continue reading
Posted in poj
Leave a comment
Poj Solution 1973
http://poj.org/problem?id=1973 #include<iostream> using namespace std; int f[110],ft[110]; int n,m; int t1[110],t2[110]; bool checkout(int t) { int i,j,a,b; for(i=1;i<=m;i++) f[i]=-1; f[0]=0; for(j=0;j<=m;j++) ft[j]=f[j]; for(i=0;i<n;i++) { for(a=0;a<=t/t1[i]&&a<=m;a++) { b=(t-t1[i]*a)/t2[i]; for(j=0;j<=m-a;j++) if(f[j]>=0) { if(ft[j+a]<f[j]+b) ft[j+a]=f[j]+b; } } for(j=0;j<=m;j++) f[j]=ft[j]; if(f[m]>=m)return 1; } return … Continue reading
Posted in poj
Leave a comment
Poj Solution 1972
http://poj.org/problem?id=1972 //* @author: <strong> import java.util.*; public class Main { static int max(int u,int v,int w,int x) { if (u< v)u=v; if (u< w)u=w; if (u< x)u=x; return u; } public static void main(String[] args){ Scanner sc = new Scanner(System.in); … Continue reading
Posted in poj
Leave a comment
Poj Solution 1971
http://poj.org/problem?id=1971 #include<stdio.h> #include<string.h> #include<stdlib.h> #define debug 0 #define INF 30000 #if debug #define NMAX 10 #else #define NMAX 1003 #endif typedef struct { int x,y; }point; point a[NMAX],m[NMAX*NMAX]; int cmp(const void*a,const void *b) { if((*(point*)a).x==(*(point*)b).x) return (*(point*)a).y-(*(point*)b).y; else return (*(point*)a).x-(*(point*)b).x; … Continue reading
Posted in poj
Leave a comment
Poj Solution 1970
http://poj.org/problem?id=1970 /* @author: */ import java.util.Scanner; public class Main{ static int p[][]=new int[21][21]; public static void main(String args[]) { Scanner sc=new Scanner(System.in); int tt,i,j,k,x=0,y=0; tt=sc.nextInt(); while((tt–)!=0) { for(i=1;i< 20;i++) for(j=1;j< 20;j++) p[i][j]=sc.nextInt(); int tag=0; for(i=1;i< 20;i++) { for(j=1;j< 16;j++) { … Continue reading
Posted in poj
Leave a comment
Poj Solution 1969
http://poj.org/problem?id=1969 import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); while(cin.hasNext()) { int num = cin.nextInt(); int index = 1; int result = 0; while(result <= num) { result += index; index … Continue reading
Posted in poj
Leave a comment
Poj Solution 1965
http://poj.org/problem?id=1965 //* @author mekarlos@gmail.com import java.math.BigDecimal; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan=new Scanner(System.in); BigDecimal k; BigDecimal root=new BigDecimal("1"); BigDecimal aux=new BigDecimal("0.0000000001"); BigDecimal tr=new BigDecimal("3"); String a; int ind=0,sum; while(scan.hasNext()){ k=scan.nextBigDecimal(); root=k.divide(new BigDecimal("2")); … Continue reading
Posted in poj
Leave a comment
Poj Solution 1964
http://poj.org/problem?id=1964 //* @author mekarlos@gmail.com import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner scan=new Scanner(System.in); int[][] N=new int[1001][1001]; int[][] M=new int[1001][1001]; int k=scan.nextInt(); int n=0,m=0,d,maxA; for(int z=0;z< k;z++){ maxA=0; m=scan.nextInt(); n=scan.nextInt(); for(int i=0;i< m;i++) for(int j=0;j< n;j++) … Continue reading
Posted in poj
Leave a comment
Poj Solution 1961
http://poj.org/problem?id=1961 //* @author: import java.util.Scanner; public class Main { static int next[]=new int[1000010]; public static void main(String[] args) { Scanner scn = new Scanner(System.in); int n; String input = ""; int j=0; int k=0; while(scn.hasNext()){ n=scn.nextInt(); input = scn.next(); if(n==0){ … Continue reading
Posted in poj
Leave a comment
Poj Solution 1959
http://poj.org/problem?id=1959 /* @author: */ import java.text.DecimalFormat; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a[]=new int[100]; int n,T; long sum; a[0]=0; for(int i=1;i<=20;i++) { a[i]=i; a[20+i]=2*(i); a[40+i]=3*(i); } a[61]=25; a[62]=50; … Continue reading
Posted in poj
Leave a comment
Poj Solution 1953
http://poj.org/problem?id=1953 import java.io.BufferedInputStream; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(new BufferedInputStream(System.in)); if (scan.hasNext()) { long[] f = new long[46]; f[0] = 0; f[1] = 2; f[2] = 3; for (int … Continue reading
Posted in poj
Leave a comment
Poj Solution 1952
http://poj.org/problem?id=1952 //* @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 a=Integer.parseInt(in.readLine()); int n=0; my[] p=new my[a]; String[] ss; while(a-n>10) { ss=in.readLine().split(" "); for(int i=0;i< 10;i++) … Continue reading
Posted in poj
Leave a comment
Poj Solution 1950
http://poj.org/problem?id=1950 //* @author:alpc12 import java.io.*; import java.util.*; import java.math.*; public class Main { char[] opa = { ‘+’, ‘-‘, ‘.’ }; char[] op; int cnt; int n; int rec[] = {88, 162, 197, 437, 1350 }; void print() { cnt++; … Continue reading
Posted in poj
Leave a comment
Poj Solution 1948
http://poj.org/problem?id=1948 #include <stdio.h> #include <memory.h> #include <math.h> #include <list> using namespace std; bool sign[800][800]; int l[40], n; typedef pair<int,int> node; node q[800*800]; int qn; int main() { int i, j, x, y, s, m; list< node >::iterator iter; scanf( "%d", … Continue reading
Posted in poj
Leave a comment
Poj Solution 1947
http://poj.org/problem?id=1947 #include <list> #include <iostream> using namespace std; list< int > e[150]; int ans[150][151]; int n, p, answer; int root; int creat( int r ) { int i, j, n, m, c, temp[151]; n = 1; ans[r][0] = 1; ans[r][1] … Continue reading
Posted in poj
Leave a comment