hdu 1880 魔咒詞典

2022-08-03 14:03:22 字數 2375 閱讀 2547

哈利波特在魔法學校的必修課之一就是學習魔咒。據說魔法世界有100000種不同的魔咒,哈利很難全部記住,但是為了對抗強敵,他必須在危急時刻能夠呼叫任何乙個需要的魔咒,所以他需要你的幫助。

給你一部魔咒詞典。當哈利聽到乙個魔咒時,你的程式必須告訴他那個魔咒的功能;當哈利需要某個功能但不知道該用什麼魔咒時,你的程式要替他找到相應的魔咒。如果他要的魔咒不在詞典中,就輸出「what?」

首先列出詞典中不超過100000條不同的魔咒詞條,每條格式為:

[魔咒] 對應功能

其中「魔咒」和「對應功能」分別為長度不超過20和80的字串,字串中保證不包含字元「[」和「]」,且「]」和後面的字串之間有且僅有乙個空格。詞典最後一行以「@end@」結束,這一行不屬於詞典中的詞條。

詞典之後的一行包含正整數n(<=1000),隨後是n個測試用例。每個測試用例佔一行,或者給出「[魔咒]」,或者給出「對應功能」。

每個測試用例的輸出佔一行,輸出魔咒對應的功能,或者功能對應的魔咒。如果魔咒不在詞典中,就輸出「what?」

[expelliarmus] the disarming charm

[rictusempra] send a jet of silver light to hit the enemy

[tarantallegra] control the movement of one's legs

[serpensortia] shoot a snake out of the end of one's wand

[lumos] light the wand

[obliviate] the memory charm

[expecto patronum] send a patronus to the dementors

[accio] the summoning charm

@end@

4[lumos]

the summoning charm

[arha]

take me to the sky

light the wand

accio

what?

what?

開始用的mp, mle了然後寫了個雜湊太挫了 掩面(*/ω╲*)。。

#include#include#include#include#include#include#includeusing std::abs;

using std::sort;

using std::pair;

using std::swap;

using std::vector;

using std::multimap;

#define pb(e) push_back(e)

#define sz(c) (int)(c).size()

#define mp(a, b) make_pair(a, b)

#define all(c) (c).begin(), (c).end()

#define iter(c) decltype((c).begin())

#define cls(arr, val) memset(arr, val, sizeof(arr))

#define cpresent(c, e) (find(all(c), (e)) != (c).end())

#define rep(i, n) for(int i = 0; i < (int)n; i++)

#define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)

const int n = 100077;

const int inf = 0x3f3f3f3f;

typedef unsigned long long ull;

struct hash_set g_1[n], g_2[n];

int tot_1, tot_2, head_1[n], head_2[n];

inline void init()

inline int hash_func(char *s)

return val;

}inline void insert_1(char *p, char *p1)

inline void insert_2(char *p, char *p1)

inline char *find_1(char *p)

return null;

}inline char *find_2(char *p)

return null;

}}hash;

int main()

scanf("%d", &n);

getchar();

while (n--) else

}return 0;

}

hdu1880(魔咒詞典)

1.下面是二分查詢 ac include include include define max 100005 typedef struct node node node mag1 max node mag2 max int cmp1 const void a,const void b int cmp...

魔咒詞典 HDU 1880

感覺這題巨毒瘤,讀入字串方面調了好久才避免了讀入空白字元。思路就是對每條資訊的魔咒和功能的記錄在s1和s2串裡,並在ihash陣列裡通過資訊的編號 cnt 確定存放的列,將魔咒 魔咒的hash值存在第一行 或功能 功能的hash值存在第2行 的hash值存入。然後輸入乙個要查詢的字串,就先求出其ha...

HDU 1880魔咒詞典

problem description 哈利波特在魔法學校的必修課之一就是學習魔咒。據說魔法世界有100000種不同的魔咒,哈利很難全部記住,但是為了對抗強敵,他必須在危急時刻能夠呼叫任何乙個需要的魔咒,所以他需要你的幫助。給你一部魔咒詞典。當哈利聽到乙個魔咒時,你的程式必須告訴他那個魔咒的功能 當...