EOJ 2794 鍊錶

2021-06-19 05:21:12 字數 1063 閱讀 9506

大概是在10000*10的矩陣裡找兩行,兩列,使得兩行中的對應列是相同的。

思路:在長列中hash,建立hash陣列,表示這個hash[i]的i前乙個位置,建立鍊錶next[i] 指向hash[value[i]],這樣就能o(n)的找到所有相同的數的乙個鍊錶。

然後搜尋兩列的時候比較當前指向的位置,當前比較短的跳轉。

#include #include #include #include #include #include #include #include #include #include #include using namespace std;

typedef long long ll;

#define debug(x) (cerr << #x << " = " << (x) << endl)

#define debug2(x, y) (cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl)

templateinline t& rd(t &x)

const int inf = 0x3f3f3f3f;

const int maxn = 10005;

mapmymap;

int mat[maxn][11];

int vis[maxn*11];

int next[maxn][11];

void solve(int n, int m)

else if(next[i1][j] == next[i2][k])

else }}

} }printf("yes\n");

} int main(){

string str;

int n,m;

char ch;

//freopen("in","r",stdin);

while(~scanf("%d%d",&n,&m)){

mymap.clear();

ch = getchar();

str = "";

int tot = 1;

for(int i=0;i

鍊錶 環形鍊錶

環形鍊錶也叫迴圈鍊錶 可以是雙鏈表 也可以是單鏈表 操作原理和單鏈表差不多,只是最後乙個節點不在指向空 null 而是頭 head 這裡以單鏈表舉例 description 環形鍊錶 author lzq date 2018 11 3 20 46 version 1.0 public class a...

鍊錶 初識鍊錶

鍊錶 前言 小弟初學資料結構,有錯誤的地方望大家不吝賜教 認識鍊錶 列表相比陣列更具有優勢,鍊錶不同於資料和其他資料結構依靠位置來進行訪問或者其他操作,如陣列是依靠下表來運算元據。而鍊錶是通過關係來尋找或者運算元據。鍊錶的特性 插入 和 刪除 效率高,只需要變更指向的鏈結點即可。但是隨即訪問操作的效...

鍊錶(鍊錶建立)

先找到了一些與單鏈表相關的概念 2.指標域 ai元素儲存指向後繼元素儲存位置的資訊 3.結點 包含資料域和指標域 4.單鏈表 每個結點只包含乙個指標域的線性表 5.頭指標 要素 鍊錶中第乙個結點的儲存位置 線性表最後乙個結點指標為空 6.頭結點 非要素 單鏈表第乙個結點前附設乙個結點 其指標域指向第...