• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            糯米

            TI DaVinci, gstreamer, ffmpeg
            隨筆 - 167, 文章 - 0, 評論 - 47, 引用 - 0
            數據加載中……

            POJ 2009 Moo University - Emergency Pizza Order 無恥貪心解法

            這題能不能貪心,是很難說的。。
            因為沒有能什么證明貪心是對的,但也沒找到什么反例。
            代碼寫出來,WA了。
            但總覺得是對的,因為嗎的實在找不到反例。
            結果找到數據測了下,果然十個過了九個。。
            你看,如果這是NOIP,跟滿分都沒啥區別的對吧。我已經滿足了。。
            沒過的那組,比較大,肉眼看不出是啥問題。
            想了下,給排序加多了一個判斷,然后那組數據就過了。。
            然后提交,嗎的還上榜了。。無語。

            這樣做比較無恥,網上有人說用最大流做,不理解。下次想一想。

            思路:
            如果牛喜歡的種類個數小于 K,那這種牛是無法滿足的。。
            把牛按照喜歡的種類個數排序,先處理小的。
            就是用組合數枚舉每一種可能的 pizza 情況。
            用 hash 保存這些情況。

            代碼:
            #include <stdio.h>
            #include 
            <stdlib.h>

            #define HASH_SIZE 65536

            struct cow_node {
                
            int val, cnt;
            }
            ;

            int C, T, K, ans;
            struct cow_node cows[1024];
            int hash[HASH_SIZE];

            int cmp(const void *a, const void *b)
            {
                
            if (((struct cow_node *)a)->cnt == ((struct cow_node *)b)->cnt)
                    
            return ((struct cow_node *)a)->val - ((struct cow_node *)b)->val;
                
            return ((struct cow_node *)a)->cnt - ((struct cow_node *)b)->cnt;
            }


            inline 
            int insert(int val)
            {
                
            int i, h;

                h 
            = val & (HASH_SIZE - 1);
                
            for (i = h + 1; i != h && hash[i] && hash[i] != val; )
                    i 
            = (i + 1& (HASH_SIZE - 1);
                
            if (i == h || hash[i] == val)
                    
            return 0;
                hash[i] 
            = val;
                
            return 1;
            }


            inline 
            int calc(struct cow_node *t)
            {
                
            int arr[32], map[32], i, j, val;

                
            for (i = j = 0; i < 32; i++)
                    
            if (t->val & (1 << i))
                        map[j
            ++= (1 << i);
                
            for (i = 0; i < K; i++)
                    arr[i] 
            = i;
                
            while (1{
                    val 
            = 0;
                    
            for (i = 0; i < K; i++)
                        val 
            |= map[arr[i]];
                    
            if (insert(val))
                        
            return 1;
                    
            for (i = K - 1; i >= 0 && arr[i] == i + t->cnt - K; i--);
                    
            if (i < 0)
                        
            break;
                    arr[i]
            ++;
                    
            for (i++; i < K; i++)
                        arr[i] 
            = arr[i - 1+ 1;
                }


                
            return 0;
            }


            int main()
            {
                
            int i, j, k;

                freopen(
            "e:\\test\\in.txt""r", stdin);

                scanf(
            "%d%d%d"&C, &T, &K);
                
            for (i = 0; i < C; i++{
                    scanf(
            "%d"&cows[i].cnt);
                    cows[i].val 
            = 0;
                    
            for (j = 0; j < cows[i].cnt; j++{
                        scanf(
            "%d"&k);
                        k
            --;
                        cows[i].val 
            |= 1 << k;
                    }

                    
            if (cows[i].cnt < K) {
                        i
            --; C--;
                        
            continue;
                    }

                }

                qsort(cows, C, 
            sizeof(cows[0]), cmp);

                
            for (i = 0; i < C; i++
                    ans 
            += calc(&cows[i]);
                printf(
            "%d\n", ans);

                
            return 0;
            }


            posted on 2010-04-27 14:25 糯米 閱讀(818) 評論(0)  編輯 收藏 引用 所屬分類: POJ

            97久久国产综合精品女不卡| 亚洲AV无码久久| 色综合久久最新中文字幕| 岛国搬运www久久| 久久久国产视频| 久久66热人妻偷产精品9| 国产 亚洲 欧美 另类 久久| 中文字幕精品久久久久人妻| 久久精品亚洲一区二区三区浴池| 99久久精品国产综合一区| 伊人久久大香线蕉无码麻豆| 久久99国产精品久久| 久久久SS麻豆欧美国产日韩| 女人香蕉久久**毛片精品| av色综合久久天堂av色综合在| www亚洲欲色成人久久精品| 久久久无码一区二区三区| 亚洲精品综合久久| 久久久久国产一区二区三区| 99久久777色| 色欲久久久天天天综合网精品 | 亚洲国产精品18久久久久久| 精品综合久久久久久88小说| 精品无码久久久久国产| 亚洲中文字幕久久精品无码喷水| 久久男人中文字幕资源站| 久久99精品国产麻豆蜜芽| 66精品综合久久久久久久| 国产精品一区二区久久精品| 777午夜精品久久av蜜臀| 一本大道久久东京热无码AV| 久久久久一级精品亚洲国产成人综合AV区 | 精品久久久久久无码人妻蜜桃| 久久久久亚洲AV片无码下载蜜桃 | 97精品伊人久久大香线蕉| 久久夜色精品国产亚洲av| 蜜桃麻豆www久久国产精品| 久久久久久青草大香综合精品| 久久影院午夜理论片无码| 久久久久黑人强伦姧人妻| 日本加勒比久久精品|