Author Archives: toad, die

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

Poj Solution 3088

http://poj.org/problem?id=3088 /* @author: */ import java.util.*; import java.io.*; import java.lang.reflect.Array; public class Main { static int a[][] = new int[12][12]; static long ans[] = new long[12]; static public void main( String [] str ) throws Exception{ int n; int m; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3087

http://poj.org/problem?id=3087 /* @author: */ import java.util.*; import java.io.*; import java.lang.reflect.Array; public class Main { static int a[] = new int[200]; static char start[], result[]; static public void main( String [] str ) throws Exception{ int n; int m; Scanner cin … Continue reading

Posted in poj | Leave a comment

Poj Solution 3086

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

Posted in poj | Leave a comment

Poj Solution 3085

http://poj.org/problem?id=3085 //* @author ������&lt;hongxp11@163.com&gt; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); for(int i = 0; i < n; i++) { int sum = in.nextInt(); int quarter … Continue reading

Posted in poj | Leave a comment

Poj Solution 3084

http://poj.org/problem?id=3084 /* @author: */ import java.util.*; class ff { static int min( int a, int b ) { return a< b?a:b; } class edge { int to; int c, f; int rev_i; edge( int pa, int pb, int pc ) … Continue reading

Posted in poj | Leave a comment

Poj Solution 3083

http://poj.org/problem?id=3083 /* @author: */ import java.util.*; public class Main { static String map[] = new String[50]; static int q[] = new int[2000]; static int n, m; static boolean inmap( int x, int y ) { return 0<=x&&x< n && 0<=y&&y< … Continue reading

Posted in poj | Leave a comment

Poj Solution 3082

http://poj.org/problem?id=3082 /* @author: */ import java.util.*; class point { int x,y; point(){x=y=0;} }; public class Main { static int cheng(point a,point b,point c) { return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y); } static int dcheng(point a,point b,point c) { return (b.x-a.x)*(c.x-a.x)+(c.y-a.y)*(b.y-a.y); } static int in(point … Continue reading

Posted in poj | Leave a comment

Poj Solution 3080

http://poj.org/problem?id=3080 import java.util.*; public class Main { static String w[] = new String[10]; public static void main(String args[]) { int t, n, i, j = 0, k; Scanner cin = new Scanner( System.in ); t = cin.nextInt(); String p = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3078

http://poj.org/problem?id=3078 import java.math.BigInteger; import java.util.*; public class Main { static String name[] = new String[20]; static int pos[] = new int[20]; public static void main(String args[]) { Scanner cin = new Scanner( System.in ); int t, n, m, a, b; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3077

http://poj.org/problem?id=3077 import java.math.BigInteger; import java.util.*; public class Main { public static void main(String args[]) { int n, s, i; Scanner cin = new Scanner( System.in ); n = cin.nextInt(); while( n– != 0 ) { s = cin.nextInt(); for( i=10; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3070

http://poj.org/problem?id=3070 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)); int[] f = new int[15000]; f[0] = 0; f[1] = 1; f[2] = 1; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3068

http://poj.org/problem?id=3068 #include <stdio.h> #include <memory.h> #include <math.h> #include <algorithm> using namespace std; #include <vector> using namespace std; typedef int type; //�������� const int size = 230; //ͼ�Ķ���ģ const type MAX_FEE = (1<<30); //�������� const int MAX = (1<<30); //������� const … Continue reading

Posted in poj | Leave a comment

Poj Solution 3067

http://poj.org/problem?id=3067 //* @author: 82638882@163.com import java.io.*; import java.util.Arrays; public class Main { static long ans=0; public static void main(String[] args) throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); int a=Integer.parseInt(in.readLine()); int cnt=0; while((a–)!=0) { ans=0; cnt++; String[] ss=in.readLine().split(" "); … Continue reading

Posted in poj | Leave a comment

Poj Solution 3066

http://poj.org/problem?id=3066 #include <stdio.h> #include <memory.h> #include <math.h> #include <algorithm> int main( ) { int m, p, a, b, k, i; double sum, q_a, a_p, ans, t; while( scanf( "%d%d%d%d", &m, &p, &a, &b ) == 4 ) { q_a = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3065

http://poj.org/problem?id=3065 #include <stdio.h> #include <memory.h> #include <math.h> #include <algorithm> using namespace std; int p[6000010]; int st[6000010]; void clear( int n ) { memset( p, -1, sizeof(int)*(n+1) ); } void input( int &m, int &sa, int &sb ) { char w[2]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3063

http://poj.org/problem?id=3063 #include <stdio.h> #include <stdlib.h> int m, n; int s0[5000], s1[5000]; int mem[2][10000], *a = mem[0], *b = mem[1]; int w0, w1, b0, b1, sum; #define mine( a, b ) ((a)<(b)?(a):(b)) void fill( ) { int i; int m0 = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3062

http://poj.org/problem?id=3062 import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); while(cin.hasNext()) { System.out.println(cin.nextLine()); } } }

Posted in poj | Leave a comment

Poj Solution 3061

http://poj.org/problem?id=3061 import java.util.Arrays; import java.util.Scanner; public class Main { // private static int ans[] =new int[100000]; private static int index = 0; public static void get(int[] seq, int s , int[]ans) { int sum = 0; int k = 0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3060

http://poj.org/problem?id=3060 #include <stdio.h> #include <memory.h> int m[1000][1000]; int sx[1000], sy[1000]; int main() { int t, n, i, j, d, a, b, best; scanf( "%d", &t ); while( t– ) { scanf( "%d%d", &d, &n ); best = 99999999; memset( m, … Continue reading

Posted in poj | Leave a comment

Poj Solution 3058

http://poj.org/problem?id=3058 #include <stdio.h> #include <algorithm> #include <memory.h> using namespace std; int w1[1000000]; int main() { int t, i, j, m; char c, temp; scanf( "%d", &t ); getchar(); while( t– ) { m = 0; while( 1 ){ c = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3055

http://poj.org/problem?id=3055 #include <stdio.h> int main() { int n, i, j, k; char mm[2][200], *w1 = &mm[0][0], *w2 = &mm[1][0], *t; int a[10], b[10], temp; bool key; scanf( "%d", &n ); while( n– ) { scanf( "%s %s", w1, w2 ); … Continue reading

Posted in poj | Leave a comment

Poj Solution 3051

http://poj.org/problem?id=3051 //* @author: 82638882@163.com import java.io.*; public class Main { static int[][] p; static int a,b,max=0,cnt; 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]); b=Integer.parseInt(ss[1]); p=new int[b+2][a+2]; for(int i=1;i<=b;i++) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 3050

http://poj.org/problem?id=3050 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashSet; import java.util.Set; public class Main { static Set<Integer> set; static int[][] a; public static void main(String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader( System.in)); a = new int[5][5]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 3049

http://poj.org/problem?id=3049 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { static final int N = 20; static int n,l; static String ans; static char word[] = new char[N]; static char ansp[] = new char[N]; public static void main(String … Continue reading

Posted in poj | Leave a comment

Poj Solution 3048

http://poj.org/problem?id=3048 import java.util.Scanner; import java.util.Arrays; public class Main{ public static void main(String args[]) { Scanner sc=new Scanner(System.in); int n,mx=-1,tag=-1,i,v; n=sc.nextInt(); while((n–)!=0) { v=sc.nextInt(); int u=v; int maxx=1; if(v%2==0) { maxx=2; while(v%2==0)v/=2; } for(i=3;i*i<=v;i+=2) { if(v%i==0) { maxx=i; while(v%i==0)v/=i; } } … Continue reading

Posted in poj | Leave a comment

Poj Solution 3047

http://poj.org/problem?id=3047 //* @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 a[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; String s[]={"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"}; int n,y,m,d,t; y=sc.nextInt(); m=sc.nextInt(); d=sc.nextInt(); t=(y-1)*365; for (int i=1;i< y;i++) if ((i%4==0&&i%100!=0)||(i%400==0)) … Continue reading

Posted in poj | Leave a comment

Poj Solution 3046

http://poj.org/problem?id=3046 #include <stdio.h> #include <memory.h> int c[1001]; int ans[1001][10000]; int main() { int i, j, k, sum, n, a, t, left, right; scanf( "%d%d%d%d", &n, &a, &left, &right ); if( a > 10000 ) while( printf( "asdf" ) ); for( … Continue reading

Posted in poj | Leave a comment

Poj Solution 3045

http://poj.org/problem?id=3045 #include <stdio.h> #include <algorithm> using namespace std; struct cow { int sum, w, s; }c[50000]; int n; bool cmp( cow a, cow b ) { return a.sum < b.sum; }; bool check( int k ) { int sum = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3044

http://poj.org/problem?id=3044 #include <stdio.h> #include <algorithm> using namespace std; int id[50000]; int h[50000]; bool sign[50000]; int temp[2][51000]; int *next = &temp[0][1]; int *pri = &temp[1][1]; bool cmp( int a, int b ) { return h[a] > h[b]; } int main() { … Continue reading

Posted in poj | Leave a comment

Poj Solution 3043

http://poj.org/problem?id=3043 #include <stdio.h> #define max(a,b) ((a)>(b)?(a):(b)) int clac( char *w, int len, char map[32][32], int n, int m ) { int s[5][1000], sn[5] = {0}; int ans[5][1000] = { 0 }, i, j, k, ii, l, sum = 0; for( … Continue reading

Posted in poj | Leave a comment

Poj Solution 3042

http://poj.org/problem?id=3042 #include <stdio.h> #include <algorithm> #include <memory.h> using namespace std; int x[1001]; __int64 ans[1001][1001][2]; int main() { int i, j, n, k; scanf( "%d%d", &n, &k ); for( i=0; i<n; i++ ) { scanf( "%d", &x[i] ); } x[n] = … Continue reading

Posted in poj | Leave a comment

Poj Solution 3041

http://poj.org/problem?id=3041 //* @author: 82638882@163.com import java.util.Scanner; public class Main { static int a,b; static int[][] map; static int[] used; static int[] match; public static void main(String[] args) { Scanner in=new Scanner(System.in); a=in.nextInt(); b=in.nextInt(); map=new int[a+1][a+1]; for(int i=0;i< b;i++) map[in.nextInt()][in.nextInt()]=1; match=new … Continue reading

Posted in poj | Leave a comment