上一页 1 ··· 28 29 30 31 32 33 34 35 36 ··· 38 下一页
摘要: 简单DFS#include bool used[21];bool prim[41];int now[21];int i,j,n;void out(){ printf("1"); for(int i=2;i<=n;i++) printf(" %d",now[i]); printf("\n");}void dfs(int step){ if (step==n&&prim[now[n]+1]) out();//注意是==,=导致WA for(int i=2;i<=n;i++) if ((!used[i])& 阅读全文
posted @ 2014-02-10 10:32 forever97 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 题目大意:给定你起点S,和终点D,问你是否能在 T 时刻恰好到达终点D。单词积累:doggie 小狗 befascinatedby 被……吸引题解:首先很容易将题目误解为T时刻之前到达,那么广搜无疑,但是要在T时刻刚好到达,就只能DFS了,以下是两个剪枝:1.地图方格数减去障碍数再减1小于T,则直接无解:因为无法在T时刻到达;2.奇偶剪枝:每一步走后,曼哈顿距离与所走步数之和与T的差值必定是偶数,否则剪枝。#include#include#includeusing namespace std;int n,m,t,ex,ey;bool V[10][10],flag,ans;char map[10 阅读全文
posted @ 2014-02-10 09:06 forever97 阅读(297) 评论(0) 推荐(0) 编辑
摘要: #include int main(){int a,b; scanf("%d%d",&a,&b); printf("%d",a+b); return 0;} 阅读全文
posted @ 2014-02-09 20:42 forever97 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 代码#includeint main(){ int a,b; while(scanf("%d%d",&a,&b)!=EOF) printf("%d\n",a+b); return 0;}代码#include int main(){ int a,b; while(scanf("%d%d",&a,&b)!=EOF) printf("%d\n",a+b); return 0;} 阅读全文
posted @ 2014-02-09 20:35 forever97 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 神题,搜索太差,来自网络的题解与程序思路: 封锁出口或者入口周围的格子.最多需要4个封锁点.所以我们可以采取这样的策略:1.寻找一条盗贼的可行路线,如果没有,返回0.2.计算封锁出口和入口四周需要的封锁点数量,取小的一个,假设是k,k #include #include #def... 阅读全文
posted @ 2014-02-09 12:53 forever97 阅读(383) 评论(2) 推荐(0) 编辑
摘要: 广搜……#include #include #include #include using namespace std; struct node { int num[4],step; }; node start,end; bool visit[10][10][10][10],flag; void bfs() { int i; node p,q; queue Q; memset(visit,false,sizeof(visit)); flag=true; start.step=0; p=star... 阅读全文
posted @ 2014-02-09 12:37 forever97 阅读(227) 评论(0) 推荐(0) 编辑
摘要: 题解:记录转弯次数,直接广搜即可#include#includeusing namespace std;char map[102][102];int n,m,bx,by,ex,ey,k,mark[102][102];int dir1[4][2]={{1,0},{-1,0},{0,1},{0,-1}};struct node{ int x,y,step,dir;};void bfs(){ node t; queueq; int i; t.x=bx;t.y=by;t.step=0;t.dir=-1; mark[bx][by]=0; q.push(t); ... 阅读全文
posted @ 2014-02-09 12:15 forever97 阅读(216) 评论(0) 推荐(0) 编辑
摘要: 以前敲过pascal的,一直感觉很麻烦……#include #include using namespace std; struct node { int c,r,lev; }front,tmp,start,end; queue Q; int a[]={0,-2,-2,-1,-1,1,1,2,2}; int b[]={0,-1,1,-2,2,-2,2,-1,1}; int bfs(node s,node e) { int i; while(!Q.empty()) Q.pop(); if(e.c==s.c&&e.r==s.r)... 阅读全文
posted @ 2014-02-09 10:56 forever97 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 简单的广搜:#include #include using namespace std;int map[200005],step[200005];int n,start,end,res;bool check(int x){ if ((x>0)&&(x Q; Q.push(start); step[start]=0; map[start]=false; while(!Q.empty()) { temp=Q.front(); Q.pop(); if (temp+1==end) return step[temp]+1; ... 阅读全文
posted @ 2014-02-09 10:48 forever97 阅读(260) 评论(0) 推荐(0) 编辑
摘要: 简单的广搜#include #include using namespace std;int map[205],step[205],a[205];int n,start,end,res;bool check(int x){ if ((x>0)&&(x Q; Q.push(start); step[start]=0; map[start]=false; while(!Q.empty()) { temp=Q.front(); Q.pop(); if (temp+a[temp]==end) return step[temp... 阅读全文
posted @ 2014-02-09 10:31 forever97 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 在别人的博客上学习了友元函数和进一步理解了优先队列,觉得priority—queue的确很有用。题解:首先,如果按照题目给的错误暗示从朋友开始寻找angle则会很麻烦,于是用广搜的特性,从angle出发向四处扩展即可,遇到卫兵要加2,但是要注意由于这种广搜并非步数优先,所以我们利用A*搜索的思想,每... 阅读全文
posted @ 2014-02-09 09:33 forever97 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 三维广搜#include #include #include #include using namespace std; struct node{ int x,y,z; int steps;}start,end,next;int dx[6]={0,0,0,0,1,-1}; int dy[6]={0,0,-1,1,0,0};int dz[6]={1,-1,0,0,0,0};char maps[15][15][15];int n,res; bool check(node &a){ if(a.x>=0&&a.x=0&&a.y=0&&a.z 阅读全文
posted @ 2014-02-09 09:07 forever97 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 题解:设猜到的最大的数是h,在1到h间,你最多只要猜log2(h)+1(取整)次,所以易知==>h=2^m-1.即猜m次,能猜到的最大的数为2^m-1。#include #include int main(){ int t; scanf("%d",&t); while (t--) { int n; scanf("%d",&n); printf ("%d\n",(int )pow(2.0,n)-1); } return 0;} 阅读全文
posted @ 2014-02-09 08:50 forever97 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 不会做,参见别人的程序:/* 底面为xy平面和轴为z轴的圆锥,给定一些点,使得圆锥覆盖所有点并且体积最小 点都可以投射到xz平面,问题转换为确定一条直线(交x,z与正半轴)使得与x的截距r 和与z轴的截距h满足h*r*r最小。 三分,对于确定的h可以找到最佳的r,并且h*r*r的曲线必定只有一个极小值 */ #include #include #include using namespace std;struct po { double x,y; }p[10005]; const double eps=1e-9; double Y; int n; double make... 阅读全文
posted @ 2014-02-09 08:39 forever97 阅读(254) 评论(0) 推荐(0) 编辑
摘要: 题解:很显然的二分检索,在算法艺术上看过原题,不过这里要注意精度:#include int n,m; double a[10001]; bool test(double x){ int num=0,i; for(i=1;i=m){ return true; }else{ return false; } } int main(){ while(scanf("%d%d",&n,&m),n||m){ int i ; double sum=0; ... 阅读全文
posted @ 2014-02-09 08:30 forever97 阅读(289) 评论(0) 推荐(0) 编辑
摘要: 题解:通过n>=(x+1)*(x)/2解出向下取整,再计算出n在该串中位置,模9输出即可:#include #include #include #include using namespace std;int main(){ long long k,temp,i,n; while(cin>>k) { while(k--) { cin>>n; temp=(-1+sqrt(double(1+8*(n-1))))/2; if(temp%2)n-=((1+temp)/2)*temp; ... 阅读全文
posted @ 2014-02-09 08:17 forever97 阅读(142) 评论(0) 推荐(0) 编辑
摘要: bool find(int x,int l,int r){ if(l>r)return false; int mid=(l+r)/2; if(s[mid]==x) return true; else if(s[mid]>x)return find(x,l,mid-1); else return find(x,mid+1,r);} 阅读全文
posted @ 2014-02-08 21:00 forever97 阅读(306) 评论(0) 推荐(0) 编辑
摘要: freopen("demo.in","r",stdin); freopen("demo.out","w",stdout);fclose(stdin); fclose(stdout); 阅读全文
posted @ 2014-02-08 20:58 forever97 阅读(121) 评论(0) 推荐(0) 编辑
摘要: void qsort(int l,int r){ int i,j,t,mid; mid=b[(l+r)>>1]; i=l; j=r; do{ while (b[i]mid) j--; if (i<=j) { t=b[i]; ... 阅读全文
posted @ 2014-02-08 20:55 forever97 阅读(267) 评论(0) 推荐(0) 编辑
摘要: int scan(int &x){ while(c=getchar(),c'9');x=c-'0'; while(c=getchar(),c>='0'&&c<='9')x=x*10+c-'0';} 阅读全文
posted @ 2014-02-08 20:54 forever97 阅读(517) 评论(0) 推荐(0) 编辑
上一页 1 ··· 28 29 30 31 32 33 34 35 36 ··· 38 下一页