首页 > 代码库 > HDU2095find your present (2)【hash】
HDU2095find your present (2)【hash】
水题==
代码:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int mod = 10005;struct Node { int to, next;}e[1000005];int head[mod + 10];int tot;int a[1000005];void add(int p, int num) { e[tot].to = num; e[tot].next = head[p]; head[p] = tot++;}bool check(int num) { int p = num % mod; int cnt = 0; for(int i = head[p]; i; i = e[i].next) { if(e[i].to == num) { cnt++; if(cnt >= 2) { return false; } } } return true;}int main() { int n; while(scanf("%d",&n) && n) { memset(head, 0, sizeof(head)); tot = 1; for(int i = 1; i <= n; i++) { scanf("%d",&a[i]); add(a[i] % mod, a[i]); } for(int i = 1; i <= n; i++) { if(check(a[i])) { printf("%d\n", a[i]); break; } } } return 0;}
HDU2095find your present (2)【hash】
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。