# Monthly Archives: October 2009

## Poj Solution 1185

http://poj.org/problem?id=1185 //* @author: /*��Ŀ������һ��n*m�ķ����з����ڱ�Ҫ�����ڣ���û���ڱ�������ܷŶ��� *��ʼ��Ϊû���뵽�õķ�������������һ�Σ�tle… *֪���й���״̬ѹ����㷨���ɲ�̫�����һֱ����û����쿴��һ��״̬ѹ��ģ��㷨 *������д����4���������ڣ�c.. *״̬ѹ����λ4��ʾ״̬������λ�����ʡʱ�䣨���Ǻ�����ᣩ *ö��״̬������״̬ת�ƴӶ�õ����Ž⣬��Ϊ״̬ѹ��DP… */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; class cin { static BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; static int leave=0; static int nextInt()throws IOException { return Integer.parseInt(next()); } … Continue reading

## Poj Solution 1183

http://poj.org/problem?id=1183 //* @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))); long a=scanner.nextInt(); long m=1; for (long i=a;i>=1 ;i– ){ if ((a*a+1)%i==0){ m=i; break; } } System.out.println(2*a+m+(a*a+1)/m); } }

## Poj Solution 1182

http://poj.org/problem?id=1182 import java.io.*; public class Main { public static void main(String[] args) throws IOException { Main poj = new Main(); BufferedReader read = new BufferedReader(new InputStreamReader( System.in)); String[] tm = read.readLine().split(" "); int N = new Integer(tm[0]); int K = … Continue reading

## Poj Solution 1178

http://poj.org/problem?id=1178 //* @author: import java.util.*; public class Main { static int dis[][][][]=new int[8][8][8][8]; static int x[]=new int[64],y[]=new int[64], n; static void floyd() { int i1, i2, i3, j1, j2, j3, t; for( i1=0; i1< 8; i1++ ) for( j1=0; j1< … Continue reading

## Poj Solution 1171

http://poj.org/problem?id=1171 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { static final int N = 1000+10; static int top,ans; static String opt = new String(); static String str[] =new String[N]; static int score[]={2,5,4,4,1,6,5,5,1,7,6,3,5,2,3,5,7,2,1,2,4,6,6,7,5,7}; public static void main(String[]args)throws Exception{ … Continue reading

## Poj Solution 1166

http://poj.org/problem?id=1166 /* @author: */ import java.util.Scanner; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int arr[]=new int[9]; int ans[]=new int[9]; int i=0; for(i=0;i< 9;i++) arr[i]=sc.nextInt(); int a1,a2,a3,a4,a5,a6,a7,a8,a9,cnt; int u[]=new int[9]; int min=100; for(a1=0;a1< 4;a1++) for(a2=0;a2< 4;a2++) for(a3=0;a3< … Continue reading

## Poj Solution 1165

http://poj.org/problem?id=1165 //* @author: import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int sum=in.nextInt(); int lefttop=in.nextInt(); cnt=new int[11][11][11][11][11]; for (int i = 0; i < cnt.length; i++) { for (int j = … Continue reading

## Poj Solution 1164

http://poj.org/problem?id=1164 #include<iostream> #include<string> #include<cmath> #include<algorithm> using namespace std; int mat[55][55]; int num; bool vist[55][55]; void DFS(int x,int y) { num++; vist[x][y]=true; if(mat[x][y]%2==0) //搜索该位置的西方 { if(!vist[x][y-1]) DFS(x,y-1); } mat[x][y]/=2; if(mat[x][y]%2==0) //搜索该位置的北方 { if(!vist[x-1][y]) DFS(x-1,y); } mat[x][y]/=2; if(mat[x][y]%2==0) //搜索该位置的东方 { if(!vist[x][y+1]) DFS(x,y+1); … Continue reading

## Poj Solution 1160

http://poj.org/problem?id=1160 /* @author: */ import java.util.Scanner; import java.util.Arrays; public class Main{ static int num[]=new int[302]; static int s[][]=new int[302][302]; static void cost(int n){ int i,j,k; for(i=1;i< n;i++){ for(k=i+1; k <= n; k ++){ int mid=(i+k)/2; for(j=i;j< mid;j++) s[i][k]+=num[mid]-num[j]; for(j=mid+1;j<=k;j++) s[i][k]+=num[j]-num[mid]; … Continue reading

## Poj Solution 1158

http://poj.org/problem?id=1158 #include <stdio.h> #include <memory.h> #include <vector> #include <queue> using namespace std; int n, begin, end; int b[300], p[300], sum[300]; int r[300]; typedef pair<int,int> p_i; bool s[300][30000]; vector< p_i > e[300]; struct cmp { bool operator()( const p_i &a, const … Continue reading

## Poj Solution 1157

http://poj.org/problem?id=1157 //* @author: 82638882@163.com import java.io.*; public class Main { static boolean[][] p; static int sz; static String[] ss; 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]); … Continue reading

## Poj Solution 1155

http://poj.org/problem?id=1155 /* @author: */ import java.util.*; import java.util.Scanner; public class Main{ static int[][] dp; static int[] offspring; static int[] vert; static int[] parent; static int[] leaf; static int n,k; public static void main(String[] args) { Scanner cin=new Scanner(System.in); n=cin.nextInt(); leaf=new … Continue reading