HDU 2600 War 哈希

来源:互联网 发布:一致性hash算法原理 编辑:程序博客网 时间:2024/06/08 18:23

传送门:HDU 2600 War

注意:不能开int数组做hash,爆内存。要用bool 或是 char类型。

代码如下;

#include <stdio.h>#include <string.h>bool hash[12000005]; // 开 int 内存超限 bool 和  char 都只占1个字节   int 开 12000000的数组大小会到48MBint main() {    int cas,st,ed,i,j,s,t,flag;    char warN[101];    while(scanf("%d",&cas) != EOF) {        scanf("%d%d",&st,&ed);        st += 6000000;        ed += 6000000;        memset(hash, false, sizeof(hash));        for(i=0; i<cas; i++) {            scanf("%d%d%[^\n]",&s,&t,warN);            s += 6000000;            t += 6000000;            for(j=s; j<=t; j++)                hash[j] = true;        }        flag = 0;        for(i=ed; i>=st; i--) {            if(!hash[i]) {                printf("%d\n",i-6000000);                flag = 1;                break;            }        }        if(flag == 0)            printf("Badly!\n");    }    return 0;}
1 0
原创粉丝点击