多校第10場01,雙向bfs

2022-08-15 06:27:14 字數 2682 閱讀 9222

雙向dfs也可以過,程式設計複雜度低一些,不過會剛剛好跑複雜度上限,慢了不少

時間差的還挺多的

dfs的時候剪枝都不能有,會蜜汁wa,丟掉就過了

dfs

#include 

#include

#include

#include

#include

using

namespace

std;

typedef

unsigned

long

long ll;

const

int n = 9;

const

int dx = ;

const

int dy = ;

const

int maxstep = 10;

int ans;

ll po[9][9];

ll power(int a, int x)

return ans;

}void initpower(int a, int b)

int g[9][9];

struct ha

ha(int a[n][n], int x, int s)

};map

hash;

int h = 0, v;

ll hashmove(ll hashnum, int x, int y, int cx, int cy)

void initdfs(int x, int y, ll hashnum, int step)

}inline

void init()

}hash.clear();

initdfs(1, 1, hashnum, 0);

}void dfs(int x, int y, ll hashnum, int step)

if (step > maxstep) return;

for (int i = 0; i < 4; i++)

}//inline void bfs(int sx, int sy, )

int main()}}

ans = 33; v = 0;

dfs(sx, sy, hashnum, 0);

//bfs(sx, sy, hashnum);

if (ans <= 20) printf("%d\n", ans);

else

puts("too difficult");

}return

0;}

bfs

#include 

#include

#include

#include

#include

#include

using

namespace

std;

typedef

unsigned

long

long ll;

const

int n = 9;

const

int dx = ;

const

int dy = ;

const

int maxstep = 10;

ll po[9][9];

ll power(int a, int x)

return ans;

}void initpower(int a, int b)

int g[9][9];

struct ha

ha(int a[n][n], int _x, int _y, int s, ll h)

void print()

};map

hash;

mapint> vis;

int v;

ll hashmove(ll hashnum, int x, int y, int cx, int cy)

void initbfs(ll hashnum)

}}inline

void init()

}initbfs(hashnum);

}int bfs(int sx, int sy, ll hashnum)

if (step > maxstep) return

22; hashnum = h.hashnum;

if (vis.find(hashnum) != vis.end()) continue;

vis[hashnum] = ++v;

if (hash.find(hashnum) != hash.end())

return step + hash[hashnum].step;

memcpy(g, h.g, sizeof(g));

for (int i = 0; i < 4; i++)

}return

22;}

int main()}}

int ans = bfs(sx, sy, hashnum);

if (ans <= 20) printf("%d\n", ans);

else

puts("too difficult");

}return

0;}

2016多校第10場

1001 media tag 二分 題意給你乙個排好的n個數,讓你求l1,r1,和 l2,r2這兩區間合併起來的中位數。分析 我們可以很容易將這個問題轉化為第k問題,因此我們二分這個數,假設他是第k大那麼小於等於它的數的數量肯定大於等於k。include include include using ...

多校第9場

這道題挺水,只是要耐心的打表,我一開始只打了一半就不想做了,也是因為我的方法太麻煩了,把x,y座標分開存,處理的資料量差不多增加了一倍。這題有一點注意 題目中並沒有限制字串的長度,所以char陣列盡量開大些。下面是賽後ac的 include include include include inclu...

多校第4場1012

理解題意以後會發現時比較簡單的線段樹,理解題意以後首先應該想到乙個貪心,就是再尋找最終答案的第i個數時,餓哦們要盡量使這個數盡可能大。那麼我們找 1,pos i 1 這個區間中已經組隊的位置的最大值,記為l,然後找 l 1pos i 1 之間未被找過的最大的數。這裡組隊的意思是可以詳見程式,並不是被...