Category Archives: poj

Poj Solution 2812

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

Posted in poj | Leave a comment

Poj Solution 2810

http://poj.org/problem?id=2810 #include <stdio.h> #include <memory.h> #include <vector> #include <string> using namespace std; vector<string> v; int main( ) { double a, b; int i, j; char w[1000], unit[1000]; while( 1 ) { scanf( "%lf %s %lf %1s", &a, unit, &b, w … Continue reading

Posted in poj | Leave a comment

Poj Solution 2800

http://poj.org/problem?id=2800 //* @author: <strong>Yeming&nbsp;Hu</strong>&quot;cslittleye@gmail.com&quot; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n,k; while(sc.hasNext()) { n = sc.nextLong(); k = sc.nextLong(); long sum; if(n<=k) { sum = sumMod(k,n); }else { … Continue reading

Posted in poj | Leave a comment

Poj Solution 2799

http://poj.org/problem?id=2799 //* @author: SmilingWang import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); IPAddress[] ips = new IPAddress[n]; for(int i = 0; i < … Continue reading

Posted in poj | Leave a comment

Poj Solution 2796

http://poj.org/problem?id=2796 //* @author: 82638882@163.com import java.io.*; public class Main { static int[] b,c; static long[] e,d,p; 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()); p=new long[a+2]; b=new int[a+1]; c=new int[a+1]; d=new long[a+1]; e=new … Continue reading

Posted in poj | Leave a comment

Poj Solution 2785

http://poj.org/problem?id=2785 //* @author: 82638882@163.com import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); String s=in.readLine(); int a=Integer.parseInt(s); int[] t1=new int[a]; int[] t2=new int[a]; int[] t3=new int[a]; int[] … Continue reading

Posted in poj | Leave a comment

Poj Solution 2782

http://poj.org/problem?id=2782 //* @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(); int b=in.nextInt(); ArrayList< Integer> t=new ArrayList< Integer>(); while((a–)!=0) t.add(in.nextInt()); Collections.sort(t); int count=0; int u=t.size()-1; int k=0; while(k<=u) { int … Continue reading

Posted in poj | Leave a comment

Poj Solution 2781

http://poj.org/problem?id=2781 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<string.h> #include<math.h> #define INF 3000000 #define NMAX 1000000 int N; typedef struct { int len; int next[101]; }DATA; DATA a[NMAX]; int st,ed; void input() { int i,j; scanf("%d",&N); int tmp; for(i=0;i<N;i++) { scanf("%d%d",&tmp,&a[i].len); for(j=0;j<a[i].len;j++) { scanf("%d",&a[i].next[j]); … Continue reading

Posted in poj | Leave a comment

Poj Solution 2780

http://poj.org/problem?id=2780 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; class Point implements Comparable { double x,y; public int compareTo(Object obj){ Point temp = (Point) obj; if(temp.x!=this.x){ if(temp.x< this.x) return 1; return -1; } if(temp.y< this.y) return 1; return -1; } } … Continue reading

Posted in poj | Leave a comment

Poj Solution 2777

http://poj.org/problem?id=2777 import java.io.*; import java.util.*; public class Main { static tree[] mytree=new tree[300003]; static boolean[] flag=new boolean[35]; public static void main(String args[]) throws Exception { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); String[] ss=in.readLine().split(" "); int l=Integer.parseInt(ss[0]); int t=Integer.parseInt(ss[1]); int o=Integer.parseInt(ss[2]); … Continue reading

Posted in poj | Leave a comment

Poj Solution 2775

http://poj.org/problem?id=2775 #include "stdio.h" struct tree{ int l, r; int v; int ans; int nds; }t[200]; int n, m; int new_node( int value ) { t[m].l = t[m].r = -1; t[m].v = value; t[m].nds = 1; m++; return m-1; } int … Continue reading

Posted in poj | Leave a comment

Poj Solution 2774

http://poj.org/problem?id=2774 #include "stdio.h" #include "memory.h" #include "string.h" #include "stdlib.h" const int CHAR_NUM = 27; const int MAXSIZE = 500000; struct suftree{ suftree *ch[CHAR_NUM]; char *l, *r; int len; suftree *s, *p; }suft[MAXSIZE]; int use_node = 0; /////////////////////////////////////////////// suftree *new_node( ) … Continue reading

Posted in poj | Leave a comment

Poj Solution 2773

http://poj.org/problem?id=2773 //* @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()) { int a=in.nextInt(); int b=in.nextInt(); if(a==1)System.out.println(b); else{ ArrayList< Integer> arr=new ArrayList< Integer>(); for(int i=1;i< a;i++) { int m=a,n=i; while(m%n!=0) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 2769

http://poj.org/problem?id=2769 //* @author mekarlos@gmail.com import java.util.Hashtable; import java.util.Scanner; public class Main { public static void main(String[] args) { Hashtable< Integer,Integer> table; Scanner scan=new Scanner(System.in); int M[]=new int[300]; int n=scan.nextInt(),k=0,m=1; boolean band=false; for(int i=0;i< n;i++){ k=scan.nextInt(); band=true; table=new Hashtable< Integer, Integer>(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 2766

http://poj.org/problem?id=2766 /* @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 dx[]={0,1,0,-1},dy[]={1,0,-1,0}; int g[][]=new int[52][52]; int ca,i,j,k,n,r,x,y,dir; ca=sc.nextInt(); while ((ca–)!=0) { n=sc.nextInt(); r=sc.nextInt(); for(i=0;i< g.length;i++) Arrays.fill(g[i],0); for … Continue reading

Posted in poj | Leave a comment

Poj Solution 2765

http://poj.org/problem?id=2765 #include <stdio.h> #include <string.h> struct product{ char w[100]; char name[110][100]; int per[110]; int most[110], least[110]; int m; }p[10]; int n; void clac( product &a ) { int s = 0, r = 100, i, j, k, low[100], up[100], sum, … Continue reading

Posted in poj | Leave a comment

Poj Solution 2760

http://poj.org/problem?id=2760 #include "stdio.h" #include "math.h" #include "memory.h" #include "algorithm" using namespace std; #define y1 sdgdsf double clac( double h0, double h1, double x0, double x1 ) { return h0/(h0-h1)*( x1 – x0 ) + x0; } double sum[5048]; struct node … Continue reading

Posted in poj | Leave a comment

Poj Solution 2757

http://poj.org/problem?id=2757 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; import java.math.*; public class Main { public static void main(String args[]) throws Exception { Scanner cin=new Scanner(System.in); BigInteger n; long b; while(cin.hasNext()) { n=cin.nextBigInteger(); b=cin.nextLong(); if(n.compareTo(BigInteger.ZERO)<=0) { System.out.println("0"); continue; } BigInteger ans; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2756

http://poj.org/problem?id=2756 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(" "); BigDecimal a … Continue reading

Posted in poj | Leave a comment

Poj Solution 2751

http://poj.org/problem?id=2751 /* @author: */ import java.util.Scanner; public class Main { static int a[][]=new int[10001][2]; static int b[][]=new int[10001][2]; static int an,bn; static void sort(){ int i,j,t1,t2; for(i=0;i< an;i++) for(j=0;j< an;j++) { if(a[i][0]< a[j][0]) { t1=a[i][0];t2=a[i][1]; a[i][0]=a[j][0];a[i][1]=a[j][1]; a[j][0]=t1;a[j][1]=t2; } } for(i=0;i< … Continue reading

Posted in poj | Leave a comment

Poj Solution 2750

http://poj.org/problem?id=2750 #include "stdio.h" #include "memory.h" const int SIZE = ( 1<<18 ); const int LEAF = ( 1<<17) – 1; int sum[SIZE],l_max[SIZE],r_max[SIZE],l_min[SIZE], r_min[SIZE], min_e[SIZE], s_max[SIZE], s_min[SIZE], pn, n; inline int max( int a, int b ) { return a>b?a:b; } … Continue reading

Posted in poj | Leave a comment

Poj Solution 2749

http://poj.org/problem?id=2749 #include "stdio.h" #include "memory.h" #include "vector" #include "algorithm" #include "functional" #include "math.h" #define max asdfds using namespace std; const int SIZE = 700; typedef pair<int,int> pair_int; int sign[SIZE*2], MS; pair_int e[SIZE*2][SIZE*2], _e[SIZE*2][SIZE*2]; int en[SIZE*2], _en[SIZE*2]; int n; void init( … Continue reading

Posted in poj | Leave a comment

Poj Solution 2748

http://poj.org/problem?id=2748 import java.io.*; 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[] fb=new int[75000]; fb[0]=1; fb[1]=1; for(int i=2;i< 75000;i++) fb[i]=(3*fb[i-1]-fb[i-2]+200000)%100000; while((a–)!=0) { int b=Integer.parseInt(in.readLine()); System.out.println(fb[b%75000]); } } }

Posted in poj | Leave a comment

Poj Solution 2744

http://poj.org/problem?id=2744 /* @author: */ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); double b,v,e,f,t[]=new double[101],t1; int n,a[]=new int[101],r; int i,j,k,dis; while(sc.hasNext()) { n=sc.nextInt(); if(n==0) break; a[0]=0; for(i=1;i<=n;i++) a[i]=sc.nextInt(); b=sc.nextDouble(); r=sc.nextInt(); v=sc.nextDouble(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 2739

http://poj.org/problem?id=2739 import java.util.*; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=1; while(true){ n=sc.nextInt(); if(n==0) break; System.out.println(test2(n)); } } /* * Sum of Consecutive Prime Numbers */ public static int test2(int x){ int count=0; for(int i=2;i+i< … Continue reading

Posted in poj | Leave a comment

Poj Solution 2738

http://poj.org/problem?id=2738 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { static final int M = 2,N = 1000+2; static int value[] = new int[N]; static int map[][][] = new int[N][N][M],n; public static int Get_Num(StreamTokenizer cin) throws Exception{ cin.nextToken(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 2728

http://poj.org/problem?id=2728 //* @author: import java.util.*; import java.math.*; import java.io.FileReader; class Node{ int x,y,z; } public class Main { static int []mark=new int[1010]; static double []dis=new double[1010]; static int []from=new int [1010]; static double sumup,sumdown; static double [][]up=new double [1010][1010]; static … Continue reading

Posted in poj | Leave a comment

Poj Solution 2726

http://poj.org/problem?id=2726 //* @author: 82638882@163.com import java.io.*; import java.util.Arrays; class Main { public static void main(String[] args) throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); while(true) { int a=Integer.parseInt(in.readLine()); if(a==0) break; my[] p=new my[a]; for(int i=0;i< a;i++) { String[] ss=in.readLine().split(" … Continue reading

Posted in poj | Leave a comment

Poj Solution 2724

http://poj.org/problem?id=2724 #include <memory.h> #include <stdio.h> #include <string.h> #define null 0 const int size = 2010; bool e[size][size]; int maxmatch( int n, int m, bool w[][size], int *p) { int p_n[size]; int p_m[size]; bool sign[size]; int q[size],from[size],s,t; int i,j,link,now,h; memset( p_n, … Continue reading

Posted in poj | Leave a comment

Poj Solution 2722

http://poj.org/problem?id=2722 /* @author: */ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); double angle,p,a,b,c,t,l,xa,xb,ya,yb,k1,k2,x1,x2,y1,y2,l2; int n,i; while(sc.hasNext()) { n=sc.nextInt(); if(n==0) break; xa=sc.nextDouble(); ya=sc.nextDouble(); xb=sc.nextDouble(); yb=sc.nextDouble(); l=l2=0; for(i=0;i< n;i++) { t=sc.nextDouble(); l+=t; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2721

http://poj.org/problem?id=2721 /* @author: */ import java.util.Scanner; import java.util.Arrays; public class Main{ private int a,b; private double f1,f2,f3,f4,f5,f6,t1,t2,t3,t4,t5,t6; public Main(int a,int b){ this.a=a; this.b=b; f1=13-a+1;f2=13-b+1;f3=1; t1=13;t2=13;t3=a+b; f4=1;f5=1;f6=26-(a+b)+1; t4=a;t5=b;t6=26; } public static void main(String args[]){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int a=sc.nextInt(); int … Continue reading

Posted in poj | Leave a comment

Poj Solution 2719

http://poj.org/problem?id=2719 import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner cin = new Scanner(System.in); while(true) { String str = cin.nextLine(); char c = str.charAt(0); int re = 0; if(c == ‘0’) break; int size = str.length(); for(int … Continue reading

Posted in poj | Leave a comment

Poj Solution 2711

http://poj.org/problem?id=2711 #include <vector> #include <string.h> #include <math.h> #include <stdio.h> #define min(a,b) (((a)<(b))?(a):(b)) using namespace std; class ff { public: typedef int type; // ��Ȩ���� enum { size = 810 }; // �����ģ enum { max = ( 1<<30 ) }; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2710

http://poj.org/problem?id=2710 //* @author: ccQ.SuperSupper import java.util.*; import java.math.*; public class Main { public static void main(String []args) throws Exception{ int t,cs=1,left,right,i,j; BigInteger a,b,seven; String str1,str2; seven = BigInteger.valueOf(1); for(i=0;i< 10000;++i) seven = seven.multiply(BigInteger.valueOf(7)); Scanner cin = new Scanner(System.in); t = … Continue reading

Posted in poj | Leave a comment

Poj Solution 2707

http://poj.org/problem?id=2707 //* @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 a,b,c,d; int z,nz; while (true){ a=scanner.nextInt(); b=scanner.nextInt(); c=scanner.nextInt(); d=scanner.nextInt(); if (a+b+c+d==0){ break; } if (a*d>b*c){ z=getN(a,c); } else{ … Continue reading

Posted in poj | Leave a comment

Poj Solution 2704

http://poj.org/problem?id=2704 //* @author: 82638882@163.com import java.io.*; public class Main { static int[][] p; static int a; static long[][] w; public static void main(String[] args) throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); while(true) { a=Integer.parseInt(in.readLine()); if(a==-1) break; p=new int[a][a]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2696

http://poj.org/problem?id=2696 //* @author: 82638882@163.com import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); int k=in.nextInt(); while((k–)!=0) { int[] arr=new int[9]; for(int i=0;i< 9;i++) arr[i]=in.nextInt(); int[] y=new int[arr[8]+1]; y[0]=arr[0]; y[1]=arr[1]; y[2]=arr[2]; for(int i=3;i<=arr[8];i++) f(y,i,arr); System.out.println(y[arr[8]]); … Continue reading

Posted in poj | Leave a comment

Poj Solution 2689

http://poj.org/problem?id=2689 import java.util.Scanner; public class Main { final static int MAXVALUE = (int) Math.sqrt(Integer.MAX_VALUE) + 1; public static void main(String[] args) { int k, l, u, tt, index; boolean hasFlg; int a, b, aa, bb; int[] num = new int[MAXVALUE]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2685

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

Posted in poj | Leave a comment

Poj Solution 2681

http://poj.org/problem?id=2681 //* @author: 82638882@163.com import java.util.Scanner; class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); int a=in.nextInt(); in.nextLine(); int u=0; while((a–)!=0) { u++; int[] p=new int[26]; String s1=in.nextLine(); String s2=in.nextLine(); for(int i=0;i< s1.length();i++) { int t=s1.charAt(i)-‘a’; p[t]++; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2680

http://poj.org/problem?id=2680 import java.io.*; import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { int n; BigInteger two,ans; Scanner cin = new Scanner (System.in); while(cin.hasNext()) { n = cin.nextInt(); two = BigInteger.valueOf(2); ans = two; if(n%2==0) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 2679

http://poj.org/problem?id=2679 #include <stdio.h> #include <vector> #include <memory.h> using namespace std; const int size = 1110; struct edge { int len; int fee; edge *next; }; edge e[size][size]; edge *link[size]; bool sign[size]; int m, n, begin, end; int fee[size]; void search( … Continue reading

Posted in poj | Leave a comment

Poj Solution 2678

http://poj.org/problem?id=2678 #include<iostream> #include"stdio.h" #include"math.h" #include<vector> #include<algorithm> using namespace std; const double eps=1e-8; const int size = 1010; //////////////////////////////// typedef double Type;/*????????*/ //////////////////////////////// struct point { Type x,y; point(){x=y=0;} point(Type x,Type y):x(x),y(y){;} bool operator==(point &a){return x==a.x&&y==a.y;} }; //???? inline Type cheng(point … Continue reading

Posted in poj | Leave a comment

Poj Solution 2677

http://poj.org/problem?id=2677 #include <stdio.h> #include <memory.h> #include <math.h> struct point { double x, y; }; double dis( point &a, point &b ) { return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) ); } double s[1010][1010]; point p[1010]; int main( ) { int n, i, … Continue reading

Posted in poj | Leave a comment

Poj Solution 2676

http://poj.org/problem?id=2676 //* @author: 82638882@163.com import java.io.*; class Main { public static void main(String[] args) throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); int cnt=Integer.parseInt(in.readLine()); while((cnt–)!=0) { int[][] p=new int[9][9]; for(int i=0;i< 9;i++) { for(int j=0;j< 9;j++) p[i][j]=in.read()-‘0’; in.readLine(); } … Continue reading

Posted in poj | Leave a comment

Poj Solution 2675

http://poj.org/problem?id=2675 #include <stdio.h> #include <algorithm> #include <string.h> #include <math.h> const double eps = 1e-6; using namespace std; double v[70000]; int id[70000], s[70000], l[70000]; bool cmp( int a, int b ) { return v[a]*l[b] < v[b]*l[a]; } int main( ) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 2673

http://poj.org/problem?id=2673 /* @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 total,per,t,max; total=sc.nextInt(); per=sc.nextInt(); t=sc.nextInt(); max=total; while((t–)!=0) { int dis,speed,fir,sum; dis=sc.nextInt(); speed=sc.nextInt(); if(speed==0) continue; if(speed>=dis) max=0; fir=dis/speed; if(dis%speed==0) fir–; sum=fir+(total-fir)/2; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2672

http://poj.org/problem?id=2672 #include <stdio.h> #include <string.h> #include <memory.h> //�����ͼ���ƥ�䣬 //����ƥ�����wΪn*m�ڽӾ���,p������X( |X|=n )ƥ��Ķ����� #define null 0 const int size=30; bool maxmatch(int n,int m,bool w[][size],int *p) { int p_n[size]; int p_m[size]; bool sign[size]; int q[size],from[size],s,t; int i,j,link,now,h; for(i=0;i<n;i++)p_n[i]=-1; for(j=0;j<m;j++)p_m[j]=-1; for(i=0;i<n;i++) if(p_n[i]==-1) { for(j=0;j<m;j++)sign[j]=0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2669

http://poj.org/problem?id=2669 #include <stdio.h> #include <memory.h> #include <vector> #include <algorithm> using namespace std; double dis[100][100]; int n, m; bool e[100][100]; int son[100]; double len[100]; bool sign [100]; int v2[100], v[100], vn2, vn; int calc2( int a, int f ) { int … Continue reading

Posted in poj | Leave a comment

Poj Solution 2665

http://poj.org/problem?id=2665 //* @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 s,n,tn; while (true){ s=scanner.nextInt(); n=scanner.nextInt(); if (s==0&&n==0){ break; } tn=s+1; for (int i=0;i< n ;i++ ){ tn=tn+scanner.nextInt()-scanner.nextInt()-1; } … Continue reading

Posted in poj | Leave a comment