简单搜索入门

    xiaoxiao2025-06-27  11

    点击打开链接

    hdu 2181 哈密顿绕行世界问题

     

    #include <iostream> #include <stdio.h> #include <string.h> #include <queue> #include <string> #include <map> #define Y 0x3f3f3f3f using namespace std; int m,mapp[25][3],mark[25],l,p[25],cas=1; void dfs(int m,int len,int c) { int i,j; mark[m]=1; p[len]=m; for(i=0;i<3;i++) { int t=mapp[m][i]; if(t==c&&len==19) { printf("%d: ",cas++); for(j=0;j<20; j++) printf("%d ",p[j]); printf("%d\n",c); } if(!mark[t]) dfs(t,len+1,c); } mark[m] = 0; ///记得 } int main() { int i,a,b,c; for(i=1;i<=20;i++){ scanf("%d %d %d",&a,&b,&c); mapp[i][0]=a,mapp[i][1]=b,mapp[i][2]=c; } while(scanf("%d",&m)&&m){ memset(mark,0,sizeof(mark)); l=0; dfs(m,0,m); } return 0; }

    hdu 2212 DFS (打表题)

     

     

    #include <iostream> #include <stdio.h> #include <string.h> #include <queue> #include <string> #include <map> using namespace std; int main() { printf("1\n2\n145\n40585\n"); return 0; }

    poj 3278 cacth the cow

     

     

    #include <iostream> #include <stdio.h> #include <string.h> #include <queue> #include <string> #include <map> #define Y 0x3f3f3f3f using namespace std; int n,m,mark[100005]; struct node { int x,step; }u,v; void bfs(){ queue<node>q; u.x=n,u.step=0,mark[n]=0; q.push(u); while(!q.empty()){ u=q.front(),q.pop(); if(u.x==m){ printf("%d\n",u.step); return ; } v.x=u.x+1;//向前一步 if(v.x>=0&&v.x<=100000&&mark[v.x]==0) mark[v.x]=1,v.step=u.step+1,q.push(v); v.x=u.x-1;//退后y一步 if(v.x>=0&&v.x<=100000&&mark[v.x]==0) mark[v.x]=1,v.step=u.step+1,q.push(v); v.x=u.x*2;//向前两步 if(v.x>=0&&v.x<=100000&&mark[v.x]==0) mark[v.x]=1,v.step=u.step+1,q.push(v); } } int main() { scanf("%d %d",&n,&m); bfs(); return 0; }

    hdu 2072 单词数

     

     

    #include <iostream> #include <stdio.h> #include <string.h> #include <queue> #include <string> #include <map> #define Y 0x3f3f3f3f using namespace std; char s[110]; int main() { int i,j; string s2; map<string,int>M; while(gets(s)){ M.clear();s2="";j=0; if(strcmp(s,"#")==0) break; s[strlen(s)]='\0'; for(i=0;i<=strlen(s);i++){ if((s[i]==' '||s[i]=='\0')&&s2!=""){ M[s2]++; s2=""; } if(s[i]!=' '&&s[i]!='\0') s2+=s[i]; } printf("%d\n",M.size()); } return 0; }

     

     

     

     

     

    转载请注明原文地址: https://ju.6miu.com/read-1300369.html
    最新回复(0)