LeeBlog

导航

上一页 1 2 3 4 5 6 7 8 9 ··· 19 下一页

2011年5月11日 #

福州大学 括号问题

摘要: 这题当时比赛的时候想到是深搜,但当时深搜做得不多,没做得出,后来看以大牛代码才会写,主要是判断条件写得好。#include<stdio.h>#include<string.h>char str[20];int l,cnt;void DFS( int k,int num ){ if( num < 0 )//右括号不能多于左括号 return ; if( k == l ) { if( num == 0 )//当左边跟右边的括号相等且刚好到最后一个,就是一中符合条件的可能 ++cnt; return; } if( str[k] == '(' ) DFS( 阅读全文

posted @ 2011-05-11 11:19 LeeBlog 阅读(169) 评论(0) 推荐(0) 编辑

HDU 1312 Red and Black

摘要: 这题忒easy了。。。。直接搜吧。。 都不用回溯的#include<stdio.h>#include<string.h>int map[25][25],des[25][25],n,m,sx,sy;void DFS( int y,int x ){ if( map[y][x] == '#'||des[y][x]||y > n || x > m ) return ; des[y][x] = 1; DFS( y - 1,x ); DFS( y + 1,x ); DFS( y,x - 1 ); DFS( y,x + 1 ); }int main( ){ 阅读全文

posted @ 2011-05-11 10:29 LeeBlog 阅读(174) 评论(0) 推荐(0) 编辑

HDU 1010 Tempter of the Bone

摘要: 这题如果是神搜的一基本题目,每次都向四个方向神搜就行了,不过要考虑剪枝,要用奇偶剪枝,否则TLE,还有用一个标记f,标记当前是否已找到来剪枝。如果还想减少时间就可以在输入时做一个标记,看当前有多少个可以走的点,如果可以走的点小于总时间t那么肯定是NO,这样要减少很多饿。。。。#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>int n,m,t,sx,sy,ex,ey,f;int maz[10][10],des[10][10];void DFS( int y,i 阅读全文

posted @ 2011-05-11 09:49 LeeBlog 阅读(220) 评论(0) 推荐(0) 编辑

2011年5月10日 #

HDU 2181 哈密顿绕行世界问题

摘要: 这个就是一深搜,不解释,还有,测试数据太弱了。#include<stdio.h>#include<string.h>int map[23][4],des[23],num[23],f,n;void DFS( int p,int nu ){ if( nu == 20 && ( map[p][1] == n || map[p][2] == n || map[p][3] == n ) ) { printf( "%d: ",++f ); for( int i = 0; i < 20; ++i ) printf( "%d &quo 阅读全文

posted @ 2011-05-10 23:23 LeeBlog 阅读(553) 评论(0) 推荐(0) 编辑

HDU 2553 N皇后问题

摘要: 这题跟其实是以DFS经典题,如果按一般思路一行一行来选,那样会灰常暴力,但是仔细思考可得这题可简化思路,因为没行只能放一个,所以只要搜索N个就行了。。。。。 而对于每一个只要判断跟前面是否有冲突就行了( DP 思想,分步来 )。#include<stdio.h>#include<string.h>int n,map[20],des[20],cnt,num[11];void DFS( int num ){ if( num == n + 1 ) { ++cnt; return ; } for( int i = 1; i <= n; ++i ) { if( !des[i 阅读全文

posted @ 2011-05-10 19:18 LeeBlog 阅读(231) 评论(0) 推荐(1) 编辑

HDU 1063 Exponentiation

摘要: JAVA 水过import java.io.*;import java.util.*;import java.math.*;public class aa{ public static void main( String[] args ) { BigDecimal a,b; int c; Scanner cin = new Scanner(System.in); while( cin.hasNext() ) { a = cin.nextBigDecimal(); b = BigDecimal.valueOf(1); c = cin.nextInt(); for( int i = 0; i &l 阅读全文

posted @ 2011-05-10 11:10 LeeBlog 阅读(222) 评论(0) 推荐(0) 编辑

POJ PKU 2305 java大数进制转化 JAVA 大数转换成字符串 转

摘要: 题目描述:给你两个n进制数a和b。以n进制的形式输出a % b。解题报告:String st = Integer.toString(num, base); // 把num当做10进制的数转成base进制的st(base <= 35).int num = Integer.parseInt(st, base); // 把st当做base进制,转成10进制的int(parseInt有两个参数,第一个为要转的字符串,第二个为说明是什么进制).BigInter m = new BigInteger(st, base); // st是字符串,base是st的进制.1.如果要将一个大数以2进制形式读入 阅读全文

posted @ 2011-05-10 10:15 LeeBlog 阅读(319) 评论(0) 推荐(0) 编辑

HDU 1715 大菲波数

摘要: JAVA水过import java.io.*;import java.util.*;import java.math.*;public class aa{ public static void main( String[] args ) { BigInteger f[] = new BigInteger[1005]; f[1] = BigInteger.valueOf(1); f[2] = BigInteger.valueOf(1); for( int i = 3; i < 1005; ++i ) f[i] = f[i-1].add(f[i-2]); Scanner cin = new 阅读全文

posted @ 2011-05-10 09:55 LeeBlog 阅读(190) 评论(0) 推荐(0) 编辑

2011年5月9日 #

大明 A + B JAVA

摘要: java 水过import java.io.*;import java.util.*;import java.math.BigDecimal;public class aa{ public static void main( String args[] ) { BigDecimal a,b; Scanner in = new Scanner ( System.in ); //int t = in.nextInt(); while( in.hasNext() ) { a = in.nextBigDecimal();b = in.nextBigDecimal(); BigDecimal c = a 阅读全文

posted @ 2011-05-09 21:33 LeeBlog 阅读(207) 评论(0) 推荐(0) 编辑

HDU 2614 Beat

摘要: 其实这题是一DFS的简单题,但是题目意思,是在让人蛋痛啊!这题就是解决一个问题后,解决下一个问题的时间一定要比解决这题的多或者等于这题。。。。。但那英文是在太难看;第1个是第0个,时间为0,然后解决下一个。代码如下#include<stdio.h>#include<string.h>int n,des[20],max;int num[20][20],N[20];void DFS( int p,int val,int nu ){ int f = 0; for( int i = 1; i <= n; ++i ) { if( !des[i] && ( n 阅读全文

posted @ 2011-05-09 19:03 LeeBlog 阅读(384) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 8 9 ··· 19 下一页