Author Archives: toad, die

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

Poj Solution 1276

http://poj.org/problem?id=1276 import java.util.Scanner; public class Main { static int[] value = new int[100]; static int[] dp = new int[100001]; public static void main(String[] args) { Scanner s; try { // s = new Scanner(new InputStreamReader(new FileInputStream( // "c:\1.txt"))); s = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1274

http://poj.org/problem?id=1274 import java.io.*; import java.util.*; public class Main { static int m,n; static boolean[] flag; static int[] occ; static int[][] adj; public static void main(String args[]) throws Exception { Scanner cin=new Scanner(System.in); while(cin.hasNext()) { n=cin.nextInt(); m=cin.nextInt(); adj=new int[n+1][m+1]; for(int i=0;i< … Continue reading

Posted in poj | Leave a comment

Poj Solution 1273

http://poj.org/problem?id=1273 //* @author: import java.util.*; public class Main implements Comparator< Integer> { static class Edge{ int e,c; Edge next; Edge rev; public void dec(int f){ c-=f; rev.c+=f; } } int n,m,src,tag; final Edge[] g=new Edge[200]; final int[] h=new int[200]; final … Continue reading

Posted in poj | Leave a comment

Poj Solution 1269

http://poj.org/problem?id=1269 //* @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))); int n=scanner.nextInt(); double[] x,y; double px,py; double k1,k2,b1,b2; System.out.println("INTERSECTING LINES OUTPUT"); for (int i=0;i< n ;i++ ){ x=new double[4]; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1265

http://poj.org/problem?id=1265 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; class Point{ int x,y; } public class Main { static final int N = 100+10; static int n; static Point Area[] = new Point[N]; static void start(){ for(int i=0;i< N;++i) Area[i] = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1263

http://poj.org/problem?id=1263 #include<iostream> #include"math.h" using namespace std; const double pi=3.14159265358979324; struct point {double x,y;}; struct cir {point p; double r;}; struct ray {point p; double dx,dy;}; struct line {double a,b,c;}; //l: ax+by+c=0 inline double sq(double a) {return a*a;} line ray_line(ray s) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1260

http://poj.org/problem?id=1260 /* @author: */ import java.util.Scanner; import java.util.Arrays; public class Main{ static final int maxn=100; private int a[]=new int[maxn],p[]=new int[maxn],f[]=new int[maxn]; private int min(int a,int b){ return a< b?a:b; } public int dp(int x){ if(x< 0)return 0; if(f[x]!=-1)return f[x]; if(x==0)return … Continue reading

Posted in poj | Leave a comment

Poj Solution 1258

http://poj.org/problem?id=1258 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader( System.in)); String s = null; int n; int[][] a; int t; String[] ss; int index; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1256

http://poj.org/problem?id=1256 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Comparator; public class Main { class Compara implements Comparator<Character> { public int compare(Character o1, Character o2) { char a = Character.toLowerCase(o1); char b = Character.toLowerCase(o2); if (a == b) { … Continue reading

Posted in poj | Leave a comment

Poj Solution 1254

http://poj.org/problem?id=1254 import java.text.DecimalFormat; import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner cin = new Scanner(System.in); DecimalFormat df1 = new DecimalFormat("0.0000"); int n = cin.nextInt(); while(n– > 0) { int x1 = cin.nextInt(); int y1 = cin.nextInt(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1251

http://poj.org/problem?id=1251 import java.io.BufferedInputStream; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.Map.Entry; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(new BufferedInputStream(System.in)); while (scanner.hasNext()) { int n = scanner.nextInt(); if (n … Continue reading

Posted in poj | Leave a comment

Poj Solution 1250

http://poj.org/problem?id=1250 //* @author ������&lt;hongxp11@163.com&gt; import java.util.ArrayList; import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (true) { int num = in.nextInt(); if (num == 0) break; String … Continue reading

Posted in poj | Leave a comment

Poj Solution 1247

http://poj.org/problem?id=1247 //* @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) { int a=in.nextInt(); if(a==0)break; int[] arr=new int[a]; int t=0; for(int i=0;i< a;i++) { arr[i]=in.nextInt(); t+=arr[i]; } if(t%2==1)System.out.println("No equal partitioning."); else … Continue reading

Posted in poj | Leave a comment

Poj Solution 1244

http://poj.org/problem?id=1244 //* @author popop0p0popo import java.util.*; import java.io.*; public class Main{ public static void main(String[] args) throws Exception{ Scanner scanner=new Scanner(new BufferedReader(new InputStreamReader(System.in))); int n,flag; String line,r; char c; int[] idx; while (true){ n=scanner.nextInt(); if (n==0){ break; } line=scanner.next(); r=""; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1243

http://poj.org/problem?id=1243 /* @author:zeropinzuo */ import java.util.*; public class Main{ static Scanner cin; static int Case = 0; static int[][] result; public static void main(String args[]){ cin = new Scanner(System.in); result = new int[100][100]; int i,j; for(i = 0;i < 100;i++) … Continue reading

Posted in poj | Leave a comment

Poj Solution 1240

http://poj.org/problem?id=1240 /* @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(){ int n = cin.nextInt(); if(n==0) return false; Tree tree = new … Continue reading

Posted in poj | Leave a comment

Poj Solution 1230

http://poj.org/problem?id=1230 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; interface Pass{ int N = 100+10; void SetInit(int n,int k); void AddData(int left,int right); void InitData(); int GetAns(); } class Interval implements Comparable{ int left,right; void set(int left,int right){ this.left = left; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1228

http://poj.org/problem?id=1228 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { class Point { int x; int y; public Point(int x, int y) { this.x = x; this.y = y; } } public static void main(String[] args) throws NumberFormatException, IOException … Continue reading

Posted in poj | Leave a comment

Poj Solution 1226

http://poj.org/problem?id=1226 //* @author:alpc12 import java.math.*; import java.io.*; import java.util.*; class Main { public static void main(String[] args) throws Exception { new Main().run(); } private int n; private void run() throws Exception { Scanner cin = new Scanner(System.in); int ntc = … Continue reading

Posted in poj | Leave a comment

Poj Solution 1222

http://poj.org/problem?id=1222 import java.util.Scanner; public class Main { int times; int[][] puzzle; static final int length = 6; static final int width = 5; int[][] arr; int temp; int req; public Main() { Scanner scan = new Scanner(System.in); times = scan.nextInt(); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1221

http://poj.org/problem?id=1221 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { static final int N = 500; static long DP[][] = new long[N][N]; static void init(){ int i,j; for(i=0;i< N;++i) for(j=0;j< N;++j) DP[i][j] = 0; for(i=1;i< N;++i){ for(j=i;j>=0;–j) DP[i][j]=1; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1220

http://poj.org/problem?id=1220 import java.util.*; import java.math.*; public class Main { static int c2i(char c){ if(c>=’0’&&c<=’9′) return c-‘0′; if(c>=’A’&&c<=’Z’) return c-‘A’+10; return c-‘a’+36; } static char i2c(int c){ if(c< 10) return (char)(48+c); if(c>=10&&c< 36) return (char)(‘A’+c-10); return (char)(‘a’+c-36); } public static void … Continue reading

Posted in poj | Leave a comment

Poj Solution 1219

http://poj.org/problem?id=1219 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader( System.in)); String s; String r; int time; char[] last; StringBuilder temp; char[] buff; int pos; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1218

http://poj.org/problem?id=1218 import java.io.BufferedInputStream; import java.util.Scanner; /** *poj1218 * @author NC */ public class Main { public static void main(String[] args) { Scanner scan = new Scanner(new BufferedInputStream(System.in)); if (scan.hasNext()) { int t = scan.nextInt(); for (int i = 0; i … Continue reading

Posted in poj | Leave a comment

Poj Solution 1208

http://poj.org/problem?id=1208 /* @author:zeropinzuo */ import java.util.*; public class Main{ static Scanner cin; static MyList list; public static void main(String args[]){ cin = new Scanner(System.in); int n = cin.nextInt(); list = new MyList(); for(int i = 0;i < n;i++) list.add(new Stack(new … Continue reading

Posted in poj | Leave a comment

Poj Solution 1207

http://poj.org/problem?id=1207 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader( System.in)); int t; int s; int[] len; String str; int start; int end; int max; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1205

http://poj.org/problem?id=1205 //* @author: import java.util.*; import java.math.BigInteger; public class Main { public static void main(String[] args) { BigInteger a[]=new BigInteger[105]; int i,k; BigInteger temp; a[1]=new BigInteger("1"); for(i=2;i<=100;i++) { temp=new BigInteger("1"); for(k=1;k< i;k++) { temp=temp.add(a[k]); } a[i]=temp.add(a[i-1]); } Scanner stdin=new Scanner(System.in); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1201

http://poj.org/problem?id=1201 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; class Intervals{ int left,right,ci; } public class Main { static final int N = 50000+10; static int DP[] = new int[N],n,left,right; static Intervals Inter[] = new Intervals[N]; static void start(){ for(int i=0;i< … Continue reading

Posted in poj | Leave a comment

Poj Solution 1200

http://poj.org/problem?id=1200 #include <iostream> #include <cmath> #include <cstring> using namespace std ; char str[20000000+10] ; int sub, radix, ans, index[256] ; bool hash[20000000+10] ; // 转化为nc进制 void Change() { int i, cnt(0) ; for( i=0; ; ++i ){ if( 0 == … Continue reading

Posted in poj | Leave a comment

Poj Solution 1192

http://poj.org/problem?id=1192 /* @author: */ import java.util.Scanner; public class Main { static int n; static int x[]; static int y[]; static int c[]; static int ans=0; static int search(int i,int parent) { int ret=0,t; for(int j=0;j< n;j++) { if(parent!=j&&Math.abs(x[i]-x[j])+Math.abs(y[i]-y[j])==1) { t=search(j,i); … Continue reading

Posted in poj | Leave a comment

Poj Solution 1190

http://poj.org/problem?id=1190 /* @author: */ import java.util.Scanner; public class Main { static int end,min; static int M,S; static int dfs(int v,int m,int lastr,int lasth) { if(m==0) { //������Ϊ0ʱ��ʣ�����Ϊ0,˵��˴�����ɹ�,Ӧ���� if(v>0||v< 0) return 0; else { //Ϊ0,����Ŀ���н�,�жϵ�ǰ�������Ƿ���Ѿ��õ�����С���С,��С���û�. end=1; if(min< S) S=min; return 0; … Continue reading

Posted in poj | Leave a comment

Poj Solution 1189

http://poj.org/problem?id=1189 /* @author: */ import java.util.*; public class Main { static long gcd(long a,long b)//����a,b�����Լ�� { if(b==0) return a; else return gcd(b,a%b); } public static void main(String[] args){ Scanner sc = new Scanner(System.in); int m,n; long d,tmp; n=sc.nextInt(); m=sc.nextInt(); char … Continue reading

Posted in poj | Leave a comment