Author Archives: toad, die

Poj Solution 1095

http://poj.org/problem?id=1095 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { static final int N = 20+10; static int sum[] = new int[N],catana[] = new int[N]; static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); public static void main(String[]args) throws Exception{ … Continue reading

Posted in poj | Leave a comment

Poj Solution 1093

http://poj.org/problem?id=1093 #include<iostream> using namespace std; const char space=’ ‘; char word[10001],l; int len[10002],m,n; int jie[10002]; int chen[10002]; long bad[10002]; void init() {int h=0,j=1,t=0; while(cin.get()) {if(cin.peek()==10)break; while(cin.peek()!=10) {if(cin.peek()==32){cin.get();if(t){len[j++]=t;t=0;}} else {cin.get(word[h++]); t++;} } if(t){len[j++]=t;t=0;} } len[0]=0; m=j-1; l=h; //for(i=0;i<l;i++)cout<<word[i]; //cout<<endl; //for(i=1;i<=m;i++)cout<<len[i]<<endl; } … Continue reading

Posted in poj | Leave a comment

Poj Solution 1091

http://poj.org/problem?id=1091 //* @author popop0p0popo import java.util.*; import java.math.*; public class Main{ public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); int m=scanner.nextInt(); int[] yue=getYue(m); for (int i=0;i< yue.length ;i++ ){ if (yue[i]==0){ break; } m=m/yue[i]; } BigInteger ok=(new BigInteger(""+m)).pow(n); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1090

http://poj.org/problem?id=1090 /* @author: */ import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner stdin=new Scanner(System.in); int n=stdin.nextInt(); int[] a=new int[n],b=new int[n]; for(int i=0;i< n;i++)a[i]=stdin.nextInt(); b[0]=a[n-1]; for(int i=1;i< n;i++){ b[i]=b[i-1]^a[n-1-i]; } BigInteger ans=new BigInteger("0"),two=new BigInteger("2"); for(int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1089

http://poj.org/problem?id=1089 //* @author: SmilingWang import java.util.*; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); int n; n = in.nextInt(); Interval intervals[] = new Interval[n]; for(int i = 0; i < n; i++){ int x = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1087

http://poj.org/problem?id=1087 #include<iostream> #include"string.h" using namespace std; #define null 0 const int size=1000; bool w[size][size]; void maxmatch(int n,int m,int *p) { int p_n[size]; int p_m[size]; bool sign[size]; int q[size],from[size],s,t; int i,j,link,now,h; for(i=0;i<n;i++)p_n[i]=-1; for(j=0;j<m;j++)p_m[j]=-1; for(i=0;i<n;i++) if(p_n[i]==-1) { for(j=0;j<m;j++)sign[j]=0; s=0; for(j=0;j<m;j++) if(w[i][j]!=null) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1083

http://poj.org/problem?id=1083 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader read = new BufferedReader(new InputStreamReader( System.in)); int t = Integer.parseInt(read.readLine()); int s; int[][] m; String[] str; int[] … Continue reading

Posted in poj | Leave a comment

Poj Solution 1082

http://poj.org/problem?id=1082 //* @author: 82638882@163.com import java.util.*; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); int a=in.nextInt(); while((a–)!=0) { in.nextInt(); boolean bb=false; int m=in.nextInt(); int d=in.nextInt(); if((m+d)%2==0)bb=true; else if(m==9&&d==30)bb=true; else if(m==11&&d==30)bb=true; if(bb)System.out.println("YES"); else System.out.println("NO"); } } … Continue reading

Posted in poj | Leave a comment

Poj Solution 1080

http://poj.org/problem?id=1080 //* @author popop0p0popo import java.util.*; import java.io.*; public class Main{ public static int[][] chart; public static void main(String[] args){ init(); Scanner in=new Scanner(new BufferedReader(new InputStreamReader(System.in))); int p=in.nextInt(); for (int k=0;k< p ;k++ ){ int m=in.nextInt(); String a=in.next(); int n=in.nextInt(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1079

http://poj.org/problem?id=1079 import java.io.*; public class Main { public static int gcd(int a,int b){ while(a%b!=0){ int temp=a; a=b; b=temp%b; } return b; } public static void main(String[] args) throws IOException{ StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); while(in.nextToken()!=StreamTokenizer.TT_EOF){ int a,b; double last=100000; a=(int)in.nval; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1078

http://poj.org/problem?id=1078 #include<iostream> using namespace std; int t[100],n; int go(int i,long s,long a,long b) {if(s==1)return 1; if(i==n)return 0; if(a%t[i]==0)if(go(i+1,s/t[i],a/t[i],b))return 1; if(b%t[i]==0)if(go(i+1,s/t[i],a,b/t[i]))return 1; if(go(i+1,s,a,b))return 1; return 0; } int main() {int i;long a,b,s; while(1) {cin>>a;if(cin.fail())break; cin>>b; if(a<b){a=a+b;b=a-b;a=a-b;} s=a*b;n=0; for(i=100;i>1;i–) if(s%i==0&&(a%i==0||b%i==0))t[n++]=i; if(!go(0,b,b,1)){cout<<a<<endl;continue;} if(!go(0,a,a,1)){cout<<b<<endl;continue;} … Continue reading

Posted in poj | Leave a comment

Poj Solution 1077

http://poj.org/problem?id=1077 //* @author: 82638882@163.com import java.util.*; public class Main { static int[][] arr; static boolean[] bb=new boolean[10000000]; static Queue< my> qu=new LinkedList< my>(); public static void main(String[] args) { Scanner in=new Scanner(System.in); arr=new int[5][5]; String s; for(int i=1;i< 4;i++) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1072

http://poj.org/problem?id=1072 #include <stdio.h> #include <string.h> #include <algorithm> //#define DEBUG //#define PRINT_TREE #ifdef DEBUG #include <time.h> #endif using namespace std; const char NONE = 30; const char WORD = 50; struct node { node(){ p=0; m=”; for(int i=0;i<27;i++)id[i]=NONE; } char id[27]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1068

http://poj.org/problem?id=1068 import java.util.Scanner; public class Main { int t; int len; int[] p; int[] w; String[] s; int index; int temp; int pos; public Main() { Scanner scan = new Scanner(System.in); t = scan.nextInt(); for (int i = 0; i … Continue reading

Posted in poj | Leave a comment

Poj Solution 1067

http://poj.org/problem?id=1067 #include <iostream> #include <algorithm> #include <cmath> #include <stdio.h> using namespace std; int main() { int ax,bx,temp; int k,wantedax; while(scanf("%d%d",&ax,&bx)!=EOF) /*题中没有输入结标志时,必须这样写,否则会WA*/ { if(ax>bx) swap(ax,bx); k = bx – ax; wantedax = (floor)( k*(1.0+sqrt(5.0))/2.0 ); if(ax==wantedax) printf("%dn",0); else printf("%dn",1); } return … Continue reading

Posted in poj | Leave a comment

Poj Solution 1066

http://poj.org/problem?id=1066 #include <iostream> #include <cstdio> #include <algorithm> #define MAX 35 int N; using namespace std; typedef struct Point { double x,y; Point() {} Point(double tx,double ty):x(tx),y(ty) {} }Vector; int WallY0[MAX]; //��ַ����ݸ��� int WallY100[MAX]; int WallX0[MAX]; int WallX100[MAX]; struct Line { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1065

http://poj.org/problem?id=1065 import java.util.*; public class Main{ public static void main(String[] args){ int l[]=new int[10000]; int w[]=new int[10000]; int tt[]=new int[5000]; int k=0; Scanner keyin=new Scanner(System.in); int m=keyin.nextInt(); int mm=m; int n=0; for(;m>0;m–){ n=keyin.nextInt(); for(int j=0;j< n;j++){ l[j]=keyin.nextInt(); w[j]=keyin.nextInt(); } int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1064

http://poj.org/problem?id=1064 #include <iostream> #include <cstdio> using namespace std; int N,K; long long len[10001]; int main() { while(cin>>N>>K) { double t; long long sum = 0; for(int i = 0;i < N;i++) { cin>>t; t *= 100; len[i] = (long long)t; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1063

http://poj.org/problem?id=1063 //* @author: import java.util.Scanner; public class Main{ public static void main(String args[]) { int cas, i, n, j, s1, s2; int a[]=new int[30]; Scanner sc=new Scanner(System.in); cas=sc.nextInt(); while((cas–)!=0 ) { n=sc.nextInt(); for( i=0; i< n; i++ ) { a[i]=sc.nextInt(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1062

http://poj.org/problem?id=1062 //���ձ��˵�˼���õ�,֮ǰ���Ǻ��˽�dijkstra������������Щ��� //1,����ǰδ�������·�ķ��Ҫ��ľ�����̽���������·; //2,�������뵱ǰ����Ľ���й�j����δ���������·�Ľ����̾�����и��¡� //ͼ������һ������С�����ĵľ����㷨Prim�㷨��Dij��̼������ƣ�����̰��˼�롣 //ֻ��һ���ǶԶ����ѡ������һ���ǶԱߵ�ѡ�� import java.util.*; public class Main { public static int[][] e; public static int[] dis; public static int[] used; public static int[] level; public static int n,m; public static void main(String[] args){ Scanner cin = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1061

http://poj.org/problem?id=1061 import java.util.Scanner; public class Main { static long x0, y0; public static void main(String[] args) { Scanner scan = new Scanner(System.in); long x = scan.nextInt(); long y = scan.nextInt(); long m = scan.nextInt(); long n = scan.nextInt(); long L … Continue reading

Posted in poj | Leave a comment

Poj Solution 1058

http://poj.org/problem?id=1058 //* @author: import java.util.*; public class Main{ String result[][]; char c[]={‘A’,’B’,’C’,’D’,’E’,’F’,’G’,’H’,’I’,’J’,’K’,’L’,’M’,’N’,’O’,’P’}; boolean used[]; public Main(String result[][]){ this.result=result; } public static void main(String args[]){ Scanner sc=new Scanner(System.in); while(true){ String result[][]=new String[5][4]; for(int i=0;i< 5;i++) for(int j=0;j< 4;j++){ if(i>=3) result[i][j]=""; else … Continue reading

Posted in poj | Leave a comment

Poj Solution 1057

http://poj.org/problem?id=1057 /* @author:����acmilan_fan@yahoo.cn */ import java.io.*; public class Main { public static void main(String[] args) throws Exception{ //System.setIn(new FileInputStream(new File("E:\in.txt"))); //System.setOut(new PrintStream(new File("E:\out.txt"))); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s; Node root=new Node("ROOT",null); Node curr=root; Node t,n; int count=1; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1056

http://poj.org/problem?id=1056 //* @author 洪晓鹏&lt;hongxp11@163.com&gt; import java.util.ArrayList; import java.util.Scanner; public class Main { /** * @param args */ public static boolean isPrefix(String a, String b) { int len = a.length() > b.length() ? b.length() : a.length(); if (a.substring(0, len).equals(b.substring(0, len))) return … Continue reading

Posted in poj | Leave a comment

Poj Solution 1054

http://poj.org/problem?id=1054 import java.util.Arrays; import java.util.Scanner; public class Main { class Point implements Comparable { int row; int col; public Point(int x, int y) { this.row = x; this.col = y; } public int compareTo(Object o) { int result = 0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1051

http://poj.org/problem?id=1051 //* @author import java.io.*; import java.util.*; public class Main { static HashMap< String,String> codeMap = new HashMap< String,String>(); static HashMap< String,String> ref = new HashMap< String,String>(); public static void main(String[] args) throws Exception { initMap(); readFile(); } static void … Continue reading

Posted in poj | Leave a comment

Poj Solution 1050

http://poj.org/problem?id=1050 import java.util.Scanner; public class Main { int[][] a; int l; int max = Integer.MIN_VALUE; int t; int t1; int t2[]; public Main() { Scanner scan = new Scanner(System.in); l = scan.nextInt(); a = new int[l][l]; for (int i = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1047

http://poj.org/problem?id=1047 import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); BigInteger b,c,d; String str,str1,str2,str3; int i,len; while(cin.hasNext()) { str = cin.next(); b = new BigInteger(str); len=str.length()+1; char []kids = new … Continue reading

Posted in poj | Leave a comment

Poj Solution 1046

http://poj.org/problem?id=1046 #include <stdio.h> struct Color{ int R,G,B; }map[16]; int main() { int i; for ( i = 0; i < 16; ++i) scanf("%d%d%d",&map[i].R,&map[i].G,&map[i].B); struct Color c; while(scanf("%d%d%d",&c.R,&c.G,&c.B)&&c.R>=0){ int index=0,min=65535; for ( i = 0; i < 16; ++i) { int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1045

http://poj.org/problem?id=1045 import java.util.Scanner; public class Main { static double vs = 0; static double c = 0; static double r = 0; static double w = 0; static int times = 0; public static void main(String[] args) { Scanner scan … Continue reading

Posted in poj | Leave a comment

Poj Solution 1043

http://poj.org/problem?id=1043 #include<iostream> #include<string> #include<cmath> #include<algorithm> using namespace std; struct criminal { char name[21]; int id; }crim[20]; int cmp(void const * a,void const * b) //按姓名升序排序 { return strcmp(((criminal *)a)->name,((criminal *)b)->name); } int Bipartite(bool decryp[][20],int n,int count) //二分图的匈牙利算法,decryp是原始数组,n是用户ID的个数,count是罪犯的个数(列数) { int i,j,x,qs,qe,q[20],prev[20],ncount=0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1042

http://poj.org/problem?id=1042 import java.io.BufferedInputStream; import java.util.Arrays; import java.util.Scanner; 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 == 0) { break; } int h = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1039

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

Posted in poj | Leave a comment

Poj Solution 1038

http://poj.org/problem?id=1038 //* @author import java.util.*; public class Main { static Scanner in = new Scanner(System.in); static int[] p = new int[12]; static { p[0] = 1; for(int i=1; i!=p.length; ++i) p[i] = 3*p[i-1]; } static int get(int s, int i) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1037

http://poj.org/problem?id=1037 //* @author: import java.util.*; public class Main{ static final int MAX=21;//���20��ľ�� static long w[][];//w�����еĸ��� static long m[][];//m�����еĸ���m[x][n]Ϊ��n��Ȳ�ͬ��ľ����ɵ�դ8�У������е�x��ľ��ʼ�ġ�M�������еĸ��� private int n;//ľ��ĸ��� private long c;//��� private boolean flag[]; private boolean print; static {//��ʼ����̬�� w=new long[MAX][MAX]; m=new long[MAX][MAX]; w[1][1] = 1; m[1][1] … Continue reading

Posted in poj | Leave a comment

Poj Solution 1035

http://poj.org/problem?id=1035 //* @author import java.io.*; import java.util.*; public class Main { static ArrayList< Item> dicts = new ArrayList< Item>(); public static void main(String[] args) throws Exception { readFile(); } static void readFile() throws Exception { BufferedReader br = new BufferedReader( … Continue reading

Posted in poj | Leave a comment

Poj Solution 1032

http://poj.org/problem?id=1032 //* @author: 82638882@163.com import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); int[] u=new int[]{ 1,2,5,9,14,20,27,35,44,54,65,77,90,104,119,135,152,170,189,209,230,252,275,299,324, 350,377,405,434,464,495,527,560,594,629,665,702,740,779,819,860,902,945,989,1034,1111 }; int a=in.nextInt(); int b=0; int k=22; int m=0; int h=45; while(!(a< u[k+1]&&a>=u[k])) { if(a>=u[k+1]) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1028

http://poj.org/problem?id=1028 import java.util.Scanner; import java.util.Stack; public class Main { String command; Stack<String> back = new Stack<String>(); Stack<String> forward = new Stack<String>(); String current = "http://www.acm.org/"; String display; public Main() { Scanner scan = new Scanner(System.in); while (!(command = scan.next()).equals("QUIT")) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1026

http://poj.org/problem?id=1026 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader read = new BufferedReader(new InputStreamReader( System.in)); int len; int[] n; int[] loop; String[] s; int times; int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1025

http://poj.org/problem?id=1025 #include <iostream> class Room { public: int fNo , rNo; // rNo表示房间号,fNo表楼层号,其中fNo-2表楼外。rNo=-1表示电梯 char * toString() { // 此函数线程不安全,不过用在此题没问题。千万不能在printf()这类函数内两次调用此函数。 static char str_room[5]; sprintf(str_room,"%02d%02d",fNo,rNo); return str_room; } Room& operator = ( const Room& room ) { fNo=room.fNo; rNo=room.rNo; return *this; } … Continue reading

Posted in poj | Leave a comment

Poj Solution 1024

http://poj.org/problem?id=1024 #include <stdio.h> #include <string.h> struct pos { int len[2]; int used; int r; int u; }p[20][20]; int num, wallNum, w, h, Dx, Dy, minPath; void DFS(int x, int y, int len, int flag) { if (len >= p[x][y].len[flag] && … Continue reading

Posted in poj | Leave a comment

Poj Solution 1023

http://poj.org/problem?id=1023 /* @author: */ import java.util.Scanner; public class Main{ public static void main(String args[]){ long n; int k,t; int ans[]=new int[65]; char a[]=new char[66]; Scanner sc=new Scanner(System.in); t=sc.nextInt(); while((t–)!=0){ k=sc.nextInt(); a=sc.next().toCharArray(); n=sc.nextLong(); for(int i=0;i< k;i++){ if((n&0x1)!=0){ ans[k-1-i]=1; if(a[k-i-1]==’p’) n=n-1; else … Continue reading

Posted in poj | Leave a comment

Poj Solution 1022

http://poj.org/problem?id=1022 #include<iostream> #include"math.h" using namespace std; int id[100];int edge[100][100],set[100]; int next[100][8],n,ok; int find(int d) {int i; for(i=0;i<n;i++) if(id[i]==d)return i; return -1; } int zb[4][2]; ///////////////////////// void search(int i,int axes[4]) {int ax[4],k; set[i]=1;ok++; for(k=0;k<4;k++) {if(axes[k]<zb[k][0])zb[k][0]=axes[k]; else if(axes[k]>zb[k][1])zb[k][1]=axes[k]; } int j; for(j=0;j<n;j++) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1021

http://poj.org/problem?id=1021 /* @author: */ import java.util.Scanner; import java.util.Arrays; public class Main{ static int n_limit=100*100; static int width; static int height; static boolean in_map(int x,int y){ if (0<=x&&x< width&&0<=y&&y< height) return true; else return false; } static int calculate(int x,int y,int[][] … Continue reading

Posted in poj | Leave a comment

Poj Solution 1020

http://poj.org/problem?id=1020 /* @author: */ import java.util.Scanner; import java.util.Arrays; public class Main{ static int c[]=new int[11];//c[i]��ű߳�Ϊi��С���εĸ��� static int d[]=new int[41];//d[i]��ʾ��i������С���κ��������� static int s,n,sum; static boolean ok; public static void main(String args[]) { int t,it,i,tp; Scanner sc=new Scanner(System.in); t=sc.nextInt();//���Դ�¦ for(it=1;it<=t;it++)//ѭ������ÿһ�β��� { s=sc.nextInt();//�����ӡ������εı߳� … Continue reading

Posted in poj | Leave a comment

Poj Solution 1019

http://poj.org/problem?id=1019 #include <iostream> #include <cmath> using namespace std; unsigned int a[31270], s[31270]; /* 打表 */ void reset() { int i; a[1] = 1; s[1] = 1; for(i = 2; i < 31270; i++) { /* 每一组数字都比上一组长 (int)log10((double)i) + 1 */ … Continue reading

Posted in poj | Leave a comment

Poj Solution 1018

http://poj.org/problem?id=1018 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { double bp = 0; public Main() throws NumberFormatException, IOException { BufferedReader read = new BufferedReader(new InputStreamReader( System.in)); int t = Integer.parseInt(read.readLine()); int num; int[][] b; int[][] p; int[] n; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1017

http://poj.org/problem?id=1017 import java.util.Scanner; public class Main { int a; int b; int c; int d; int e; int f; int packets; int t; public Main() { Scanner scan = new Scanner(System.in); a = scan.nextInt(); b = scan.nextInt(); c = scan.nextInt(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1015

http://poj.org/problem?id=1015 //* @author: 82638882@163.com import java.util.Scanner; public class Main{ static short[] p,d; static short[][][] arr,path; static int add,a,b,st,ed; public static void main(String[] args) { Scanner in=new Scanner(System.in); int cnt=0; while(true) { cnt++; a=in.nextInt(); b=in.nextInt(); if(a==0&&b==0)break; System.out.println("Jury #"+cnt); p=new short[a+1]; d=new … Continue reading

Posted in poj | Leave a comment

Poj Solution 1014

http://poj.org/problem?id=1014 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; int[] marbles; int sum; int part; int times = 0; while (true) … Continue reading

Posted in poj | Leave a comment