上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 27 下一页
摘要: 该题与HDU 1728 逃离迷宫是一样的解题思路http://acm.hdu.edu.cn/showproblem.php?pid=1728;这里我采取的方法还是一直走到底,如果没有路了就代表一定要转完了。#include<stdio.h>#include<stdlib.h>#include<string.h>struct T{ int x,y,turn;}q[1000024];int map[1024][1024],n,m,k;int d[4][2]={ 0,1,1,0,0,-1,-1,0 };int hash[1024][1024];int inline 阅读全文
posted @ 2011-11-24 11:46 wutaoKeen 阅读(1090) 评论(0) 推荐(0) 编辑
摘要: 该题是一道典型的搜索题,#include<stdio.h>#include<stdlib.h>#include<string.h>struct Node{ int x, y; int time; int flag;}q[100024];int d[4][2]={ 0,1,1,0,0,-1,-1,0 };int N,M;char map[2][13][13];void getxy( int &X,int &Y,int &K ){ for( int k=0;k<2;k++ ) for( int i=1;i<=N;i++ ) f 阅读全文
posted @ 2011-11-24 11:42 wutaoKeen 阅读(333) 评论(0) 推荐(0) 编辑
摘要: 思路: 由于一个盒子在考虑放入另一个盒子之前,要考虑两个因素,宽和高,如果我们能够消除一个因素,就在一维的条件下考虑会简单些。怎么才能降低维数呢。因为只有w小于另一个时才能才能考虑是否能放,所以我们就把w从小到大排序,这样大体盒子的先后顺序就有了,我们在比较的时候就不需要考虑宽了,因为只有后边的盒子才能容纳前边的盒子,这时我们就可以用LIS了。先不考虑w和h相同的情况,排好序后,从第一个盒子开始遍历,第一个盒子不能容纳其他任何的盒子(宽最小)。然后第二个,看他能不能容纳第一个,只需考虑h满足要求与否。然后第三个,问题来了,它既能容纳第一个,又能容纳第二个,选择哪一个,贪心就在这,它能刚好容纳谁 阅读全文
posted @ 2011-11-21 22:12 wutaoKeen 阅读(406) 评论(0) 推荐(0) 编辑
摘要: 这题就是有一点要注意:要开一个三维数组来保存每个点的步数状态,因为那些障碍物会在第k的倍数消失,所以在该点来走过也是可以再走的,所以要开一个三维数组保存步数状态,以为每个时间段的步数是不同的。#include<stdio.h>#include<stdlib.h>#include<string.h>const int inf=0x7fffffff;struct T{ int x,y; int step; }q[100024];int hash[124][124][16],n,m,k,X,Y;int d[4][2]={0,1,1,0,0,-1,-1,0};cha 阅读全文
posted @ 2011-11-21 19:15 wutaoKeen 阅读(423) 评论(0) 推荐(0) 编辑
摘要: 该题用的知识是:如果点在三角形内,则这个点为顶点的三个角之和为360度。#include<stdio.h>#include<stdlib.h>#include<math.h>double x1,Y1,x2,y2,x3,y3,x,y;double length( double a1,double b1,double a2,double b2 ){ return ( a1-a2 )*( a1-a2 )+( b1-b2 )*( b1-b2 ) ; }double area( double a1,double b1,double a2,double b2,doubl 阅读全文
posted @ 2011-11-20 20:46 wutaoKeen 阅读(257) 评论(0) 推荐(0) 编辑
摘要: 这个题伤到我了!!!!搞了我好久才把他给弄出来;这里采取的方法是当选取一个方向是就一直走到底,如果没有到终点,那么一定会要转弯;#include<stdio.h>#include<stdlib.h>#include<string.h>const int inf=0x7fffffff; struct T{ int x,y; int turn; }q[100024];int d[4][2]={0,1,1,0,0,-1,-1,0};int hash[124][124],n,m,x1,x2,y1,y2,k;char map[124][124];void init( 阅读全文
posted @ 2011-11-19 17:47 wutaoKeen 阅读(195) 评论(0) 推荐(0) 编辑
摘要: 典型的BFS题,这里要注意的就是边界条件,就是2*X不要超过人与牛的距离绝对值之差加上牛的距离,应为超过就没意义了,因为最长时间为人与牛的距离绝对值之差;#include<stdio.h>#include<stdlib.h>#include<string.h>struct T{ int place,time; }q[200000];int hash[200024];int BFS( int pointA,int pointB ){ int number=abs( pointA-pointB ); memset( hash,0,sizeof( hash ) ) 阅读全文
posted @ 2011-11-19 09:26 wutaoKeen 阅读(334) 评论(0) 推荐(0) 编辑
摘要: 这题重要的走过的点可以走第二次,但是我们会发现当走过4时我们可以标记为0,因为回走是没必要#include<stdio.h>#include<stdlib.h>#include<string.h>struct T{ int x,y,time,step; }q[10024];int map[12][12],N,M,x,y;int d[4][2]={ 1,0,0,1,-1,0,0,-1 };int BFS( ){ int first=0,end=0; T t; t.step=0;t.time=6; t.x=x;t.y=y; q[end++]=t; wh... 阅读全文
posted @ 2011-11-18 21:35 wutaoKeen 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 该题是一道典型的BFS题,如果你用DFS你就会要把所有的肯能枚举,而BFS就不需要这样。#include<stdio.h>#include<stdlib.h>struct T{ int x, n; }q[424];int BFS( int n,int k[],int start,int end ){ int first=0,tail=0,hash[224]={0}; T t; hash[start]=1; t.x=start;t.n=0; q[first++]=t; while( first>tail ) { int count=q[t... 阅读全文
posted @ 2011-11-18 17:10 wutaoKeen 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 猜数字刚开始看有点假假的,但是仔细用二分分析时,你就会发现只有2^n-1时,才可能满足猜n次你才能猜对。 1 #include<stdio.h> 2 #include<stdlib.h> 3 __int64 pow( int n ) 4 { 5 __int64 sum=1; 6 for( int i=1;i<=n ;i++) 7 sum*=2; 8 return sum-1; 9 }10 int main()11 {12 int T,n;13 scanf( "%d",&T );14 while( T-- )15 {16 sc... 阅读全文
posted @ 2011-11-18 17:06 wutaoKeen 阅读(186) 评论(0) 推荐(0) 编辑
上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 27 下一页