Category Archives: poj

Poj Solution 3185

http://poj.org/problem?id=3185 /* @author: */ import java.util.Scanner; public class Main { static boolean b[]=new boolean[20]; static void set( int k ) { if( k !=0) b[k-1] = !b[k-1]; b[k] = !b[k]; if( k< 19 ) b[k+1] = !b[k+1]; } public static … Continue reading

Posted in poj | Leave a comment

Poj Solution 3184

http://poj.org/problem?id=3184 #include <stdio.h> #include <algorithm> #include <math.h> #include <memory.h> using namespace std; int l[10000]; int temp[2][10001], *ans1 = temp[0], *ans2 = temp[1]; int main( ) { int n, len, i, j, d1, d2, rest, t, k, *ans_i_j, *ans_i1_j; scanf( "%d%d", … Continue reading

Posted in poj | Leave a comment

Poj Solution 3183

http://poj.org/problem?id=3183 /* @author: */ import java.util.Scanner; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class Main{ static final int MAX=50001; public static void main(String args[]) throws IOException{ BufferedReader buff = new BufferedReader(new InputStreamReader(System.in)); // Scanner sc = new Scanner (System.in);//�����Ȼ��ʱ int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3181

http://poj.org/problem?id=3181 //* @author:alpc12 import java.io.*; import java.util.*; import java.math.*; public class Main { final int N = 1010; BigInteger[] dp = new BigInteger[N]; void run() { Scanner cin = new Scanner(System.in); while(cin.hasNext()) { int i, j; int n = cin.nextInt(), … Continue reading

Posted in poj | Leave a comment

Poj Solution 3180

http://poj.org/problem?id=3180 #include <stdio.h> #include <algorithm> #include <vector> #include <memory.h> using namespace std; class Graph { public: enum { MAX_NUM_EDGE = 50010, MAX_NUM_NODE = 10010 }; struct Edge { int to; Edge *next; }e[2*MAX_NUM_EDGE]; int en; Edge *e_begin[MAX_NUM_NODE], *e_reverse[MAX_NUM_NODE], *e_end[MAX_NUM_NODE]; Edge … Continue reading

Posted in poj | Leave a comment

Poj Solution 3179

http://poj.org/problem?id=3179 #include <stdio.h> #include <algorithm> using namespace std; int sum[1024][1024],s; inline int lowbit(int a) { return a&(a^(a-1)); } void init( ) { int i,j; for(i=1;i<=s;i++) for(j=1;j<=s;j++) sum[i][j]=0; } void set( int x, int y ) { int j; x++,y++; while(x<=s) … Continue reading

Posted in poj | Leave a comment

Poj Solution 3177

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

Posted in poj | Leave a comment

Poj Solution 3176

http://poj.org/problem?id=3176 import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int height = cin.nextInt(); int[][] tree = new int[height][height]; int[][] max = new int[height][height]; int maxValue = 0; int left, right = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3174

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

Posted in poj | Leave a comment

Poj Solution 3173

http://poj.org/problem?id=3173 import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); String[] str = cin.nextLine().split(" "); int N = Integer.valueOf(str[0]).intValue(); int S = Integer.valueOf(str[1]).intValue(); int[][] Tri = new int[N][N]; for(int j = 0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3171

http://poj.org/problem?id=3171 #include <stdio.h> #include <algorithm> using namespace std; int t1[10000], t2[10000], f[10000], t[10000], fee[10000]; int id[10000]; bool cmp( int a, int b ) { return t2[a] < t2[b]; } int main( ) { int i, n, m, e, tn, x, … Continue reading

Posted in poj | Leave a comment

Poj Solution 3168

http://poj.org/problem?id=3168 #include <stdio.h> #include <memory.h> #include <algorithm> using namespace std; bool sign[25000]; struct corner { int x, y; int id; int key; }c[100010]; int key; bool cmp( const corner &a, const corner &b ) { return a.x<b.x || a.x==b.x && … Continue reading

Posted in poj | Leave a comment

Poj Solution 3167

http://poj.org/problem?id=3167 #include <stdio.h> #include <memory.h> #include <algorithm> using namespace std; int ss[26][25010], sn[27], last[26]; int aa[26][100010], an[27], S, N, K; int pos[26][100010]; int next[25010]; int sign[130000]; int flag[130000]; void clac_next( int a[], int n ) { int i=1, j=0; next[1] … Continue reading

Posted in poj | Leave a comment

Poj Solution 3159

http://poj.org/problem?id=3159 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; class node implements Comparable{ int v,next,disten; node(){ v = next = disten = -1; } node(int v,int next,int disten){ this.v = v; this.next = next; this.disten = disten; } void set_node(int v,int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3158

http://poj.org/problem?id=3158 //* @author mekarlos@gmail.com import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan=new Scanner(System.in); String s1,s2,s; int[] m; int k,v1,v2; boolean band; while(scan.hasNext()){ s1=scan.next(); s2=scan.next(); s=s1; for(int i=0;i< s2.length();i++)s+="1"; k=-1; for(int i=0;i<=s.length();i++){ band=true; for(int j=0;j< … Continue reading

Posted in poj | Leave a comment

Poj Solution 3157

http://poj.org/problem?id=3157 import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); while(cin.hasNext()) { String str = cin.nextLine(); int type = checkType(str); if(type == -1) System.out.println("Error!"); else if(type == 1) { StringBuffer sb = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3146

http://poj.org/problem?id=3146 /* @author: */ import java.util.Scanner; public class Main { static int clac( int s, int p, int n ) { if( s < p ) return 0; return (s-n%s-1)*(n/s) + clac( s/p, p, n%s )*((n+s-1)/s); } public static void … Continue reading

Posted in poj | Leave a comment

Poj Solution 3141

http://poj.org/problem?id=3141 #include <stdio.h> #include <math.h> #include <algorithm> using namespace std; pair<int,int> p[100], q[100]; int n; bool input( ) { int i; scanf( "%d", &n ); if( n == 0 ) return false; for( i=0; i<n; i++ ) scanf( "%d%d", &p[i].first, … Continue reading

Posted in poj | Leave a comment

Poj Solution 3140

http://poj.org/problem?id=3140 #include <stdio.h> #include <math.h> #include <vector> using namespace std; double ans, total; vector<int> e[100100]; int s[100100]; double dfs( int k, int f ) { double sum = 0, t; for( int i=0; i<e[k].size(); i++ ) { if( e[k][i] != … Continue reading

Posted in poj | Leave a comment

Poj Solution 3139

http://poj.org/problem?id=3139 #include <stdio.h> #include <algorithm> using namespace std; int has_one[1<<16]; int ans[1<<16]; int result[1<<16][24]; int a[16]; void clac_has_one( ) { int i; has_one[0] = 0; for( i=1; i<(1<<16); i++ ) has_one[i] = has_one[ i&(i-1) ] + 1; } void clac_result( … Continue reading

Posted in poj | Leave a comment

Poj Solution 3138

http://poj.org/problem?id=3138 //* @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 p[]=new int[101]; int i,j,n,s,t,m,id,t1,t2,sum,sid,tot,cas=0;; while (true) { s=sc.nextInt();t=sc.nextInt();m=sc.nextInt(); if (s==0&&t==0&&m==0) break; for (i=1;i<=100;i++) p[i]=0;sum=0;cas++; for (i=1;i<=s;i++) { id=sc.nextInt(); t1=sc.nextInt(); t2=sc.nextInt(); if … Continue reading

Posted in poj | Leave a comment

Poj Solution 3134

http://poj.org/problem?id=3134 #include <stdio.h> bool sign[1010]; int a[20]; int ans, best; int search( int k, int big ) { int b = 1000, t, temp, sb; if( a[k] == ans ) { best = k; return 0; } if( k >= … Continue reading

Posted in poj | Leave a comment

Poj Solution 3132

http://poj.org/problem?id=3132 //* @author: import java.io.BufferedInputStream; import java.util.ArrayList; import java.util.Scanner; public class Main { static ArrayList< Integer> primes = Prime.getPrimes(1120); public static void main(String[] args) { int[][] f = new int[1140][1140]; Scanner scan = new Scanner(new BufferedInputStream(System.in)); f[0][0] = 1; for … Continue reading

Posted in poj | Leave a comment

Poj Solution 3130

http://poj.org/problem?id=3130 #include <stdio.h> #include <math.h> #include <memory.h> #include <algorithm> using namespace std; 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 a,point b,point c) {return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);} inline Type … Continue reading

Posted in poj | Leave a comment

Poj Solution 3129

http://poj.org/problem?id=3129 #include <stdio.h> #include <math.h> struct point { double x, y, z; }; double dcheng( point &a, point &b ) { return a.x*b.x+a.y*b.y+a.z*b.z; } point p[500], q[50]; double r[50]; int main( ) { int i, j, n, m, counter; double … Continue reading

Posted in poj | Leave a comment

Poj Solution 3128

http://poj.org/problem?id=3128 /* @author: */ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t, i, c, j; char w[]=new char[100]; boolean s[]=new boolean[100]; int ans[]=new int[100]; t=sc.nextInt(); while(( t– )!=0) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 3126

http://poj.org/problem?id=3126 import java.io.BufferedInputStream; import java.util.LinkedList; import java.util.Scanner; public class Main { static boolean[] isPrime = Prime.getPrimes(10000); public static void main(String[] args) { Scanner scan = new Scanner(new BufferedInputStream(System.in)); int cas = scan.nextInt(); for (int i = 1; i <= cas; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3125

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

Posted in poj | Leave a comment

Poj Solution 3122

http://poj.org/problem?id=3122 /* @author: */ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int r[]=new int[10000], t, i, n, f, count; double a, b, c; t=sc.nextInt(); while(( t–)!=0 ) { n=sc.nextInt(); f=sc.nextInt(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 3119

http://poj.org/problem?id=3119 #include <stdio.h> #include <math.h> #include <stdlib.h> int sx[65536], sy[65536]; int c, r, to; const int dx[] = { 0, 1, 0, -1 }, dy[] = { 1, 0, -1, 0 }; void next( int &x, int &y ) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 3117

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

Posted in poj | Leave a comment

Poj Solution 3115

http://poj.org/problem?id=3115 #include <stdio.h> #include <math.h> #include <stdlib.h> #include <algorithm> using namespace std; int main( ) { __int64 m[4][2], *ans = m[0], *temp = m[1], *id = m[2], *idt = m[3], s1, s2, mem[2][20], *res = mem[0], *rest = mem[1]; int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3114

http://poj.org/problem?id=3114  

Posted in poj | Leave a comment

Poj Solution 3112

http://poj.org/problem?id=3112 #include <stdio.h> int m[1000]; int main( ) { int n, p, c, i, j, t, ans; while( 1 ) { scanf( "%d%d%d", &p, &n, &c ); if( n == 0 && p == 0 && c == 0 ) … Continue reading

Posted in poj | Leave a comment

Poj Solution 3111

http://poj.org/problem?id=3111 #include <stdio.h> #include <algorithm> using namespace std; struct node{ int v, w, id; }nd[100010]; double r; bool cmp( node &a, node &b ) { return a.v-a.w*r > b.v-b.w*r; } int main( ){ int n, k, i; double t, s1, … Continue reading

Posted in poj | Leave a comment

Poj Solution 3110

http://poj.org/problem?id=3110 #include <stdio.h> #include <queue> using namespace std; int days[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int getDays( int dd, int mm, int year ) { int res = (year-1700)*365 … Continue reading

Posted in poj | Leave a comment

Poj Solution 3109

http://poj.org/problem?id=3109 #include <stdio.h> #include <memory.h> #include <algorithm> using namespace std; const int size = 100010; int s[size]; int m; //��� void clear( ) { memset( s, 0, sizeof s ); } inline int lowbit(int a) { return a&(a^(a-1)); } //����a[y] … Continue reading

Posted in poj | Leave a comment

Poj Solution 3106

http://poj.org/problem?id=3106 #include <stdio.h> static char str[100010]; static char input[310][310], ans[310][310]; static int n, m; static int doit( int s ) { int i = s/1000, j = s%1000, a = i, b = j; int nn = n; int mm … Continue reading

Posted in poj | Leave a comment

Poj Solution 3105

http://poj.org/problem?id=3105 /* @author: */ import java.util.*; import java.io.*; import java.lang.reflect.Array; public class Main { static public void main( String [] string ) throws Exception{ Scanner cin = new Scanner( System.in ); int m = cin.nextInt(); int n, i, p1, p0, … Continue reading

Posted in poj | Leave a comment

Poj Solution 3104

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

Posted in poj | Leave a comment

Poj Solution 3102

http://poj.org/problem?id=3102 /* @author: */ import java.util.*; import java.io.*; import java.lang.reflect.Array; public class Main { static double dis[][]; static int e[][]; static int [] x, y, en; static double distance( int a, int b ) { return Math.sqrt( (x[a]-x[b])*(x[a]-x[b]) + (y[a]-y[b])*(y[a]-y[b]) … Continue reading

Posted in poj | Leave a comment

Poj Solution 3101

http://poj.org/problem?id=3101 import java.util.*; import java.math.*; public class Main { public static int[] p=new int[3000]; public static int pc; public static int[] a=new int[3000]; public static boolean[] che=new boolean[10001]; public static void init(){ int t1=2; while(t1*t1<=10000){ int t2=t1*t1; while(t2<=10000){ che[t2]=true; t2+=t1; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3100

http://poj.org/problem?id=3100 import java.util.*; import java.io.*; import java.lang.reflect.Array; public class Main { static public void main( String [] string ) throws Exception{ Scanner cin = new Scanner( System.in ); int b, n; while( true ) { b = cin.nextInt(); n = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3096

http://poj.org/problem?id=3096 //* @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))); boolean flag; int index; String s; String[] pair; while (true){ s=scanner.next(); if (s.equals("*")){ break; } if (s.length()==1){ System.out.println(s+" is … Continue reading

Posted in poj | Leave a comment

Poj Solution 3095

http://poj.org/problem?id=3095 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)); String s; while (!(s = read.readLine()).equals("#")) { char[] c = s.toCharArray(); int[] p = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3094

http://poj.org/problem?id=3094 //* @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))); String s; int total; while (true){ s=scanner.nextLine(); if (s.equals("#")){ break; } total=0; for (int i=0;i< s.length() ;i++ ){ total=total+(i+1)*getValue(s.charAt(i)); … Continue reading

Posted in poj | Leave a comment

Poj Solution 3093

http://poj.org/problem?id=3093 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { static final int N = 30+5; static final int M = 1000+10; static int n,m; static int DP[] = new int[M],value[] = new int[N]; public static void main(String … Continue reading

Posted in poj | Leave a comment

Poj Solution 3092

http://poj.org/problem?id=3092 /* @author: */ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n, i, k, t, tt, p, count = 0; tt=sc.nextInt(); while(( tt– )!=0) { n=sc.nextInt(); int a[]=new int[100]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3091

http://poj.org/problem?id=3091 /* @author: */ import java.util.*; import java.io.*; import java.lang.reflect.Array; public class Main { static public void main( String [] str ) throws Exception{ int n; int m; Scanner cin = new Scanner( System.in ); n = cin.nextInt(); for( int … Continue reading

Posted in poj | Leave a comment

Poj Solution 3090

http://poj.org/problem?id=3090 //* @author: import java.util.*; public class Main { public static void main(String[] args){ int[] p=new int[1001]; p[1]=3; p[2]=5; Scanner cin=new Scanner(System.in); int T=cin.nextInt(); for(int a=3;a<=1000;a++){ p[a]=p[a-1]+2; for(int i=2;i<=a;i++) p[a]+=2*c(a,i); } for(int t=1;t<=T;t++){ int r=cin.nextInt(); System.out.println(t+" "+r+" "+p[r]); } } … Continue reading

Posted in poj | Leave a comment