Author Archives: toad, die

Poj Solution 3219

http://poj.org/problem?id=3219 //* @author: import java.util.*; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=0; int k=0; int m=0; while(sc.hasNext()){ int a=0; int b=0; int c=0; n=sc.nextInt(); k=sc.nextInt(); m=n-k; while((n=n>>1)!=0) //��n�ĸ������λ����һλ�����൱�ڳ���2 a+=n; while((m=m>>1)!=0) b+=m; while((k=k>>1)!=0) c+=k; if(a-b>c) … Continue reading

Posted in poj | Leave a comment

Poj Solution 3217

http://poj.org/problem?id=3217 #include <stdio.h> #include <memory.h> #include <vector> using namespace std; vector<int> ch[101]; int father[101], mother[101]; bool gender[101]; int A, B; void input( ) { int i, h, t; scanf( "%d%d", &A, &B ); for( i=0; i<101; i++ ) ch[i].clear( ); … Continue reading

Posted in poj | Leave a comment

Poj Solution 3214

http://poj.org/problem?id=3214 #include <stdio.h> #include <memory.h> #include <vector> #include <algorithm> using namespace std; vector<int> v[20]; int a[2100000]; int t[2100000]; int n, m, h; int vn[20]; void input( ) { int i, j; scanf( "%d", &m ); for( i=0; i<m; i++ ) … Continue reading

Posted in poj | Leave a comment

Poj Solution 3212

http://poj.org/problem?id=3212 #include <stdio.h> #include <memory.h> #include <vector> #include <algorithm> using namespace std; #define __int64 long long const int size = 100010; __int64 s[size]; int ss[size]; int m; int pos[100100]; //��� void clear( ) { memset( s, 0, sizeof s ); … Continue reading

Posted in poj | Leave a comment

Poj Solution 3211

http://poj.org/problem?id=3211 #include <stdio.h> #include <vector> #include <string> #include <set> using namespace std; vector<int> v[10]; string color[10]; set<int> s; int main( ) { int n, m, i, j, ans, sum, t, best; char w[100]; while( scanf( "%d%d", &m, &n ) == … Continue reading

Posted in poj | Leave a comment

Poj Solution 3210

http://poj.org/problem?id=3210 //* @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; while (true){ n=scanner.nextInt(); if (n==0){ break; } if (n%2==0){ System.out.println("No Solution!"); } else{ System.out.println(n-1); } } } … Continue reading

Posted in poj | Leave a comment

Poj Solution 3208

http://poj.org/problem?id=3208 /* @author: */ import java.util.Scanner; public class Main { static int s[][]=new int[14][4]; static int to[][]=new int[4][10]; static void doit( ) { int i, j, k; for( i=0; i< 3; i++ ) for( j=0; j< 10; j++ ) to[i][j] … Continue reading

Posted in poj | Leave a comment

Poj Solution 3199

http://poj.org/problem?id=3199 import java.io.BufferedInputStream; import java.math.BigDecimal; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(new BufferedInputStream(System.in)); while (scan.hasNext()) { BigDecimal n = scan.nextBigDecimal(); int d = scan.nextInt(); if (d == 0 && n.equals(BigDecimal.ZERO)) … Continue reading

Posted in poj | Leave a comment

Poj Solution 3198

http://poj.org/problem?id=3198 /* @author: */ import java.math.BigInteger; import java.util.*; public class Main { public static BigInteger get( BigInteger h ) { BigInteger s = h.shiftLeft(1); BigInteger a = BigInteger.ONE.shiftLeft( s.bitLength()/2-1 ).subtract( BigInteger.ONE ); BigInteger b = BigInteger.ONE.shiftLeft( s.bitLength()/2+1 ), c; while( … Continue reading

Posted in poj | Leave a comment

Poj Solution 3194

http://poj.org/problem?id=3194 /* @author: */ import java.util.Scanner; import java.util.Arrays; public class Main{ static int p[][]=new int[105][105]; static int q[][]=new int[101][101]; static int n,cnt; static void dfs(int i,int j) { if(i>n||j>n||i< 1||j< 1) return; q[i][j]=cnt; if(q[i][j+1]==0&&p[i][j]==p[i][j+1]) dfs(i,j+1); if(q[i][j-1]==0&&p[i][j]==p[i][j-1]) dfs(i,j-1); if(q[i+1][j]==0&&p[i][j]==p[i+1][j]) dfs(i+1,j); if(q[i-1][j]==0&&p[i][j]==p[i-1][j]) … Continue reading

Posted in poj | Leave a comment

Poj Solution 3193

http://poj.org/problem?id=3193 //* @author: <strong>Yeming&nbsp;Hu</strong>&quot;cslittleye@gmail.com&quot; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String mn = sc.nextLine(); Scanner lmn = new Scanner(mn); int m = lmn.nextInt(); int n = lmn.nextInt(); String[] phrases … Continue reading

Posted in poj | Leave a comment

Poj Solution 3192

http://poj.org/problem?id=3192 #include <stdio.h> #include <algorithm> #include <string> #include <string.h> using namespace std; int index[7]; char sum[100]; char str[7][10]; int len[7]; int merge( int len, char *w, int l ) { int i = len-l, j; if( i<0 ) i = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3191

http://poj.org/problem?id=3191 /* @author: */ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int i, n, h; boolean s[]=new boolean[100]; n=sc.nextInt(); if( n == 0 ) { System.out.printf( "0n" ); return ; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3190

http://poj.org/problem?id=3190 #include <stdio.h> #include <algorithm> #include <string> #include <string.h> using namespace std; int empty[50000]; int use[50000]; int a[50000], b[50000]; typedef pair<int,int> p_i; p_i p[100000]; int main( ) { int i, n, m, ans=0; scanf( "%d", &n ); for( i=0; i<n; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3189

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

Posted in poj | Leave a comment

Poj Solution 3188

http://poj.org/problem?id=3188 #include <stdio.h> #include <algorithm> using namespace std; char w[1000][11]; int button[26]; __int64 a[1000]; int n, B, L; int flag[26]; void clac( int &s1, int &s2 ) { int i, j; s1 = 0, s2 = 0; flag[B] = 100; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3187

http://poj.org/problem?id=3187 //* @author: 82638882@163.com import java.io.*; import java.util.Arrays; public class Main { static int[] p,arr; static int a; 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]); int sum=Integer.parseInt(ss[1]); p=new int[a]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3186

http://poj.org/problem?id=3186 //* @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); String s=in.readLine(); int a=Integer.parseInt(s); int[] arr=new int[a]; int[][] ds=new int[a][a]; for(int i=0;i< a;i++) { s=in.readLine(); arr[i]=Integer.parseInt(s); … Continue reading

Posted in poj | Leave a comment

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