Category Archives: poj

Poj Solution 1810

http://poj.org/problem?id=1810 #include<iostream> #include"algorithm" using std::sort; using namespace std; int s[1001],N,K,M; long d[10000]; int max() {int i,k=M; for(i=M+1;i<=N;i++)if(s[k]<=s[i])k=i; return k; } void find() {int i,j,k,h,down,up,x=N,y=N,best=0; for(i=N,j=0,h=0;i>=M;i–) {while(h<j&&d[h]%2000>i) {down=d[h]/2000;up=down+M-1<N?down+M-1:N; for(k=down;k<=up;k++)s[k]–; h++; } while(j<K&&i-d[j]%2000<M) {down=d[j]/2000;up=down+M-1<N?down+M-1:N; for(k=down;k<=up;k++)s[k]++; j++; } k=max(); if(s[k]>best){best=s[k];y=k;x=i;} if(j>=K)break; } cout<<x-M<<‘ … Continue reading

Posted in poj | Leave a comment

Poj Solution 1808

http://poj.org/problem?id=1808 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; import java.math.*; public class Main { public static long mod(long a,long b,long c) { long ret=1%c; while(b!=0) { if((b&0x1)!=0) ret=ret*a%c; a=a*a%c; b>>=1; } return ret; } public static void main(String args[]) throws … Continue reading

Posted in poj | Leave a comment

Poj Solution 1804

http://poj.org/problem?id=1804 //* @author import java.util.*; public class Main { static int count=0; /** * @param args */ public static void main(String[] args) { Scanner in=new Scanner(System.in); String t=in.nextLine(); int tcase=Integer.parseInt(t); for(int j=1;j<=tcase;j++){ count=0; String str = in.nextLine(); String b[]=str.split("\s"); int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1803

http://poj.org/problem?id=1803 #include"stdio.h" #include<iostream> #include"memory.h" #include"algorithm" using namespace std; int tree[1024*1024*2]; int stop[1024*1024*2]; long m[1024*1024*2]; long area; int x1,y1,x2,y2,key; long temp; void search(int s,long mj); void find(int xu,int yu,int xd,int yd,long s,long mj,int k) { if(xu>=x2||xd<=x1||yu>=y2||yd<=y1){return;} if(key){tree[s]++;} if(!key){tree[s]–;} if(xu>=x1&&yu>=y1&&xd<=x2&&yd<=y2) {if(!key)stop[s]–;else tree[s]–; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1800

http://poj.org/problem?id=1800 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader re=new BufferedReader(new InputStreamReader(System.in) ); int T=Integer.parseInt(re.readLine()); for(int i=1;i<=T;i++) { int n=0,last=0; boolean[] use=new boolean[300010]; Set strset=new TreeSet(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1799

http://poj.org/problem?id=1799 //* @author popop0p0popo import java.util.*; import java.io.*; import java.text.*; public class Main{ public static void main(String[] args){ Scanner scanner=new Scanner(new BufferedReader(new InputStreamReader(System.in))); int n=scanner.nextInt(); double r,t; for (int i=0;i< n ;i++ ){ r=scanner.nextDouble(); t=scanner.nextDouble(); System.out.println("Scenario #"+(i+1)+":"); DecimalFormat df=new DecimalFormat("0.000"); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1794

http://poj.org/problem?id=1794 /* @author: */ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int cas, k; cas=sc.nextInt(); for( k=1; k<=cas; k++ ) { int s1[]=new int[60010], s2[]=new int[60010]; int i, n, m, … Continue reading

Posted in poj | Leave a comment

Poj Solution 1789

http://poj.org/problem?id=1789 import java.io.PrintWriter; import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); //Scanner scn = new Scanner(Main.class.getResourceAsStream("in.dat")); PrintWriter out = new PrintWriter(System.out); int[][] table; String[] input; int n = 0; while(true){ n = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1787

http://poj.org/problem?id=1787 #include<iostream> #include"memory.h" using namespace std; char set[10000]; int use[10000][4]; long total[10000]; int money[4]={1,5,10,25}; int limit[4],p; void doit() {int i,j,h,k; memset(set,0,10000*sizeof(char)); memset(use,0,10000*4*sizeof(int)); set[0]=1; total[0]=0; for(i=0;i<4;i++) for(j=0;j<=p-money[i];j++) {h=j+money[i]; if(set[j]&&(!set[h]||total[h]<total[j]+1)&&use[j][i]<limit[i]) {set[h]=1; for(k=0;k<4;k++)use[h][k]=use[j][k]; use[h][i]=use[j][i]+1; total[h]=total[j]+1; } } return; } int main() {int i; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1786

http://poj.org/problem?id=1786 //* @author: SmilingWang import java.util.*; public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); Map< String, Integer> map = new HashMap< String, Integer>(); map.put("N", 0); map.put("E", 1); map.put("S", 2); map.put("W", 3); String pos[] = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1784

http://poj.org/problem?id=1784 /* @author: */ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int p[]=new int[202]; int q[]=new int[202]; int s[][]=new int[202][202]; int ans[][]=new int[202][202]; int sum[]=new int[202]; int n , i, … Continue reading

Posted in poj | Leave a comment

Poj Solution 1783

http://poj.org/problem?id=1783 #include<iostream> using namespace std; int prime[200],t[200],n; void doprime() {int i,j; n=1; prime[0]=2; for(i=3;i<1000;i++) {for(j=0;j<n;j++)if(i%prime[j]==0)break; if(j==n)prime[n++]=i; } } void fjie(int a[200],int s) {int i; for(i=0;i<200;i++)a[i]=0; for(i=0;i<n&&s>1;i++) while(s%prime[i]==0){a[i]++;s/=prime[i];} } int fn[101][200],fd[101][200],k,m,fdp[101][200],fnp[101][200]; int now[200]; void init() {int i,s,j,h; cin>>s; fjie(now,s); cin>>k; for(i=0;i<k;i++) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1782

http://poj.org/problem?id=1782 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { /** * @param args */ public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub int i,j,n,cotinue; boolean is_first; String str; Scanner cin = new Scanner(System.in); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1781

http://poj.org/problem?id=1781 //* @author: 82638882@163.com import java.io.*; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); while(true) { String s=in.readLine(); if(s.equals("00e0")) break; int a=(int)(((s.charAt(0)-‘0’)*10+s.charAt(1)-‘0’)*Math.pow(10, s.charAt(3)-‘0’)); s=Integer.toBinaryString(a); s=s.substring(1)+s.charAt(0); a=Integer.parseInt(s, 2); System.out.println(a); } … Continue reading

Posted in poj | Leave a comment

Poj Solution 1775

http://poj.org/problem?id=1775 /* @author: */ import java.util.*; public class Main { static StringBuffer res = new StringBuffer(); public static void main(String[] args){ Scanner in = new Scanner(System.in); int maxn=1100000; int a[]=new int[11]; boolean f[]=new boolean[maxn]; int n; a[0]=1; for(int i=1;i<=10;i++) a[i]=i*a[i-1]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1774

http://poj.org/problem?id=1774 #include<iostream> using namespace std; struct point {double x,y;}; struct line {point a,b;}; point a[1010],b[1010]; int n,d[1010]; inline double cheng(point a,point b,point c) {return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);} inline double dcheng(point a,point b,point c) {return (b.x-a.x)*(c.x-a.x)+(c.y-a.y)*(b.y-a.y);} /////////////// void init() {int i; d[0]=-1; a[0].x=0;b[0].x=0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1766

http://poj.org/problem?id=1766 #include<iostream> using namespace std; int edge[32][32],sign[32]; int e[][2]={{0,1},{0,2},{0,3},{0,4},{0,5}, {11,6},{11,7},{11,8},{11,9},{11,10}, {1,2},{2,3},{3,4},{4,5},{5,1}, {6,7},{7,8},{8,9},{9,10},{10,6}, {1,6},{1,7}, {2,7},{2,8}, {3,8},{3,9}, {4,9},{4,10}, {5,10},{5,6}, }; void find(int a) {int i; for(i=0;i<32;i++) if(edge[a][i]&&sign[i]==0){sign[i]=1;find(i);} } int main() {int i,j,a,b,k,h,n,yes,no,past; for(i=0;i<32;i++) for(j=0;j<32;j++)edge[i][j]=0; for(i=0;i<30;i++) {a=e[i][0];b=e[i][1];edge[a][b]=edge[b][a]=1;} h=12; for(i=0;i<12;i++) for(j=i+1;j<12;j++) for(k=j+1;k<12;k++) if(edge[i][j]&&edge[i][k]&&edge[j][k]) {edge[h][i]=edge[i][h]=1; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1763

http://poj.org/problem?id=1763 #include<iostream> #include"memory.h" #include"algorithm" using namespace std; long x[260000],y[260000]; long ordx[260000],ordy[260000]; inline long abs(long a) {return a>0?a:-a;} int cmpx(long a,long b) {return x[a]<x[b]||(x[a]==x[b]&&y[a]<y[b]);} int cmpy(long a,long b) {return y[a]<y[b]||(y[a]==y[b]&&x[a]<x[b]);} int main() {char c;long xn,yn,n,i,bb,eb,lb,b,e,l; cin>>n; xn=0;yn=0;ordx[0]=0;ordy[0]=0;x[0]=0;y[0]=0; for(i=1;i<=n;i++) {cin>>c; switch(c) {case’N’:yn–;break; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1761

http://poj.org/problem?id=1761 #include<iostream> #include"string.h" #include"stdio.h" using namespace std; char name[62][10],w[10]; long ci[62][9],ti[62][9]; int main() {long i,n,j,m,t,c;char q,a; for(i=0;i<62;i++) for(j=0;j<9;j++){ti[i][j]=-1;ci[i][j]=0;} cin>>n; m=0; while(n–) {cin>>t>>w>>q>>a; for(i=0;i<m;i++)if(strcmp(name[i],w)==0)break; if(i==m){m++;strcpy(name[m-1],w);} j=q-‘A’; if(ti[i][j]==-1){ci[i][j]++;if(a==’A’)ti[i][j]=t;} } int ac; for(j=0;j<9;j++) {c=0;t=0;ac=0; for(i=0;i<62;i++) if(ti[i][j]!=-1){ac++;c+=ci[i][j];t+=ti[i][j];} printf("%c %ld",j+’A’,ac); if(ac)printf(" %.2f %.2f",(float)c/ac,(float)t/ac); printf("n"); } … Continue reading

Posted in poj | Leave a comment

Poj Solution 1753

http://poj.org/problem?id=1753 import java.io.BufferedInputStream; import java.util.LinkedList; import java.util.Scanner; public class Main { static boolean[] isVisited = new boolean[65536]; public static void main(String[] args) { Scanner scan = new Scanner(new BufferedInputStream(System.in)); if (scan.hasNext()) { int[][] chessBoard = new int[4][4]; for (int i … Continue reading

Posted in poj | Leave a comment

Poj Solution 1751

http://poj.org/problem?id=1751 //* @author: 82638882@163.com import java.io.*; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); String[] ss; int b=Integer.parseInt(in.readLine()); int[] ax=new int[b]; int[] ay=new int[b]; int[][] p=new int[b][b]; for(int i=0;i< … Continue reading

Posted in poj | Leave a comment

Poj Solution 1745

http://poj.org/problem?id=1745 //* @author: ccQ.SuperSupper import java.util.*; public class Main { static int M = 100+10; static int N = 2; public static void main(String []args) throws Exception{ int n,m,i,j,k,cnt; int DP[][] = new int[N][M]; Scanner cin = new Scanner(System.in); n … Continue reading

Posted in poj | Leave a comment

Poj Solution 1742

http://poj.org/problem?id=1742 /* @author: */ import java.util.Scanner; import java.util.Arrays; public class Main{ public static void main(String args[]) { int N, M; Scanner sc=new Scanner(System.in); while(sc.hasNext()) { N=sc.nextInt();//Ӳ�ҵ����� M=sc.nextInt();// if(N==0&&M==0) break; int a[]=new int[100];//a[i]��ʾ��i��Ӳ�ҵ���ֵ int c[]=new int [100];//c[i]��ʾ��i��Ӳ�ҵĸ��� for (int i=0; i< … Continue reading

Posted in poj | Leave a comment

Poj Solution 1741

http://poj.org/problem?id=1741 #include"stdio.h" #include"algorithm" using namespace std; long use[14]; long lchild[10010][14]; long rchild[10010][14]; long sum[510010][14]; long depth[10010][14]; long value[10010],dist[10010]; long m,n,k,kind,answer; long findit(long key,long s1,long deep) { long &lc=lchild[s1][deep],&rc=rchild[s1][deep],sumnow=sum[s1][deep]; long now=depth[s1][deep]; if(now==key) { if(rc>=0)return sumnow-sum[rc][deep+1]; else return sumnow; } else if(key<now) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1740

http://poj.org/problem?id=1740 /* @author: */ import java.util.Scanner; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int a[]=new int[11]; boolean flag=false; while(sc.hasNext()) { flag=true; int n=sc.nextInt(); if(n==0) break; for(int i=1;i<=n;i++) a[i]=sc.nextInt(); if(n%2==1) { System.out.printf("1n"); continue; }//������������Ȼ�ǵ�һ����Ӯ for(int i=1;i< n&&flag;i++) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1737

http://poj.org/problem?id=1737 import java.util.*; import java.math.*; public class Main { BigInteger[] ans = new BigInteger[52]; public Main() { DP(); solve(); } //求组合数 BigInteger combinationNum(int n, int m) { BigInteger ret = new BigInteger("1"); int i; for (i = 0; i < … Continue reading

Posted in poj | Leave a comment

Poj Solution 1732

http://poj.org/problem?id=1732 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; class word{ String str,num; public void change(){ } } public class Main { static final int N = 100+10,M = 50000+10; static Map mymap = new HashMap(); static int DP[] = new … Continue reading

Posted in poj | Leave a comment

Poj Solution 1731

http://poj.org/problem?id=1731 //* @author: import java.util.*; //���ظ������� public class Main { static Scanner in = new Scanner(System.in); static boolean nextPermutation(char[] s) { int i; for(i=s.length-1; i>0; –i) if(s[i-1]< s[i]) break; if(i==0) return false; –i; int k=i+1; for(int j=i+2; j< s.length; ++j) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1730

http://poj.org/problem?id=1730 //* @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) { long x = sc.nextLong(); long xx = Math.abs(x); if(x == 0) { break; } int result = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1727

http://poj.org/problem?id=1727 #include "stdio.h" #include "algorithm" using namespace std; struct event{ int t, x; }p[100000]; bool cmp( event &a, event &b ) { return a.x+a.t < b.x+b.t; } int n, m; void input( ) { int i; scanf( "%d%d", &n, &m); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1723

http://poj.org/problem?id=1723 import java.io.BufferedInputStream; import java.util.Arrays; import java.util.Scanner; public class Main { static int x[]; static int y[]; public static void main(String[] args) { Scanner scan = new Scanner(new BufferedInputStream(System.in)); if (scan.hasNext()) { int n = scan.nextInt(); x = new int[n]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1719

http://poj.org/problem?id=1719 #include <stdio.h> #include <memory.h> int e[1000][1000], en[1000], col[1000]; int match[1000]; bool sign1[1000], sign2[1000]; int flag[1000]; bool search( int a ) { int i, j; sign1[a] = true; for( i=0; i<en[a]; i++ ) { j = e[a][i]; if( !sign2[j] ) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1716

http://poj.org/problem?id=1716 //* @author: 82638882@163.com import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); int a=Integer.parseInt(in.readLine()); int ans=2,i; my[] arr=new my[a]; String[] ss; for(i=0;i< a;i++) { ss=in.readLine().split(" … Continue reading

Posted in poj | Leave a comment

Poj Solution 1715

http://poj.org/problem?id=1715 #include <stdio.h> #include <algorithm> using namespace std; char *digit = "FEDCBA9876543210"; //0123456789ABCDEF"; int p[8][8]; bool sign[16]; int main() { int i,j,n,k; char ans[9]; for( k=0; k<8; k++ ) { p[k][7-k] = 1; for( i=6-k; i>=0; i– ) p[k][i] = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1714

http://poj.org/problem?id=1714 #include <stdio.h> #include <algorithm> using namespace std; struct node { int id; int order; node *l,*r,*f; int lv,rv,fv; }tree[600]; node *leaf[600]; int n, k; int e[600][3]; int v[600][3]; int d[600]; inline bool isleaf( node *s ) { return s->id … Continue reading

Posted in poj | Leave a comment

Poj Solution 1710

http://poj.org/problem?id=1710 #include<iostream> #include"memory.h" using namespace std; int n; bool map[101][101]; void init() {int i,j;bool k; k=1; for(i=1;i<=n;i++,k=!k) map[i][1]=k; for(i=1;i<=n;i++) for(j=2;j<=n;j++) map[i][j]=!map[i][j-1]; } void doit() {int i,j,step=2*n+1;bool k=true; for(i=1;i<n;i++) {cout<<step; for(j=1;j<=n;j++) if(map[i][j]==k)cout<<‘ ‘<<(i-1)*n+j; cout<<endl; step+=2;k=!k; cout<<step; for(j=1;j<=n;j++) if(map[i][j]==k)cout<<‘ ‘<<(i-1)*n+j; cout<<endl; step+=2;k=!k; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1709

http://poj.org/problem?id=1709 #include<iostream> #include"memory.h" #include"string.h" using namespace std; char word[1000][23]; int index[27]; int n,l,len[1000],set[1000]; void init() { int i; for(i=0;i<26;i++)index[i]=n; for(i=0;i<n;i++) { cin>>word[i]; len[i]=strlen(word[i]); if(index[word[i][0]-‘a’]==n)index[word[i][0]-‘a’]=i; } memset(set,1,1000*sizeof(int)); } char best[100];int go; char w[100]; void find(int a,int b) { if(go&&strcmp(w,best)>0)return; if(b==a&&a) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1708

http://poj.org/problem?id=1708 #include<iostream> #include"memory.h" using namespace std; int set[100][100]; int map[100][10000][2]; int path[100]; int n,l,k,q; int cir[100]; void init() {int i,m,a,b; memset(path,0,100*sizeof(int)); memset(set,0,100*100*sizeof(int)); cin>>n>>l>>k>>q; l–;k–;q–; for(i=0;i<n;i++)cin>>cir[i]; cin>>m; for(i=0;i<m;i++){cin>>a>>b;a–;b–; cin>>map[a][path[a]++][1]; map[a][path[a]-1][0]=b;} } int queue[10000][3],head,tail; void find() {int a,b,c,i,to; head=0;tail=0; queue[tail][0]=l;queue[tail][1]=k; queue[tail][2]=0; set[l][k]=set[k][l]=1; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1707

http://poj.org/problem?id=1707 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; import java.math.*; import java.text.*; public class Main { static class com { BigInteger a,b;//a/b… com add(com C) { com ret=new com(); BigInteger lcm; lcm=b.multiply(C.b).divide(b.gcd(C.b)); ret.b=lcm; ret.a=a.multiply(lcm.divide(b)).add(C.a.multiply(lcm.divide(C.b))); lcm=ret.b.gcd(ret.a); ret.a=ret.a.divide(lcm); ret.b=ret.b.divide(lcm); return ret; } … Continue reading

Posted in poj | Leave a comment

Poj Solution 1706

http://poj.org/problem?id=1706 //* @author: <strong>Yeming&nbsp;Hu</strong>&quot;cslittleye@gmail.com&quot; import java.util.*; import java.io.*; public class Main { public static Map< Integer,Integer> mapOldToNew; public static Map< Integer,Integer> mapNewToOld; public static int counter = 1; public static void main(String[] args) throws Exception { BufferedReader stdin = new … Continue reading

Posted in poj | Leave a comment

Poj Solution 1704

http://poj.org/problem?id=1704 /* @author: */ import java.util.Scanner; import java.util.Arrays; public class Main{ public static void main(String args[] ){ int arr[]=new int[10005]; Scanner sc=new Scanner(System.in); int T=sc.nextInt(); while((T–)!=0){ int n=sc.nextInt(); arr[0] = 0; for (int i = 1; i <= n;i++) arr[i]=sc.nextInt(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1703

http://poj.org/problem?id=1703 //* @author: 82638882@163.com import java.io.*; public class Main { static int[] p,q; static int u; 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()); while((a–)!=0) { String[] ss=in.readLine().split(" "); int n=Integer.parseInt(ss[0]); int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1702

http://poj.org/problem?id=1702 /* @author: */ import java.util.Scanner; import java.util.Arrays; public class Main{ static long ans[]={ 1,3,9,27,81,243,729,2187,6561,19683,59049,177147,531441, 1594323,4782969,14348907,43046721,129140163,387420489,1162261467 }; public static void main(String args[]){ int n; Scanner sc=new Scanner(System.in); n=sc.nextInt(); int p[]=new int[25]; while((n–)!=0){ Arrays.fill(p,0); int a; a=sc.nextInt(); int len=0,i; while(a!=0) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1700

http://poj.org/problem?id=1700 import java.util.Arrays; import java.util.Scanner; public class Main { private static int sum; public static int getSumTime(int[] a, int n) { if (n < 3) { return a[n-1]; } else if (n == 3) { return a[0] + a[1] + … Continue reading

Posted in poj | Leave a comment

Poj Solution 1699

http://poj.org/problem?id=1699 #include<iostream> #include"string.h" #include<vector> #include<algorithm> using namespace std; int m[10][10]; int set[10]; int len[10];int n; int order1[10][9],order2[10][9]; char word[10][22]; int h; int cmp1(int a,int b) {return m[h][a]>m[h][b];} int cmp2(int a,int b) {return m[a][h]>m[b][h];} int link(int a,int b) {int i,j; for(i=0;i<=len[a];i++) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1695

http://poj.org/problem?id=1695 /* @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); int M = cin.nextInt(); for(int i=0;i< M;i++) run(); } static void run(){ int N = cin.nextInt(); int[][] … Continue reading

Posted in poj | Leave a comment

Poj Solution 1694

http://poj.org/problem?id=1694 #include<iostream> #include<vector> #include"stdlib.h" using namespace std; int child[201],need[201]; int ch[201][200]; //int cmp(int i,int j) int cmp(const void * i,const void * j) { if(need[*((int *)i)]<need[*((int *)j)]) return 1; else if(need[*((int *)i)]>need[*((int *)j)]) return -1; return 0; } void doit(int … Continue reading

Posted in poj | Leave a comment

Poj Solution 1693

http://poj.org/problem?id=1693 #include<iostream> using namespace std; char set[100][100]; int n_cl,n_rl; struct line {int x1,x2,y1,y2;}; line c[100],r[100]; inline int min(int a,int b) {if(a<b)return a; else return b; } inline int max(int a,int b) {if(a>b)return a; else return b; } int jiao(line rl,line … Continue reading

Posted in poj | Leave a comment

Poj Solution 1692

http://poj.org/problem?id=1692 #include<iostream> using namespace std; int links[101][101]; int f[101],s[101],n,m; int answer; void find() {int i,j,t,k,h; links[0][0]=0; links[0][1]=0; links[1][0]=0; for(i=1;i<=n;i++) for(j=1;j<=m;j++) {t=links[i-1][j]>links[i][j-1]?links[i-1][j]:links[i][j-1]; if(f[i]!=s[j]) { for(k=i-1;k>=1;k–) if(f[k]==s[j])break; for(h=j-1;h>=1;h–) if(f[i]==s[h])break; if(k&&h&&links[k-1][h-1]+1>t)t=links[k-1][h-1]+1; } links[i][j]=t; } } int main() {int i,t; cin>>t; while(t–) {cin>>n>>m; for(i=1;i<=n;i++)cin>>f[i]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1689

http://poj.org/problem?id=1689 #include<iostream> #include"vector" #include"algorithm" #define max(x,y) (((x)>(y))?(x):(y)) #define min(x,y) (((x)<(y))?(x):(y)) using namespace std; struct point {long x,y;}; struct type_dbx {int n; point d[50]; }; type_dbx dbx[50]; vector <long> x,y; long mx,my; int n; char sign[50*50*2]; inline long cheng(point a,point b,point … Continue reading

Posted in poj | Leave a comment