查看: 1583|回復: 0
打印 上一主題 下一主題

[ZJ] a174 - 上帝玩不玩骰子?

[複製鏈接]
  • TA的每日心情
    慵懶
    2015-4-10 14:18
  • 簽到天數: 78 天

    [LV.6]常住居民II

    176

    主題

    612

    帖子

    3959

    積分

    管理員

    Rank: 9Rank: 9Rank: 9

    積分
    3959

    台南一中資訊社新手達陣程式設計達人 - 2014

    跳轉到指定樓層
    樓主
    發表於 2014-5-6 13:12:42 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式

    趕快加入我們來參與討論吧!

    您需要 登錄 才可以下載或查看,沒有帳號?加入我們

    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;
                }
                
            }
        }
    }


    回復

    使用道具 檢舉

    您需要登錄後才可以回帖 登入 | 加入我們

    本版積分規則

    快速回覆 返回頂部 返回列表