# 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).intValue(); int S = Integer.valueOf(str).intValue(); int[][] Tri = new int[N][N]; for(int j = 0; … Continue reading

Posted in poj | Comments Off on Poj Solution 3173

## Poj Solution 3171

http://poj.org/problem?id=3171 #include <stdio.h> #include <algorithm> using namespace std; int t1, t2, f, t, fee; int id; 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 | Comments Off on Poj Solution 3171

## Poj Solution 3168

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

Posted in poj | Comments Off on Poj Solution 3168

## Poj Solution 3167

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

Posted in poj | Comments Off on Poj Solution 3167

## 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 | Comments Off on Poj Solution 3159

## 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 | Comments Off on Poj Solution 3158

## 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 | Comments Off on Poj Solution 3157

## 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 | Comments Off on Poj Solution 3146

## Poj Solution 3141

http://poj.org/problem?id=3141 #include <stdio.h> #include <math.h> #include <algorithm> using namespace std; pair<int,int> p, q; 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 | Comments Off on Poj Solution 3141

## 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; int s; 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 | Comments Off on Poj Solution 3140

## 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]; int a; void clac_has_one( ) { int i; has_one = 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 | Comments Off on Poj Solution 3139

## 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; 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 | Comments Off on Poj Solution 3138

## Poj Solution 3134

http://poj.org/problem?id=3134 #include <stdio.h> bool sign; int a; 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 | Comments Off on Poj Solution 3134