bfs(优先队列)
。
infinity°º
stay hungry stay foolish
展开
-
hdu2527(哈夫曼编码长度+优先队列bfs)
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; using namespace std; string s; int n,ans,num[30]; void bfs(){ int a,b; priority_queue<int,vector<int>,greater<int> > q; for(int i=0;i<26;i++){ if(num[i]!=0) q.push(num.原创 2021-05-10 20:12:16 · 103 阅读 · 0 评论 -
hdu1053最佳编码(哈夫曼编码长度+优先队列bfs)
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; using namespace std; string s; int ans,num[50]; void bfs(){ int a,b; priority_queue<int,vector<int>,greater<int> > q;//为了与>>区分 最后要有个空格 for(int i=0;i<=36;i++){ if(n.原创 2021-05-10 20:03:23 · 210 阅读 · 0 评论 -
2021-07-14洛谷lucky numbers
#include<bits/stdc++.h> using namespace std; const int maxn=1e6; long long n,q[maxn]; int check(long long x){ int a=0,b=0;long long y; if(x<n) return 0; while(x){ y=x%10; x=x/10; if(y==4) a++; else b++; } return a==b ; } int main(){ .原创 2021-07-14 14:56:47 · 120 阅读 · 0 评论 -
hdu1253
#include<bits/stdc++.h> using namespace std; int a,b,c,T,vis[55][55][55]; int dir[6][3]={1,0,0,0,1,0,-1,0,0,0,-1,0,0,0,1,0,0,-1}; int g[55][55][55]; struct ss{ int x,y,z,step; }; int check(int x,int y,int z){ if(x>=0&&x<a&&y.原创 2021-07-14 11:26:06 · 57 阅读 · 0 评论 -
hdu1242优先队列
#include<bits/stdc++.h> using namespace std; int n,m,vis[205][205],sx,sy,ex,ey; int dir[4][2]={1,0,0,1,-1,0,0,-1}; char g[205][205]; struct ss{ int x,y,step; //友缘关系运算符 重载< friend bool operator < (ss a,ss b){ return a.step>b.step; }.原创 2021-07-14 11:03:22 · 102 阅读 · 0 评论 -
hdu1372
#include<bits/stdc++.h>//国际象棋(骑士)只走斜对角线(1*2) using namespace std; int vis[10][10]; int dir[8][2]={2,1,1,2,-1,2,-2,1,-1,-2,-2,-1,1,-2,2,-1}; //!!!八个方位,2位分别存的xy struct ss{ int step; int x,y; }; char a[3],b[3];//%s还要留一位给\0!! int sx,sy,ex,ey; int ch.原创 2021-07-13 20:45:36 · 56 阅读 · 0 评论 -
hdu1495
#include<bits/stdc++.h> using namespace std; const int maxn=107; int v[3],s[3],vis[maxn][maxn][maxn];//vis看这个状态遇到过没 struct ss{ int step; int s[3]; }; //check是在while里for外面 int check(int x,int y,int z){ if(x==y&&z==0||x==z&&y==0||.原创 2021-07-13 19:49:54 · 70 阅读 · 0 评论 -
hdu1548
#include<bits/stdc++.h> using namespace std; const int maxn=205; const int inf=0x3f3f3f3f; int a[maxn],vis[maxn],n,s,t; struct ss{ int step,x; }; void bfs(){ queue<ss> q; ss cur,nex; cur.x=s; cur.step=0; q.push(cur); vis[s]=0; while(!q.原创 2021-05-18 22:24:46 · 47 阅读 · 0 评论