TA的每日心情 | 慵懶 2015-4-10 14:18 |
---|
簽到天數: 78 天 [LV.6]常住居民II
管理員
- 積分
- 3959
|
趕快加入我們來參與討論吧!
您需要 登錄 才可以下載或查看,沒有帳號?加入我們
x
原題:http://zerojudge.tw/ShowProblem?problemid=a174
AC:http://zerojudge.tw/Submissions?problemid=a174&account=lfs92002
HASH Table的小練習~,就照題意模擬的簡單題
/**********************************************************************************/
/* Problem: a174 "上帝玩不玩骰子?" from Hash Table */
/* Language: CPP (1117 Bytes) */
/* Result: AC(0.4s, 524KB) judge by this@ZeroJudge */
/* Author: lfs92002 at 2013-03-20 11:44:18 */
/**********************************************************************************/
#include<cstdio>
#include<vector>
#include<algorithm>
#include<set>
#define hash(X) ((X)%M)
using namespace std;
vector<int>ht[200];
set<int>inp;
int main()
{
int K,M,i,j,t;
while(~scanf("%d%d",&K,&M))
{
for(int a=0;a<M;a++)ht[a].clear();
inp.clear();
while(K--)
{
scanf("%d",&t);
switch(t)
{
case 1:
scanf("%d",&i);
if(inp.find(i)==inp.end())
{
ht[hash(i)].push_back(i);
inp.insert(i);
}
break;
case 2:
scanf("%d",&i);
if(inp.find(i)!=inp.end())
{
inp.erase(i);
int d=0;
while(ht[hash(i)][d]!=i)d++;
while(d<ht[hash(i)].size()-1)ht[hash(i)][d]=ht[hash(i)][d+1],d++;
ht[hash(i)].resize(ht[hash(i)].size()-1);
}
break;
case 3:
puts("===== s =====");
for(i=0;i<M;i++)
{
printf("[%03d]:",i);
sort(ht[i].begin(),ht[i].end());
for(j=0;j<ht[i].size();j++)
{
printf("%d -> ",ht[i][j]);
}
printf("NULL\n");
}
puts("===== e =====");
break;
}
}
}
}
|
|