• <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 2492 A Bug's Life 并查集

            思路:

            這題的背景是亮點,描述如下:
            Background 
            Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender. In his experiment, individual bugs and their interactions were easy to identify, because numbers were printed on their backs.
            Problem 
            Given a list of bug interactions, decide whether the experiment supports his assumption of two genders with no homosexual bugs or if it contains some bug interactions that falsify it.

            Hopper 在研究某種稀有蟲子的性行為。他假設蟲子們有兩種不同的性別,而且它們只跟異性發生關系。
            在他的試驗里,每個蟲子和它的性行為都很容易辨認,因為它們的背后印著號碼。
            給出一些蟲子的性行為,確定是否有同性戀的蟲子能推翻這個假設。

            同性戀確實讓人無法接受,無論是人還是蟲子。。

            這題的解法不是亮點,就是普通的并查集,數據量非常龐大,需要路徑壓縮。

            #include <stdio.h>
            #include 
            <string.h>

            int N, T, set[2048], val[2048];

            inline 
            int find(int idx)
            {
                
            static int stk[2048], i;

                
            for (i = 0set[idx]; i++{
                    stk[i] 
            = idx;
                    idx 
            = set[idx];
                }

                
            for (i--; i >= 0; i--{
                    val[stk[i]] 
            ^= val[set[stk[i]]];
                    
            set[stk[i]] = idx;
                }


                
            return idx;
            }


            int main()
            {
                
            int i, j, a, b, t, m, r;

                scanf(
            "%d"&T);
                
            for (t = 1; t <= T; t++{
                    scanf(
            "%d%d"&N, &m);
                    memset(
            set0, (N + 1* 4);
                    memset(val, 
            0, (N + 1* 4);
                    r 
            = 0;
                    
            while (m--{
                        scanf(
            "%d%d"&a, &b);
                        i 
            = find(a);
                        j 
            = find(b);
                        
            if (i == j) 
                            r 
            |= val[a] == val[b];
                        
            else {
                            
            set[i] = b;
                            val[i] 
            = !val[a];
                        }

                    }

                    printf(
            "Scenario #%d:\n%s\n\n"
                            t,
                            r 
            ? "Suspicious bugs found!" : "No suspicious bugs found!"
                            );
                }


                
            return 0;
            }

            posted @ 2010-04-17 20:57 糯米 閱讀(747) | 評論 (0)編輯 收藏

            POJ 1324 Holedox Moving 貪食蛇

                 摘要: 思路:繼推箱子以后,又發現POJ上有這類題目,哈哈。這次是給出一條貪食蛇當前的狀態、墻的位置、食物的位置。求吃到食物需要走的最小的步數。這類題目是相當牛逼的!高手的速度可以做到很BT的。在 status 上面就看到有 0ms 的!相當震驚,如此龐大的數據量能做到 0ms,肯定是神牛!后來搜了一下,還找到了那位神牛的博客,看了一下,發現看不大懂,杯具。。哪一天有空,一定會再想一下這道題的。一開始想了...  閱讀全文

            posted @ 2010-04-17 20:47 糯米 閱讀(748) | 評論 (0)編輯 收藏

            POJ 2437 Muddy roads 貪心

            思路:

            四個字:能放就放。。

            #include <stdio.h>
            #include 
            <stdlib.h>

            int arr[10032][2], N, L, ans;

            int cmp(const void *a, const void *b)
            {
                
            return *(int *)a - *(int *)b;
            }


            inline 
            int max(int a, int b)
            {
                
            return a > b ? a : b;
            }


            int main()
            {
                
            int i, p, c;

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

                scanf(
            "%d%d"&N, &L);
                
            for (i = 0; i < N; i++)
                    scanf(
            "%d%d"&arr[i][0], &arr[i][1]);
                qsort(arr, N, 
            sizeof(arr[0]), cmp);

                
            for (i = p = 0; p < N; ) {
                    i 
            = max(i, arr[p][0]);
                    c 
            = (arr[p][1- i + L - 1/ L;
                    i 
            += c * L;
                    ans 
            += c;
                    
            while (p < N && i >= arr[p][1])
                        p
            ++;
                }


                printf(
            "%d\n", ans);

                
            return 0;
            }

            posted @ 2010-04-17 20:27 糯米 閱讀(366) | 評論 (0)編輯 收藏

            POJ 2436 Disease Management 排列組合

                 摘要: 思路:這題沒有啥好的方法了,看來。用組合C(K, D)枚舉所有可能的疾病集合。其實復雜度很高的,C(15, 7) 都不知道多大了。但是數據比較弱。用別人的代碼試了一下,用STL里面的全排列生成函數,都可以 60ms AC。下面的代碼,沒有用STL里面的函數,我以為會快一點,結果慢了不少,200+ms。。原理就是把16位分成2個8位來處理。#include <stdio.h>...  閱讀全文

            posted @ 2010-04-17 20:24 糯米 閱讀(544) | 評論 (0)編輯 收藏

            POJ 2434 Waves 模擬

                 摘要: 思路:每個石頭可以分為兩個波,一個高峰波,一個低谷波。每個波可以分為很多個水平方向的波。每個水平方向的波有三種情況,起始點的位置:1. 位于 B1 左邊2. 位于 B1,B2 中間3. 位于 B2 右邊其中第2種情況有點麻煩,多次往返的話要一次算完。代碼:#include <stdio.h>#include <string.h>int P,&...  閱讀全文

            posted @ 2010-04-14 16:57 糯米 閱讀(443) | 評論 (0)編輯 收藏

            POJ 2431 Expedition 貪心+堆

            思路:

            有油的時候能走多遠就走多遠,看能否走到目的地。
            如果走不到,就必須要加一次油,途中會遇到很多加油站,一定要選油最多的那個。
            這很容易理解,因為如果你只加這一次,越多當然越好。如果要以后還要加,那能走遠一點選擇也多一點。

            重復這樣的過程就可以求解了。可以用堆維護加油站中的油量。

            杯具:稍稍修改了一下堆的寫法,結果WA兩次。。

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

            #define MAX_N 10032

            struct node {
                
            int x, f;
            }
            ;

            struct node stop[MAX_N];
            int N, L, P;
            int heap[MAX_N], heap_size;

            inline 
            void shift_up(int idx)
            {
                
            int val = heap[idx];
                
            while (idx > 1 && heap[idx/2< val) {
                    heap[idx] 
            = heap[idx/2];
                    idx 
            /= 2;
                }

                heap[idx] 
            = val;
            }


            inline 
            void shift_down(int idx)
            {
                
            int val = heap[idx];
                
            while (1{
                    idx 
            *= 2;
                    
            if (idx > heap_size)
                        
            break;
                    
            if (idx + 1 <= heap_size && heap[idx + 1> heap[idx])
                        idx
            ++;
                    
            if (val >= heap[idx])
                        
            break;
                    heap[idx
            /2= heap[idx];
                }

                heap[idx
            /2= val;
            }


            int cmp(const void *a, const void *b)
            {
                
            return ((struct node *)b)->- ((struct node *)a)->x;
            }


            inline 
            void push(int val)
            {
                heap[
            ++heap_size] = val;
                shift_up(heap_size);
            }


            inline 
            void pop()
            {
                heap[
            1= heap[heap_size--];
                shift_down(
            1);
            }


            int main()
            {
                
            int i, x, t;

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

                scanf(
            "%d"&N);
                
            for (i = 0; i < N; i++)
                    scanf(
            "%d%d"&stop[i].x, &stop[i].f);
                scanf(
            "%d%d"&L, &P);
                qsort(stop, N, 
            sizeof(stop[0]), cmp);

                push(P);
                x 
            = L;
                i 
            = 0;
                
            for (t = 0; heap_size && x > 0; t++{
                    x 
            -= heap[1];
                    pop();
                    
            while (i < N && x <= stop[i].x)
                        push(stop[i
            ++].f);
                }

                printf(
            "%d\n", x <= 0 ? t - 1 : -1);

                
            return 0;
            }



            posted @ 2010-04-13 13:53 糯米 閱讀(603) | 評論 (0)編輯 收藏

            POJ 3040 Allowance 貪心

            思路:

            每次放錢的時候,遵循兩個原則來尋找最優方案:
            1. 不能用面額小的組成面額大的
            2. 所有方案中取最接近 C 的那個
            就這樣一次次的放,放到沒錢為止。

            注意,由于貨幣的數量較大,如果最優方案可以執行多次,那就一次過執行完。

            #include <stdio.h>
            #include 
            <stdlib.h>

            #define MAX_N 64

            struct node {
                
            int val, cnt;
            }
            ;
            struct node coin[MAX_N];
            int N, C, best, best_idx, ans, need[MAX_N];

            inline 
            int min(int a, int b)
            {
                
            return a < b ? a : b;
            }


            int cmp(const void *a, const void *b)
            {
                
            return ((struct node *)a)->val - ((struct node *)b)->val;
            }


            inline 
            int put(int idx, int val)
            {
                
            int n;

                n 
            = min(coin[idx].cnt, (C - val - 1/ coin[idx].val);
                val 
            += coin[idx].val * n;
                
            if (coin[idx].cnt > n) {
                    
            if (!best || val + coin[idx].val < best) {
                        best 
            = val + coin[idx].val;
                        best_idx 
            = idx;
                    }

                }
             
                need[idx] 
            = n;

                
            return val;
            }


            inline 
            int can()
            {
                
            int i, val;

                best 
            = val = 0;
                
            for (i = N - 1; i >= 0; i--)
                    val 
            = put(i, val);

                
            return best;
            }


            inline 
            void update()
            {
                
            int i, cnt;

                cnt 
            = 100000000;
                need[best_idx]
            ++;
                
            for (i = N - 1; i >= best_idx; i--)
                    
            if (need[i])
                        cnt 
            = min(cnt, coin[i].cnt / need[i]);
                
            for (i = N - 1; i >= best_idx; i--
                    coin[i].cnt 
            -= cnt * need[i];
                ans 
            += cnt;
            }


            int main()
            {
                
            int i;

                scanf(
            "%d%d"&N, &C);
                
            for (i = 0; i < N; i++
                    scanf(
            "%d%d"&coin[i].val, &coin[i].cnt);
                qsort(coin, N, 
            sizeof(coin[0]), cmp);
                
                
            while (coin[N - 1].val >= C) {
                    ans 
            += coin[N - 1].cnt;
                    N
            --;
                }

                
            while (can())
                    update();
                
                printf(
            "%d\n", ans);

                
            return 0;
            }

            posted @ 2010-04-13 12:25 糯米 閱讀(558) | 評論 (0)編輯 收藏

            POJ 2430 Lazy Cows 動態規劃

                 摘要: 屬于狀態型的動態規劃,特難搞的那一類,狀態一多,轉換的時候難免遺漏一兩個。這題還算,借助數據搞出來了,漏了兩個轉移,結果一組數據過不了。后來加上就AC了,時間還行,32MS。思路:從左往右開始放矩形,假設現在準備擺放第i列之后的矩形。實際上我們只關注第i-1列是怎么擺的,前面怎么擺都無所謂。所以,第i列牛的狀態 + 第i-1列擺放的狀態 -> 第i列擺放的狀態擺放的狀態有五種:1. 光上面有...  閱讀全文

            posted @ 2010-04-13 12:19 糯米 閱讀(1000) | 評論 (0)編輯 收藏

            POJ 3047 Bovine Birthday 算日期

            看到這道題,忽然想到,這就是大一時候C++考試的最后一題啊!
            叫寫一個程序,計算今天是星期幾。
            那時候記得寫滿了半張卷子。。八成還沒寫對。
            不過今天,只用了5行!
            我感到很由衷的高興,面包會有的,牛奶會有的,腦殘只是暫時的!

            #include <stdio.h>

            int days[] = {
                
            0,
                
            315990120,
                
            151181212243,
                
            273304334365
            }
            ;

            char *weeks[] = {
                
            "monday""tuesday""wednesday"
                
            "thursday""friday""saturday"
                
            "sunday"
            }
            ;

            int main()
            {
                
            int y, m, d, w;

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

                scanf(
            "%d%d%d"&y, &m, &d);
                d 
            += (y - 1799)*365 - 1;
                
            if (m <= 2)
                    y
            --;
                d 
            += (y/4 - 449- (y/100 - 17+ y/400 - 4 + days[m - 1];
                w 
            = (d + 1% 7;
                printf(
            "%s\n", weeks[w]);

                
            return 0;
            }

            posted @ 2010-04-12 16:51 糯米 閱讀(314) | 評論 (0)編輯 收藏

            POJ 3039 Skiing 單源最短路徑

            這題看起來很屌。
            但是實際上走到每個點之后,速度必然是當前點和左上角點的差值的倒數。
            所以,每個點到其他點的所花費的時間都是這個點自己的值決定的。
            而且沒可能經過一個點兩次的,因為經過兩次肯定是浪費時間的。
            問題就變成了求最短路徑。

            注意:
            這題的精度很莫名其妙,用C++可以AC的,G++、GCC都是WA。
            不能用整數來保存時間,雖然看上去位數是夠用的,但是遇到比較屌的數據就掛了。
            就在這個問題上杯具了很久。

            #include <stdio.h>
            #include 
            <math.h>

            #ifndef _countof
            #define _countof(x) (sizeof(x)/sizeof(x[0]))
            #endif

            #define SIZE 128

            int map[SIZE][SIZE], R, C, V;
            double D[SIZE][SIZE], _tbl[128], *tbl = &_tbl[64];
            int queue[65536][2], head, tail;
            int vis[SIZE][SIZE];

            inline 
            void push(int y, int x, double d)
            {
                
            if (y < 0 || y >= R || x < 0 || x >= C)
                    
            return ;
                
            if (d > D[y][x])
                    
            return ;
                D[y][x] 
            = d;
                
            if (vis[y][x])
                    
            return ;
                vis[y][x] 
            = 1;
                queue[tail][
            0= y;
                queue[tail][
            1= x;
                tail
            ++;
                tail 
            &= _countof(queue) - 1;
            }


            inline 
            void pop(int *y, int *x)
            {
                
            *= queue[head][0];
                
            *= queue[head][1];
                head
            ++;
                head 
            &= _countof(queue) - 1;
                vis[
            *y][*x] = 0;
            }


            int main()
            {
                
            int i, j;
                
            double d;

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

                
            for (i = -64; i <= 64; i++)
                    tbl[i] 
            = pow(2.0, i);

                scanf(
            "%d%d%d"&V, &R, &C);
                
            for (i = 0; i < R; i++{
                    
            for (j = 0; j < C; j++{
                        scanf(
            "%d"&map[i][j]);
                        
            if (i || j)
                            map[i][j] 
            -= map[0][0];
                        D[i][j] 
            = 1e80;
                    }

                }

                map[
            0][0= 0;

                push(
            000); 
                
            while (head != tail) {
                    pop(
            &i, &j);
                    d 
            = D[i][j] + tbl[map[i][j]];
                    push(i 
            + 1, j, d);
                    push(i 
            - 1, j, d);
                    push(i, j 
            + 1, d);
                    push(i, j 
            - 1, d);
                }


                printf(
            "%.2lf\n", D[R - 1][C - 1/ V);
                
                
            return 0;
            }

            posted @ 2010-04-12 16:45 糯米 閱讀(475) | 評論 (0)編輯 收藏

            僅列出標題
            共17頁: First 5 6 7 8 9 10 11 12 13 Last 
            色婷婷久久综合中文久久蜜桃av| 成人国内精品久久久久一区| 久久亚洲中文字幕精品一区四| 国内精品久久久久久久coent| 久久天天躁狠狠躁夜夜2020| 国产亚洲精品久久久久秋霞| 久久成人精品视频| 亚洲а∨天堂久久精品| 麻豆亚洲AV永久无码精品久久| 成人亚洲欧美久久久久| 97久久婷婷五月综合色d啪蜜芽| 国内精品久久久人妻中文字幕| 国产精品亚洲美女久久久| 中文字幕久久精品无码| 久久播电影网| 日韩精品国产自在久久现线拍| 亚洲国产视频久久| 精品99久久aaa一级毛片| 久久人爽人人爽人人片AV | 久久免费小视频| 亚洲精品无码久久久| 一本色道久久88加勒比—综合| 久久精品人妻中文系列| 久久精品亚洲福利| 国产精品久久久久久久午夜片| 久久人人爽爽爽人久久久| 国色天香久久久久久久小说| 欧美一级久久久久久久大片| 97超级碰碰碰碰久久久久| 久久免费线看线看| 久久精品国产一区| 91视频国产91久久久| 91精品国产综合久久久久久| 色妞色综合久久夜夜| 亚洲国产精品久久久天堂| 久久久久99这里有精品10 | 久久精品国产99久久久香蕉| 久久久久国产精品| 久久精品国产91久久综合麻豆自制 | 99久久精品国产一区二区三区| 激情伊人五月天久久综合|