Author Archives: toad, die

Poj Solution 2101

http://poj.org/problem?id=2101 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n = cin.nextInt(); int e = cin.nextInt(); double l1 = 0, l2 = 0; while(–n > 0) { l1 += cin.nextInt(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 2092

http://poj.org/problem?id=2092 //* @author: 82638882@163.com import java.io.*; import java.util.*; import java.util.Map.Entry; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); HashMap< Integer,Integer> ts=new HashMap< Integer,Integer>(); while(true) { String[] ss=in.readLine().split(" "); int … Continue reading

Posted in poj | Leave a comment

Poj Solution 2088

http://poj.org/problem?id=2088 #include<iostream> #include"algorithm" using namespace std; int dis[21][21]; int tim[21],n; int id[21],mint[21]; int cmp(int a,int b) { return mint[a]<mint[b]; } void init() { int i,j,k; for(i=0;i<n;i++) cin>>tim[i]; for(i=0;i<n;i++) for(j=0;j<n;j++) { cin>>dis[i][j]; } for(k=0;k<n;k++) for(i=0;i<n;i++) for(j=0;j<n;j++) if(dis[i][k]+dis[k][j]<dis[i][j]) dis[i][j]=dis[i][k]+dis[k][j]; for(i=0;i<n;i++) { mint[i]=9999;id[i]=i; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2087

http://poj.org/problem?id=2087 #include<iostream> #include"stdio.h" #include"math.h" #include<algorithm> using namespace std; ///////////////////////// #define Type double /*�������*/ ///////////////////////// struct point { Type x,y; int host; }; const double pi=3.1415926535898; 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 dcheng(point a,point b,point c) {return … Continue reading

Posted in poj | Leave a comment

Poj Solution 2085

http://poj.org/problem?id=2085 import java.util.Scanner; public class Main{ public static void main(String args[]){ int n,m; int i,j,k,sum; Scanner sc=new Scanner(System.in); while(true) { n=sc.nextInt(); m=sc.nextInt(); if(n==-1&&m==-1)break; sum=0; for(i=n;i>=1;i–) { sum+=(n-i); if(sum>=m)break; } for(j=1;j< i;j++) System.out.printf("%d ",j); k=m+i-(n-i)*(n-i-1)/2; System.out.printf("%d",k); for(j=n;j>=i;j–) if(j!=k) System.out.printf(" %d",j); System.out.printf("n"); … Continue reading

Posted in poj | Leave a comment

Poj Solution 2084

http://poj.org/problem?id=2084 import java.io.*; import java.util.*; import java.math.BigInteger; public class Main { public static void main(String[]args){ Scanner sin=new Scanner(new BufferedInputStream(System.in)); int n; int i = 0; BigInteger big[] = new BigInteger[101]; for(i = 0 ; i < 101 ; i++) big[i] … Continue reading

Posted in poj | Leave a comment

Poj Solution 2083

http://poj.org/problem?id=2083 //* @author: 82638882@163.com import java.util.Scanner; class Main { static StringBuffer sb=new StringBuffer(); public static void main(String[] args) { Scanner in=new Scanner(System.in); while(true) { int a=in.nextInt(); if(a==-1) break; else if(a==1) System.out.println(‘X’); else g("",a-1); System.out.println("-"); } } static void p(int a) … Continue reading

Posted in poj | Leave a comment

Poj Solution 2082

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

Posted in poj | Leave a comment

Poj Solution 2080

http://poj.org/problem?id=2080 import java.util.*; import java.lang.*; import java.io.*; import java.text.*; public class Main{ public static void main(String[] args) throws IOException{ Date twoK,res,t1,t2; long twoKl,resl,t; //��EEEE������4λΪȫ�ƣ������Ϻ���ġ�Locale.US�������ڻ��������Ŷ�� SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd EEEE",Locale.US); //BufferedInputStream bin = new BufferedInputStream(new FileInputStream("in.txt")); //System.setIn(bin); Scanner cin = … Continue reading

Posted in poj | Leave a comment

Poj Solution 2079

http://poj.org/problem?id=2079 #include<iostream> #include"stdio.h" #include<algorithm> //ifstream in("triangle.in"); //#define cin in using namespace std; ///////////////////////// #define Type long /*�������*/ ///////////////////////// 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;} }; int cmp_x_y(point a,point b) {return a.y<b.y||(a.y==b.y&&a.x<b.x);} void sort(point *a,int … Continue reading

Posted in poj | Leave a comment

Poj Solution 2078

http://poj.org/problem?id=2078 #include "stdio.h" int a[10][10], ans, n; int k[10],sum[10]; void doit( int s ) { int i, maxv; if( s == n ) { maxv = -1; for( i=0; i<n; i++ ) if( sum[i] > maxv ) maxv = sum[i]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2076

http://poj.org/problem?id=2076 #include<iostream> #include"algorithm" using namespace std; int dist[101][101],n,m; void init() { int i,a,b,d,j,k; cin>>n>>m; for(i=0;i<n;i++) for(j=0;j<n;j++) dist[i][j]=9999; for(i=0;i<m;i++) { cin>>a>>b>>d; a–;b–; if(d<dist[a][b]) { dist[a][b]=dist[b][a]=d; } } for(i=0;i<n;i++) dist[i][i]=0; for(k=0;k<n;k++) for(i=0;i<n;i++) for(j=0;j<n;j++) if(dist[i][k]+dist[k][j]<dist[i][j]) dist[i][j]=dist[i][k]+dist[k][j]; return ; } int answer[101]; int c1,c2; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2075

http://poj.org/problem?id=2075 //* @author: SmilingWang import java.util.*; public class Main { public static final int BLOCK = Integer.MAX_VALUE; public static final double zero = 1e-6; public static double cl; public static void main(String[] args){ Scanner in = new Scanner(System.in); cl = … Continue reading

Posted in poj | Leave a comment

Poj Solution 2070

http://poj.org/problem?id=2070 //* @author: 82638882@163.com import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); while(in.hasNext()) { float a=in.nextFloat(); float b=in.nextFloat(); float c=in.nextFloat(); if(a==0&&b==0&&c==0) break; boolean s=true; if(a<=4.5&&b>=150&&c>=200){ System.out.print("Wide Receiver "); s=false; } if(a<=6&&b>=300&&c>=500){ System.out.print("Lineman "); … Continue reading

Posted in poj | Leave a comment

Poj Solution 2069

http://poj.org/problem?id=2069 #include<iostream> #include"stdio.h" #include"math.h" using namespace std; #define sq(a) ((a.x)*(a.x)+(a.y)*(a.y)+(a.z)*(a.z)) int n; typedef double det[3][3]; struct point { double x,y,z; }; double hls(det a) { return a[0][0]*a[1][1]*a[2][2]+a[0][1]*a[1][2]*a[2][0]+a[0][2]*a[1][0]*a[2][1] -a[0][2]*a[1][1]*a[2][0]-a[0][1]*a[1][0]*a[2][2]-a[0][0]*a[1][2]*a[2][1]; } bool qiujie(det s,double s0,double s1,double s2,point &o) { det t={{s0,s[0][1],s[0][2]},{s1,s[1][1],s[1][2]},{s2,s[2][1],s[2][2]}}; double … Continue reading

Posted in poj | Leave a comment

Poj Solution 2064

http://poj.org/problem?id=2064 //* @author:alpc12 import java.io.*; import java.util.*; class Layer { int cost; int frontier[]; int frontierCode; Layer(int f[], int c) { cost = c; frontier = new int[f.length]; frontierCode = 0; for (int i=0; i< frontier.length; i++) frontier[i] = f[i]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2061

http://poj.org/problem?id=2061 //* @author:alpc12 /* Sample solution to D – Pseudo random numbers / Mikael Goldmann * First count backwards to recreate the seed number * The count forwards to get T:th number. Try using few columns to * save space. … Continue reading

Posted in poj | Leave a comment

Poj Solution 2060

http://poj.org/problem?id=2060 #include <memory.h> #include <stdio.h> #include <math.h> #define null 0 #define y1 yy1 const int size = 510; //size must be bigger than n and m. //nС��mʱЧ�ʸ� int maxmatch( int n, int m, bool w[][size], int *p) { int p_n[size]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2054

http://poj.org/problem?id=2054 #include <stdio.h> #include <vector> #include <set> using namespace std; struct node { int id; int num; int cost; int sigma_c; node *father; vector <node *> child; bool colored; }t[1000]; struct cmp { bool operator()( node *a, node *b )const … Continue reading

Posted in poj | Leave a comment

Poj Solution 2051

http://poj.org/problem?id=2051 import java.util.Scanner; public class Main { private static Query[] query = new Query[1002]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int i = 0; while (sc.hasNext()) { String s = sc.nextLine(); if (s.equals("#")) { int … Continue reading

Posted in poj | Leave a comment

Poj Solution 2049

http://poj.org/problem?id=2049 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<string.h> #include<math.h> #define INF 30000 #define NMAX 201 int a[NMAX][NMAX]; int map[NMAX][NMAX][4]; int yp[4]={1,0,-1,0},xp[4]={0,1,0,-1}; int M,N; int x,y,d,t; void init() { for(int i=0;i<=200;i++) { map[0][i][2]=-1; map[200][i][0]=-1; map[i][0][3]=-1; map[i][200][1]=-1; } } typedef struct { int y,x; }DATA; … Continue reading

Posted in poj | Leave a comment

Poj Solution 2042

http://poj.org/problem?id=2042 /* @author: */ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n, s, t1, t2, t; while( sc.hasNext() ) { n=sc.nextInt(); if( n == 0 ) break; s = … Continue reading

Posted in poj | Leave a comment

Poj Solution 2039

http://poj.org/problem?id=2039 import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int num = 0; String str; char[][] array; while(true) { num = Integer.valueOf(cin.nextLine()).intValue(); if(num == 0) break; else { str = cin.nextLine(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 2035

http://poj.org/problem?id=2035 /* @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 c[][]=new int[11][53],p[]=new int[11],r[]=new int[2],d[]=new int[11],count[]=new int[11]; int casen,i,j,k,pn,top,discard,noanswer; casen=sc.nextInt(); for(k=1;k<=casen;k++) { pn=sc.nextInt(); for(i=0;i< pn;i++){count[i]=c[i][0]=0;p[i]=1;} c[0][0]=52;top=0;noanswer=0;r[0]=r[1]=0; for(i=1;i<=52;i++) c[0][i]=sc.nextInt(); while(top< pn&&c[top][0]!=0) … Continue reading

Posted in poj | Leave a comment

Poj Solution 2033

http://poj.org/problem?id=2033 //* @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); while(true) { String s=in.readLine(); if(s.equals("0")) break; int l=s.length(); int[] arr=new int[l]; int count=0; for(int i=0;i< l-1;i++) … Continue reading

Posted in poj | Leave a comment

Poj Solution 2031

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

Posted in poj | Leave a comment

Poj Solution 2029

http://poj.org/problem?id=2029 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { /** * @param args */ static int max(int a,int b) { if(a>b) return a; return b; } public static void main(String[] args) { // TODO Auto-generated method stub … Continue reading

Posted in poj | Leave a comment

Poj Solution 2028

http://poj.org/problem?id=2028 //* @author ������&lt;hongxp11@163.com&gt; import java.awt.Label; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (true) { int n = in.nextInt(); int q … Continue reading

Posted in poj | Leave a comment

Poj Solution 2027

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

Posted in poj | Leave a comment

Poj Solution 2019

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

Posted in poj | Leave a comment

Poj Solution 2018

http://poj.org/problem?id=2018 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { static int n,k; static final int N = 100000+100,que[] = new int[N]; static double DP[] = new double[N] , sum[] = new double[N]; public static int Get_Num(StreamTokenizer cin) … Continue reading

Posted in poj | Leave a comment

Poj Solution 2017

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

Posted in poj | Leave a comment

Poj Solution 2014

http://poj.org/problem?id=2014 //* @author: import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int max_width; while((max_width=cin.nextInt())!=0){ int final_width=0; int final_height=0; int remain=max_width; int cur_height=0; int r_width=cin.nextInt(); int r_height=cin.nextInt(); while(r_width!=-1){ if(r_width<=remain){ remain-=r_width; if(final_width< max_width-remain) … Continue reading

Posted in poj | Leave a comment

Poj Solution 2013

http://poj.org/problem?id=2013 //* @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; String[] s; int index=1; while (true){ n=scanner.nextInt(); if (n==0){ break; } System.out.println("SET "+index); index++; s=new String[n]; for … Continue reading

Posted in poj | Leave a comment

Poj Solution 2011

http://poj.org/problem?id=2011 #include <stdio.h> #include <math.h> #include <algorithm> using namespace std; int ans[20], an; int temp[20]; int get( int num, int s, int &r ) { int g = 0, tg=1, tr=1; bool key = true; r = 0; while( num … Continue reading

Posted in poj | Leave a comment

Poj Solution 2010

http://poj.org/problem?id=2010 #include<stdio.h> #include<vector> #include<queue> #include<algorithm> using namespace std; priority_queue< int ,vector<int> > q; typedef pair< int, int > cow; cow c[1000000]; int money[100000]; int n, m, f; int main() { int i, v; scanf( "%d %d %d", &n, &m, &f … Continue reading

Posted in poj | Leave a comment

Poj Solution 2008

http://poj.org/problem?id=2008 #include <stdio.h> #include <algorithm> #include <queue> using namespace std; pair<int,int> p[1000]; pair<int,int> q[1000]; bool cmp( const pair<int,int> &a, const pair<int,int> &b ) { return a.second < b.second; } int main( ) { int a, b, c, n, i, j, … Continue reading

Posted in poj | Leave a comment

Poj Solution 2007

http://poj.org/problem?id=2007 #include<stdio.h> #include<stdlib.h> #include<math.h> #define debug 0 #define INF 1000 #if debug #define NMAX 10 #else #define NMAX 52 #endif int point[NMAX][2]; int base[2]; int m[5]; int qu(int p[]) { if(p[0]>0&&p[1]>0) return 1; if(p[0]<0&&p[1]>0) return 2; if(p[0]<0&&p[1]<0) return 3; if(p[0]>0&&p[1]<0) … Continue reading

Posted in poj | Leave a comment

Poj Solution 2005

http://poj.org/problem?id=2005 //* @author: <strong> import java.util.*; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int tot[]=new int[12],t[]=new int[4]; char ts[]=new char[5]; int sum,s1,s2,win,tem; while (sc.hasNext()) { int n=sc.nextInt(); if(n==0) break; for (int i=2;i< 10;i++) … Continue reading

Posted in poj | Leave a comment

Poj Solution 2004

http://poj.org/problem?id=2004 //* @author: 82638882@163.com import java.io.*; import java.util.Arrays; import java.util.Comparator; public class Main { static my[] s=new my[10001]; public static void main(String[] args) throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); int l=0,max=-1,rr=-1; while(in.ready()) { String t=in.readLine(); s[l++]=new my(t); … Continue reading

Posted in poj | Leave a comment

Poj Solution 2002

http://poj.org/problem?id=2002 #include <stdio.h> #include <math.h> #include <string.h> #include <algorithm> using namespace std; #define DIFF 20000 #define MAX 1005 #define NUM 40005 #define EP 1e-8 #define LIM 1e-6 #define PI acos(-1.0) struct pt{ int x,y; }; pt p[MAX]; int s[NUM],e[NUM]; int … Continue reading

Posted in poj | Leave a comment

Poj Solution 2001

http://poj.org/problem?id=2001 import java.util.*; public class Main { static int MAX = 1010; static TrieNode root = new TrieNode(); static char[][] result = new char[MAX][22]; static char[][] s = new char[MAX][22]; public static void main(String[] args) { Scanner cin = new … Continue reading

Posted in poj | Leave a comment

Poj Solution 2000

http://poj.org/problem?id=2000 import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); while(true) { int day = Integer.valueOf(cin.nextLine()).intValue(); if(day == 0) break; System.out.println(day + " " + getTotalCoin(day)); } } private static int getTotalCoin(int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1995

http://poj.org/problem?id=1995 //* @author: import java.util.*; public class Main{ //��a^b%n private static int modexp(int a,int b,int n) { int ret=1; int tmp=a; while(b!=0) { if((b&0x1)==1) ret=ret*tmp%n; tmp=tmp*tmp%n; b>>=1; } return ret; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1990

http://poj.org/problem?id=1990 //* @author: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Comparator; import java.util.StringTokenizer; /* *�ο���ţ�ij���,��һ��д��״����… *�Ƚ�cows��volumeΪ�ؼ�������.. *}����״����,һ��ά�������,һ��ά��ǰ����С�ڵ�ǰ������֮�� */ class cin { static BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; static int leave=0; static int nextInt() throws IOException { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1989

http://poj.org/problem?id=1989 //* @author: ccQ.SuperSupper import java.util.*; import java.math.*; public class Main { public static void main(String []args) throws Exception{ int i,j,k,n,ans; int way[] = new int[100100]; int flag[] = new int[10100]; Scanner cin = new Scanner(System.in); n = cin.nextInt(); k … Continue reading

Posted in poj | Leave a comment

Poj Solution 1988

http://poj.org/problem?id=1988 /* @author: */ import java.util.Scanner; import java.util.Arrays; public class Main{ static int p[]=new int[30010]; static int d[]=new int[30010]; static int num[]=new int[30010]; static int i=0; static char c[]=new char[5]; static int getup(int a) { int b=a; while(p[b]!=b) b=p[b]; return … Continue reading

Posted in poj | Leave a comment

Poj Solution 1987

http://poj.org/problem?id=1987 #include"stdio.h" #include"algorithm" using namespace std; long use[16]; long father[40010]; long queue[40010]; long lchild[40010][16]; long rchild[40010][16]; long sum[40010][16]; long depth[40010][16]; long value[40010],dist[40010]; long m,n,k,kind,answer; long findit(long key,long s1,long deep) { long &lc=lchild[s1][deep],&rc=rchild[s1][deep],sumnow=sum[s1][deep]; long now=depth[s1][deep]; if(now==key) { if(rc>=0)return sumnow-sum[rc][deep+1]; else return … Continue reading

Posted in poj | Leave a comment

Poj Solution 1981

http://poj.org/problem?id=1981 #include<iostream> #include"math.h" #include"algorithm" using namespace std; struct point { double x,y; }p[310]; double jl(point i,point j) { return sqrt((i.x-j.x)*(i.x-j.x)+(i.y-j.y)*(i.y-j.y)); } bool fzk(point a,point b,double &in,double &out) { double jiao,l,x; if((l=jl(a,b))>2)return 0; jiao=atan2(b.y-a.y,b.x-a.x); x=acos(l/2); in=jiao-x; out=jiao+x; return 1; } int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1979

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

Posted in poj | Leave a comment