Category Archives: poj

Poj Solution 1406

http://poj.org/problem?id=1406 import java.util.*; /** * * @author leo */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int total, left; while (true) { total … Continue reading

Posted in poj | Leave a comment

Poj Solution 1405

http://poj.org/problem?id=1405 import java.io.BufferedInputStream; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(new BufferedInputStream(System.in)); if (scan.hasNext()) { int n = scan.nextInt(); ArrayList<BigDecimal> results = new ArrayList(18); results.add(0, new BigDecimal(2)); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1404

http://poj.org/problem?id=1404 //* @author: import java.util.*; public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); int K,L; char key[]=new char[100]; char letter[]=new char[100]; int F[]=new int[100]; int p[]=new int[100]; int best; int map[][][]=new int[100][100][100]; int father[][]=new … Continue reading

Posted in poj | Leave a comment

Poj Solution 1401

http://poj.org/problem?id=1401 #include <iostream> using namespace std; int calc(int z) { int i, count = 0; for (i = 5; i <= z; i *= 5) { count += z / i; } return count; } int main() { int n, … Continue reading

Posted in poj | Leave a comment

Poj Solution 1389

http://poj.org/problem?id=1389 #include<iostream> #include"memory.h" #include"algorithm" using std::sort; using namespace std; int x[2010],y[2010]; int n,index_y[2010],index_x[2010],to_y[2010]; int tree[2048*2],cover[2048*2]; int cmp_x(int a,int b) {return x[a]<x[b];} int cmp_y(int a,int b) {return y[a]<y[b];} int init() {int i; for(i=0;;i++) {cin>>x[2*i]>>y[2*i]>>x[2*i+1]>>y[2*i+1]; if(x[2*i]==-1)break; index_x[2*i]=2*i;index_x[2*i+1]=2*i+1; index_y[2*i]=2*i;index_y[2*i+1]=2*i+1; } n=i; if(n==0)return 0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1386

http://poj.org/problem?id=1386 //* @author: 82638882@163.com import java.io.*; public class Main { static int[] arr=new int[26]; static int[] cin=new int[26]; static int[] cout=new int[26]; static boolean[] used=new boolean[26]; public static void main(String[] args) throws NumberFormatException, IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new … Continue reading

Posted in poj | Leave a comment

Poj Solution 1385

http://poj.org/problem?id=1385 #include<iostream> #include"stdio.h" #include"memory.h" using namespace std; double x,y,x1,y1,xb,yb; double area,x_sum,y_sum,temp; int main() { int t,n,i; cin>>t; while(t–) { cin>>n; cin>>x1>>y1; xb=x1,yb=y1; area=x_sum=y_sum=0; for(i=1;i<=n;i++) { if(i<n)cin>>x>>y; else x=xb,y=yb; temp=x*y1-y*x1; x_sum+=temp*(x+x1); y_sum+=temp*(y+y1); area+=temp; x1=x,y1=y; } printf("%.2lf %.2lfn",(double)((long)(x_sum/area/3*100))/100,(double)(long)(y_sum/area/3*100)/100); } return 0; }

Posted in poj | Leave a comment

Poj Solution 1384

http://poj.org/problem?id=1384 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; class Coin{ int price,weight; } public class Main { static final int N = 500+10,M = 10000+10; static int DP[] = new int[M],n,m; static Coin coin[] =new Coin[N]; static void start(){ for(int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1383

http://poj.org/problem?id=1383 #include"stdio.h" #include"memory.h" char map[1100][1100]; bool sign[1100][1100]; int max,bx,by,n,m; void init_sign() { int i,j; for(i=0;i<n;i++) for(j=0;j<m;j++) sign[i][j]=0; } void init() { scanf("%d %d",&m,&n); for(int i=0;i<n;i++) scanf("%s",map[i]); } inline int inmap(int x,int y) { return x>=0&&y>=0&&x<n&&y<m; } const int dx[]={0,0,1,-1},dy[]={1,-1,0,0}; void … Continue reading

Posted in poj | Leave a comment

Poj Solution 1371

http://poj.org/problem?id=1371 #include <iostream> #include <algorithm> #include <memory.h> using namespace std; int x[200], y[200], xn, yn, n, m; struct { int x1, x2, y1, y2; }ln[100]; char map[414][414]; bool init() { int i, j, l, r, u, d, k; cin >> … Continue reading

Posted in poj | Leave a comment

Poj Solution 1368

http://poj.org/problem?id=1368 #include<iostream> #include"memory.h" using namespace std; int set[3][3][3][3]; int map[7][7][4]; int n,m; int div(char c) {switch(c) {case ‘O’:return 0; case ‘F’:return 1; case ‘I’:return 2; default:return -1; } } void init() {int i,j,a[4];char c; memset(set,0,81*sizeof(int)); for(i=0;i<n*m;i++) {for(j=0;j<4;j++) {cin>>c;a[j]=div(c);} set[a[0]][a[1]][a[2]][a[3]]++; } … Continue reading

Posted in poj | Leave a comment

Poj Solution 1366

http://poj.org/problem?id=1366 //* @author: <strong>Yeming&nbsp;Hu</strong>&quot;cslittleye@gmail.com&quot; import java.util.*; import java.io.*; public class Main { public static BufferedInputStream bis; public static StringBuilder str; public static char[][] rules; public static StringBuilder[] words; public static int k; public static void main(String[] args) throws Exception { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1365

http://poj.org/problem?id=1365 import java.util.*; import java.math.*; public class Main { /** * @param args */ static int pp; static int[] p = new int[30000]; static int[] w = new int[30000]; static boolean[] q = new boolean[35000]; static void init() { int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1363

http://poj.org/problem?id=1363 import java.util.*; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int in[]=new int[1001]; int out[]=new int[1001]; int stack[]=new int[1001]; int n; int i,j; for(i=0;i< 1001;i++) in[i]=i+1; while(sc.hasNext()) { n=sc.nextInt(); if(n==0) break; while(true) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1362

http://poj.org/problem?id=1362 //* @author: <strong>Yeming&nbsp;Hu</strong>&quot;cslittleye@gmail.com&quot; import java.util.*; public class Main { public static final int max = 30; public static void main(String[] args) { int[] weights = new int[max]; int p = 2; for(int i = 0; i < max; i++) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1354

http://poj.org/problem?id=1354 import java.io.BufferedInputStream; import java.math.BigDecimal; 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 == -1) { break; } BigDecimal nn = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1353

http://poj.org/problem?id=1353 //* @author: import java.util.*; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int a[]=new int[200],b[]=new int[200]; int n,m,k; while(sc.hasNext()) { String s=sc.nextLine(); Scanner scan=new Scanner(s); scan.useDelimiter(","); n=scan.nextInt(); if(n==-1) break; m=scan.nextInt(); k=scan.nextInt(); for (int i=1;i<=n;i++) { if … Continue reading

Posted in poj | Leave a comment

Poj Solution 1351

http://poj.org/problem?id=1351 /* @author:zeropinzuo */ import java.io.*; import java.util.*; public class Main{ static Scanner cin; static long[] f,g; public static void main(String args[]){ cin = new Scanner(System.in); f = new long[17]; g = new long[17]; g[1]=4; g[2]=14; for(int i=3;i< 17;i++) g[i]=3*g[i-1]+2*g[i-2]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1350

http://poj.org/problem?id=1350 //* @author: <strong>Yeming&nbsp;Hu</strong>&quot;cslittleye@gmail.com&quot; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(true) { String num = sc.next(); if(num.equals("-1")) { break; } System.out.println("N="+num+":"); if(num.length()!=4||(num.charAt(0)==num.charAt(1)&& num.charAt(1)==num.charAt(2)&& num.charAt(2)==num.charAt(3))) { System.out.println("No!!"); }else { int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1344

http://poj.org/problem?id=1344 //* @author: import java.util.*; public class Main { static int value[][]=new int[50][50]; static int ans,n; static void calc() { int i, j, temp, k, s; for( k=0; k< n-2; k++ ) { s = 10000000; for( i = k+1; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1338

http://poj.org/problem?id=1338 //* @author mekarlos@gmail.com import java.util.Scanner; import java.util.Vector; public class Main { public static void main(String[] args) { Scanner scan=new Scanner(System.in); Vector< Long> v=new Vector< Long>(); v.add(new Long(1)); int i=0,j=0,k=0; while(v.size()< 1500){ v.add(Math.min(Math.min(v.get(i)*2, v.get(j)*3), v.get(k)*5)); if(v.get(v.size()-1).equals(v.get(v.size()-2))){v.remove(v.size()-1);} if(v.get(i)*2==v.get(v.size()-1))i++; else if(v.get(j)*3==v.get(v.size()-1))j++; else … Continue reading

Posted in poj | Leave a comment

Poj Solution 1337

http://poj.org/problem?id=1337 //* @author: import java.util.*; public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); int ans[]=new int[300]; int a[]=new int[100],d[]=new int[100],t[]=new int[100]; int cas, i, j, n, temp; boolean key; cas=in.nextInt(); while(( cas– )!=0) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1331

http://poj.org/problem?id=1331 //* @author: 82638882@163.com import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); int a=in.nextInt(); while((a–)!=0) { String s1=in.next(); String s2=in.next(); String s3=in.next(); int max=0; for(int i=0;i< s1.length();i++) { char c=s1.charAt(i); int u=c-48; if(max< … Continue reading

Posted in poj | Leave a comment

Poj Solution 1330

http://poj.org/problem?id=1330 import java.util.*; @SuppressWarnings("unchecked") public class Main { int MAX = 10001; Vector< Integer> tree[] = new Vector[MAX + 1];; // 树结构 byte[] flag = new byte[MAX]; // 入度标志,用于寻找根节点 int parent[] = new int[MAX];; int rank[] = new int[MAX];; int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1328

http://poj.org/problem?id=1328 import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; /** * * @author 小e * * 2010-6-12 下午01:48:35 */ public class Main { static class Range implements Comparable<Range>{ double left,right; public Range(double left,double right){ this.left = left; this.right = right; } @Override … Continue reading

Posted in poj | Leave a comment

Poj Solution 1326

http://poj.org/problem?id=1326 import java.util.*; import java.text.*; class FRecord { String from; String to; int miles; String type; public FRecord(String a, String b, int c, String d) { this.from = a; this.to = b; this.miles = c; this.type = d; } } … Continue reading

Posted in poj | Leave a comment

Poj Solution 1325

http://poj.org/problem?id=1325 #include <iostream> #include<cstdio> #include<cstring> using namespace std; #define size 101 int g[size][size]; //ƥ��ͼ int visited[size]; //x�����ʱ�־ int m,n; //n:x������Ŀ��m:y����Ŀ int My[size], Mx[size]; //ƥ���� int Q[size], prev[size]; int BFS_MaxMatch(void) { int res = 0, i, u, v; int head, tail; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1323

http://poj.org/problem?id=1323 #include<iostream> #include<algorithm> using namespace std; const int mMax = 22; const int nMax = 52; struct data{ int num; bool my; bool small; }card[mMax * nMax]; int main(){ int m , n, i, j, t = 1; while(cin >> … Continue reading

Posted in poj | Leave a comment

Poj Solution 1321

http://poj.org/problem?id=1321 #include <iostream> using namespace std; int map[10][10]; int vis[10]; int n,k,ans; void dfs(int col,int cnt) { int i; if(cnt==k) { ans++ ; return ; } if(n-col<k-cnt-1) return ; for(i=1;i<=n;i++) { if(!vis[i]&&map[col][i]) { vis[i]=1; dfs(col+1,cnt+1); vis[i]=0; } } dfs(col+1,cnt); } … Continue reading

Posted in poj | Leave a comment

Poj Solution 1320

http://poj.org/problem?id=1320 /* @author:zeropinzuo */ import java.io.*; import java.util.*; public class Main{ public static void main(String args[]){ int[] array = new int[10]; array[0]=6; array[1]=35; for(int i=2;i< 10;i++) array[i] = 6*array[i-1]-array[i-2]; for(int i=0;i< 10;i++){ //System.out.println(" "+array[i]+" "+(Math.sqrt(8*array[i]*array[i]+1)-1)/2); } System.out.println(" "+6+" "+8); System.out.println(" … Continue reading

Posted in poj | Leave a comment

Poj Solution 1319

http://poj.org/problem?id=1319 //* @author: import java.util.*; public class Main { static final double l = Math.sqrt(3)/2; static int calc( double x, double y ) { int a[]=new int[2], s, i; double h; if( x < 1 ) return 0; a[0] = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1318

http://poj.org/problem?id=1318 import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); List< String> s1 = new ArrayList< String>(); List< String> s2 = new ArrayList< String>(); int indexS1 = 0; int indexS2 = 0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1317

http://poj.org/problem?id=1317 #include <iostream> #include <cstring> using namespace std; char ci[1000]; char pl[1000]; int main() { int k,temp,t1; int i; int len; while(cin>>k && k) { getchar(); gets(ci);//输入密文 len=strlen(ci); for(i=0;i<len;i++) { if(ci[i]==’.’)//这两点要特判 temp=27; else if(ci[i]==’_’) temp=0; else temp=ci[i]-‘_’-1; t1=(temp+i)%28; //密文跟明文相对应 if(t1==0) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1315

http://poj.org/problem?id=1315 //* @author: import java.io.*; import java.util.StringTokenizer; /*����,ÿ���Wall��λ����}�����,��rook����,���Թ�����Ӽ��ռ���,���ݵõ����Էŵ����rook�� *���ռ���Ϊһ�ö�����,������nΪ16,ʱ�临�Ӷ�ΪO(2^n)<=65536,�����㷨���� *�����Լ�������rook����ֱ��ˮƽ�����Ҵ�λ�ò�Ϊǽ.. */ class cin { static int leave=0; static StringTokenizer st; static BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); static int nextInt() throws IOException { while(leave==0) { st=new StringTokenizer(in.readLine()); leave=st.countTokens(); } int a=Integer.parseInt(st.nextToken()); leave–; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1314

http://poj.org/problem?id=1314 #include<iostream> using namespace std; int main() {int p[27][3],n,cas,line; int i,j,k,h,jie;char a; cas=1; while(1) {cin>>n; if(cin.fail())break; if(n==0)break; for(i=0;i<n;i++){cin>>a;p[i][0]=a;cin>>p[i][1];cin>>p[i][2];} line=0;jie=0; cout<<"Point set "<<cas<<":"; for(i=0;i<n;i++) {for(j=0;j<n;j++)if(p[i][2]==p[j][2]&&p[i][1]<p[j][1]) {for(k=0;k<n;k++)if(p[k][1]==p[j][1]&&p[k][2]<p[j][2]) {for(h=0;h<n;h++)if(p[h][1]==p[i][1]&&p[h][2]==p[k][2]) {if(line==0)cout<<endl; cout<<‘ ‘<<(char)p[i][0]<<(char)p[j][0]<<(char)p[k][0]<<(char)p[h][0]; line++;if(line%10==0){cout<<endl;}} }}} if(line==0)cout<<" No rectangles"<<endl; else if(line%10!=0)cout<<endl; cas++; } return 0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1313

http://poj.org/problem?id=1313 //* @author: import java.util.*; public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); int n,max; int i; while(in.hasNext()){ n=in.nextInt(); if(n==0) break; max=n/4+1; System.out.printf("Printing order for %d pages:n",n); if(n%4==1){ int k=3; if(n==1) System.out.printf("Sheet 1, front: … Continue reading

Posted in poj | Leave a comment

Poj Solution 1312

http://poj.org/problem?id=1312 import java.math.BigInteger; import java.util.ArrayList; import java.util.List; import java.util.Scanner; /** * * Accepted. BigInteger is used here. * * */ public class Main { /** * Check if the given string is in numberic format. * * @param a * … Continue reading

Posted in poj | Leave a comment

Poj Solution 1309

http://poj.org/problem?id=1309 //* @author: import java.util.*; public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); long N,i,j,t,ans; int flag=0; N=in.nextLong(); while(N>0) { flag=0; for(j=N-1;j>1;j–) { i=0; t=N; while(t%j==1) { t-=(t/j+1); i++; } if(t%j==0&&i==j) { flag=1; ans=j; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1308

http://poj.org/problem?id=1308 #include<iostream> using namespace std; short ins[50000]; bool bb[50000]; int main() { int a,b,c=1; int i; memset(bb,0,sizeof(bb)); memset(ins,0,sizeof(ins)); int iMax=-1; int zero; bool flag;// ones; while(scanf("%d%d",&a,&b)) { if(a==-1 && b==-1) break; if(a==0 && b==0) { zero=0; flag = false; for(i=1;i<=iMax;++i) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1307

http://poj.org/problem?id=1307 #include"stdio.h" bool left[13][13]; bool right[13][13]; bool up[13][13]; bool down[13][13]; int n,m,x1,x2,y1,y2; bool init() { int i,j,s; scanf("%d %d %d %d %d %d",&n,&m,&x1,&y1,&x2,&y2); if(n==0&&m==0&&x1==0&&x2==0&&y1==0&&y2==0) return 0; x1–,x2–,y1–,y2–; for(i=0;i<n;i++) for(j=0;j<m;j++) { scanf("%d",&s); right[i][j] = left[i][j+1]= (s&1); down[i][j] = up[i+1][j]= (s&2); } … Continue reading

Posted in poj | Leave a comment

Poj Solution 1306

http://poj.org/problem?id=1306 //* @author ������&lt;hongxp11@163.com&gt; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(true) { int n = in.nextInt(); int m = in.nextInt(); int m1 = m; BigInteger … Continue reading

Posted in poj | Leave a comment

Poj Solution 1302

http://poj.org/problem?id=1302 /* @author:zeropinzuo */ import java.io.*; import java.util.*; public class Main{ static Scanner cin; public static void main(String args[]){ cin = new Scanner(System.in); while(run()==true) ; } static boolean run(){ String marker = cin.next(); if(marker.compareTo("ENDOFINPUT")==0) return false; int n = cin.nextInt(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1300

http://poj.org/problem?id=1300 //* @author: 82638882@163.com import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); while(true) { String s=in.next(); if(s.equals("ENDOFINPUT"))break; int loc=in.nextInt(); int n=in.nextInt(); in.nextLine(); int[] door=new int[n]; int doors=0; for(int i=0;i< n;i++) { s=in.nextLine(); if(s.equals("")) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1299

http://poj.org/problem?id=1299 //* @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 s1; int r,g,w; while (true){ s1=scanner.next(); if (s1.equals("ENDOFINPUT")){ break; } r=scanner.nextInt(); g=scanner.nextInt(); w=scanner.nextInt()%360; if (w>180){ w=360-w; } int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1298

http://poj.org/problem?id=1298 import java.io.BufferedInputStream; import java.util.Scanner; public class Main { String cipher; char[] message; char c; public Main() { Scanner scan = new Scanner(new BufferedInputStream(System.in)); while (!(cipher = scan.nextLine()).equals("ENDOFINPUT")) { while (!(cipher = scan.nextLine()).equals("END")) { message = cipher.toCharArray(); for (int i … Continue reading

Posted in poj | Leave a comment

Poj Solution 1291

http://poj.org/problem?id=1291 //* @author: <strong>Yeming&nbsp;Hu</strong>&quot;cslittleye@gmail.com&quot; import java.util.*; import java.io.BufferedInputStream; public class Main { public static Node[] nodes; public static void main(String[] args) { Scanner sc = new Scanner(new BufferedInputStream(System.in)); while(true) { int n = sc.nextInt(); if(n == 0) { break; } … Continue reading

Posted in poj | Leave a comment

Poj Solution 1289

http://poj.org/problem?id=1289 #include<iostream> using namespace std; int main(){ int init_hei, work_num; while(cin >> init_hei >> work_num && init_hei != 0){ int n = 0, v1, v2, x; bool flag = false; while(!flag){ // 模拟解方程(n+1)^x = init_hei, n^x = work_num。 n ++; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1287

http://poj.org/problem?id=1287 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; class Edge implements Comparable{ int start,end; int cost; public int compareTo(Object temp){ Edge cnt = (Edge) temp; if(cnt.cost< this.cost) return 1; return -1; } } class Set{ final int N = 100; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1281

http://poj.org/problem?id=1281 import java.io.PrintWriter; import java.io.PrintWriter; import java.util.Collections; import java.util.PriorityQueue; import java.util.Scanner; public class Main { Scanner cin = new Scanner(System.in); PrintWriter out=new PrintWriter(System.out,true); public void solve() { int maxCost,removeLen; String op; while(cin.hasNext()) { maxCost=cin.nextInt(); removeLen=cin.nextInt(); int [] list=new int[removeLen]; for(int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1277

http://poj.org/problem?id=1277 /* @author:zeropinzuo */ import java.io.*; import java.util.*; import java.math.BigInteger; public class Main{ static Scanner cin; public static void main(String args[]){ cin = new Scanner(System.in); int num = cin.nextInt(); for(int i=0;i< num;i++) run(); } static void run(){ int p = … Continue reading

Posted in poj | Leave a comment