# Monthly Archives: June 2015

## 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

## 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

## 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

## 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

## 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

## 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

## 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

## 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

## 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

## 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

## 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