Author Archives: toad, die

Poj Solution 1845

http://poj.org/problem?id=1845 import java.util.*; public class Main { static long modPow(long a,long n) { long MOD=9901; if (n==1) return a%MOD; long tmp=modPow(a,n>>1); tmp=tmp*tmp%MOD; if ((n&1)==1) tmp=tmp*a%MOD; return tmp; } static long myPow(long a,long n) { if (n==0) return 1; long ans=modPow(a,(n>>1)+1); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1844

http://poj.org/problem?id=1844 //* @author: 82638882@163.com import java.util.*; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); int sun=in.nextInt(); int sum=0; int i; for(i=1;i< 9999;i++) { sum+=i; if (sum>=sun)break; } if((sum-sun)%2==0) System.out.println(i); else if((sum-sun)%2==1&&i%2==1) System.out.println(i+2); else if((sum-sun)%2==1&&i%2==0) System.out.println(i+1); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1840

http://poj.org/problem?id=1840 //* @author: import java.util.*; public class Main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int a1=sc.nextInt(); int a2=sc.nextInt(); int a3=sc.nextInt(); int a4=sc.nextInt(); int a5=sc.nextInt(); System.out.println( hashQuestions(a1,a2, a3,a4,a5)); } /** * @param a1 * @param a2 * @param … Continue reading

Posted in poj | Leave a comment

Poj Solution 1837

http://poj.org/problem?id=1837 //PKU_1837_Balance_DP(û˼·) #include <iostream> #include <cstring> using namespace std; int C,G; int Pos[22]; int Weight[22]; int Value[22][7505];//������ȫΪ��25���������һͷ�����ʮ��Ϊ25*10*15(�۳�) = 3750 //Ȼ���״̬ƽ��ȫΪ��Ϊ7500��״̬��ȡ7505 int main() { while(cin>>C>>G) { for(int i = 1;i <= C;i++) cin>>Pos[i]; for(int i = 1;i <= G;i++) cin>>Weight[i]; memset(Value,0,sizeof(Value)); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1836

http://poj.org/problem?id=1836 //* @author: import java.util.Scanner; public class Main{ private int n; private double a[]; int b[],c[],sum[]; public Main(int n,double a[]){ this.n=n; this.a=a; b=new int[n+1]; c=new int[n+1]; sum=new int[n+1]; } public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); double … Continue reading

Posted in poj | Leave a comment

Poj Solution 1835

http://poj.org/problem?id=1835 //* @author popop0p0popo import java.util.*; import java.io.*; public class Main{ public static int x,y,z,p,h; public static void main(String[] args){ Scanner scanner=new Scanner(new BufferedReader(new InputStreamReader(System.in))); int n=scanner.nextInt(); int m,s; String f; for (int i=0;i< n ;i++ ){ m=scanner.nextInt(); x=y=z=p=0; h=2; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1833

http://poj.org/problem?id=1833 //* @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()); while((a–)!=0) { String[] ss=in.readLine().split(" "); int l=Integer.parseInt(ss[0]); int cnt=Integer.parseInt(ss[1]); int[] arr=new int[l]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1832

http://poj.org/problem?id=1832 import java.math.*; import java.util.*; public class Main { static BigInteger[] base = new BigInteger[128]; static void init(){ base[0] = BigInteger.ONE; for (int i=1; i< 128; i++){ base[i] = base[i-1].multiply(BigInteger.valueOf(2)); } } public static void main(String args[]){ init(); Scanner cin … Continue reading

Posted in poj | Leave a comment

Poj Solution 1830

http://poj.org/problem?id=1830 //* @author: /*��˹��Ԫ,Ȼ������Ԫ��ľ���õ���,����ì�ܵ������޽� �����ĸ���Ϊ2^k kΪ����ȫΪ0������ */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; 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()); } static … Continue reading

Posted in poj | Leave a comment

Poj Solution 1829

http://poj.org/problem?id=1829 #include <stdio.h> #include <memory.h> #include <algorithm> using namespace std; int ans[1025][161], s[1025]; int v[161], n, m; const int MAX = ( (unsigned int)1<<31-1 ); void clac( ) { int i, j, k, t, h, best; memset( ans, 0x7F, sizeof … Continue reading

Posted in poj | Leave a comment

Poj Solution 1828

http://poj.org/problem?id=1828 //* @author: ccQ.SuperSupper import java.util.*; //Monkeys’ Pride class node implements Comparable { int x,y; public int compareTo(Object o) { node oo=(node)o; if(this.x!=((node)o).x) return this.x>((node)o).x?1:0; return this.y>((node)o).y?1:0; } } public class Main{ static int N = 500000+100; public static void … Continue reading

Posted in poj | Leave a comment

Poj Solution 1825

http://poj.org/problem?id=1825 #include"stdio.h" #include<iostream> #include"memory.h" using namespace std; int x[20],y[20],m; int s[2000],len; void cheng(int a) {int i,t; for(i=0,t=0;i<len;i++) {s[i]*=a;s[i]+=t; t=s[i]/10; s[i]%=10; } while(t) {s[len++]=t%10; t/=10; } } int p[]={2,3,5,7,11,13,17,19,23,29,31 ,37,41,43,47,53,59,61,67,71,73,79,83,89,97, 101, 103 , 107, 109 , 113, 127 , 131 , … Continue reading

Posted in poj | Leave a comment

Poj Solution 1823

http://poj.org/problem?id=1823 #include"stdio.h" #include"memory.h" const int L=2048*16; short left[L],right[L],max[L];char stop[L]; #define bigger(a,b) (((a)>(b))?(a):(b)) //inline short bigger(short a,short b) //{return a>b?a:b;} short a,b,key; void insert(short root,short begin,short end) { if(begin>end||b<begin||end<a)return; short l1,l2,*l=&left[root],*r=&right[root]; if(a<=begin&&end<=b) { stop[root]=1; if(key==1) { (*l)=(*r)=max[root]=0; } else { (*l)=(*r)=max[root]=end-begin+1; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1819

http://poj.org/problem?id=1819 #include<iostream> #include"math.h" using namespace std; double r[1000]; double x[1000],t[1000]; char set[1000]; int n; void init() {int i; cin>>n; for(i=0;i<n;i++){set[i]=1;cin>>r[i];} } void doit() {int i,j,k=0,s; for(i=0;i<n;i++) {x[i]=r[i]; k=-1; for(j=0;j<i;j++) if(set[j]) {t[j]=sqrt((r[i]+r[j])*(r[i]+r[j])-(r[i]-r[j])*(r[i]-r[j]))+x[j]; if(t[j]>x[i]){x[i]=t[j];k=j;} } for(j=k+1;j<i;j++)set[j]=0; } double right=0; for(i=0;i<n;i++)if(x[i]+r[i]>right){right=x[i]+r[i];k=i;} for(j=k+1;j<n;j++)set[j]=0; for(i=0,s=0;i<n;i++)if(!set[i])s++; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1816

http://poj.org/problem?id=1816 #include <stdio.h> #include <string.h> #include <memory.h> char w[100000][7]; int len[100000]; int code[100000]; bool check( char *p, int n, char *w, int m ) { bool ans[7][21] = { false }; char *a = p-1, *b = w-1; ans[0][0] = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1813

http://poj.org/problem?id=1813 #include<iostream> #include"math.h" #include"stdio.h" using namespace std; struct point {double x,y;}; const double pi=3.14159265359; 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);} double doit(point p1,point p2,point o,double r) {point px,p[16];int set[16];int s=0;double … Continue reading

Posted in poj | Leave a comment

Poj Solution 1812

http://poj.org/problem?id=1812 #include <stdio.h> #include <queue> #include <vector> #include <memory.h> #include <algorithm> using namespace std; char op[10]; int opn, ans; void search( int h, const int *str, int len ) { int i, j, k; if( h >= ans ) return; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1811

http://poj.org/problem?id=1811 /* @author: */ //��һ����N���ж���N�Ƿ�Ϊ������������������"Prime"�����������N����С������ import java.util.Random; import java.util.Scanner; //http://en.wikipedia.org/wiki/Pollard’s_rho_algorithm public class Main{ static int MAX_COUNT = 6; static long allFactor[ ]=new long [65]; static int nFactor; static Random rn=new Random(); static long fMultiModular( long a, long b, long n) … Continue reading

Posted in poj | Leave a comment

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