Monthly Archives: September 2009

Poj Solution 1154

http://poj.org/problem?id=1154 import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Scanner; public class Main { private static String[] a = null; private static int max = -1; private static int n = 0; private static int m = 0; private static void dfs(int x, … Continue reading

Posted in poj | Leave a comment

Poj Solution 1153

http://poj.org/problem?id=1153 #include <stdio.h> #include<iostream> #include<algorithm> using namespace std; int P[300000]; int SEG=10000000; int main() { long n; long i; long j; double result,tempresult; cin>>n; for(i=0;i<n;i++) { cin>>P[i]; } sort(P,P+n); for(i=0;i<n;i++) { P[i+n]=P[i]+SEG; P[i+2*n]=P[i+n]+SEG; } tempresult=0; int s; s=P[n]+SEG/2; for(i=n+1;P[i]<=s;++i) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1152

http://poj.org/problem?id=1152 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { static int get_base(char c){ if(c>=’0’&&c<=’9′) return c-‘0’+0; if(c>=’A’ && c<=’Z’) return c-‘A’+ 10; if(c>=’a’ && c<=’z’) return c-‘a’ + 36; return -1; } public static void main(String[]args) throws … Continue reading

Posted in poj | Leave a comment

Poj Solution 1151

http://poj.org/problem?id=1151 #include<iostream> #include"stdio.h" #include"vector" #include <algorithm> using namespace std; struct rect {double xt,yt,xb,yb; }; struct point {double x,y;}; double max(double a,double b) {if(a>b)return a; else return b; } double min(double a,double b) {if(a>b)return b; else return a; } /* rect … Continue reading

Posted in poj | Leave a comment

Poj Solution 1150

http://poj.org/problem?id=1150 #include<iostream> #include<cstring> #include<cmath> using namespace std; int get2(int n)//计算n!中质因子2的出现次数 { if(n==0) return 0; return n/2+get2(n/2); } int get5(int n)//计算n!中质因子5的出现次数 { if(n==0) return 0; return n/5+get5(n/5); } ////////////////////////////////////////////////////////////////////////// int g(int n,int x)//计算f(1) to f(n) 中,奇数数列中末尾为x的数出现的次数 { if(n==0) return 0; return … Continue reading

Posted in poj | Leave a comment

Poj Solution 1149

http://poj.org/problem?id=1149 #include <list> #include <vector> using namespace std; class pre_f { public: enum{ MAX = 1000000000 }; //��������� enum{ size = 103 }; //ͼ�����ģ(*) // ����һ��� from �� to �� ��Ϊ c �ı� void insert_edge( int from, int to, int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1148

http://poj.org/problem?id=1148 #include <stdio.h> #include <algorithm> using namespace std; int num[20000], n; int ans_x[10000], ans_y[10000],sign_x[10000], sign_y[10000]; const int xsign[]={ 1, -1, -1, 1 },ysign[]={ 1, 1, -1, -1}, h[]={ 1, -1}; void creat(int end, int num[], int sign[], int ans[], int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1147

http://poj.org/problem?id=1147 #include"stdio.h" int a[3001]; int next[3001]; int main() { int n,i,j,k=0; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&a[i]); if(!a[i])k++; } j=1; k++; for(i=1;i<=n;i++) if(a[i]) { next[k]=i; k++; } else { next[j]=i; j++; } k=1; for(i=1;i<=n;i++) { k=next[k]; printf("%d ",a[k]); } return 0; }

Posted in poj | Leave a comment

Poj Solution 1146

http://poj.org/problem?id=1146 /* @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(cin.next())) ; } static boolean run(String input){ if(input.compareTo("#") == 0) return false; System.out.println(next(input)); return true; } static … Continue reading

Posted in poj | Leave a comment

Poj Solution 1142

http://poj.org/problem?id=1142 import java.util.Scanner; public class Main { public static int sum = 0; public static boolean isPrime(int num) { for (int i = 2; i <= Math.sqrt(num); i++) { if (num % i == 0) return false; } return true; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1141

http://poj.org/problem?id=1141 //* @author: import java.util.*; public class Main { //f[i][j]��λ��i��λ��j����Ҫ�������С�ַ���ans[i][j]��ʾi��j֮������(��ƥ���ַ� private char s[]; private int len; private int f[][]; private String ans[][]; public Main(char s[]){ this.s=s; this.len=s.length; f=new int[len][len]; ans=new String[len][len]; for(int i=0;i< len;i++) Arrays.fill(ans[i],""); dp(); } public String[][] getAns(){ … Continue reading

Posted in poj | Leave a comment

Poj Solution 1140

http://poj.org/problem?id=1140 /* @author: */ import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(new BufferedInputStream(System.in)); int a,b,i,j,c[],f,d; c=new int[2000]; for(;;) { a=cin.nextInt(); b=cin.nextInt(); if(a==0&b==0)break; c[0]=a;i=0;f=0;j=0;d=1; System.out.print("."); for(;;) { a=(a*10)%b; if(a!=0) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1137

http://poj.org/problem?id=1137 //* @author:alpc12 import java.io.BufferedReader; import java.io.FileReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; import java.lang.Integer; class Node { int x, mask; int s; int f; int action; public Node(int x, int mask, int s, int f, int aa) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1135

http://poj.org/problem?id=1135 import java.util.Scanner; public class Main { static final int Inf=9999999; public static void main(String[] args) { Scanner in=new Scanner(System.in); int cnt=0; while(true) { cnt++; int n=in.nextInt(); int m=in.nextInt(); if(n==0&&m==0)break; int[][] p=new int[n][n]; for(int i=0;i< n;i++) for(int j=0;j< n;j++) p[i][j]=Inf; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1133

http://poj.org/problem?id=1133 #include<iostream> #include"math.h" #include<algorithm> #include<vector> using namespace std; struct point {long x,y;}; typedef point vect; struct {point p; int bright; }star[1001]; int sn,vn; double v_sin,v_cos,bi; vect vec[1001]; double len; point pt[1001]; inline double jl(point &a,point &b) {return sqrt(double(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));} inline long … Continue reading

Posted in poj | Leave a comment