• <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>

            A Za, A Za, Fighting...

            堅信:勤能補拙

            PKU 1054 The Troublesome Frog

            問題:
            http://acm.pku.edu.cn/JudgeOnline/problem?id=1054

            思路:
            好題,枚舉 + 二分
            枚舉所有可能路徑的前兩個點
            要注意的是: starting outside the paddy on one side and ending outside the paddy on the other side

            代碼:
             1 /* enumerate the first two points for each possible path */
             2 #include<stdio.h>
             3 #include<stdlib.h>
             4 #include<string.h>
             5 #define MAX_NUM 5001
             6 #define is_valid(x, y) ((x)>0 && (x)<=R && (y)>0 && (y)<=C)
             7 int R, C;
             8 int total;
             9 struct Point {
            10     int x, y;
            11 } points[MAX_NUM];
            12 
            13 /* from top to down, and left to right */
            14 int
            15 compare(const void *arg1, const void *arg2)
            16 {
            17     struct Point *= (struct Point *)arg1;
            18     struct Point *= (struct Point *)arg2;
            19     if(a->== b->x)
            20         return a->- b->y;
            21     return a->- b->x;
            22 }
            23 
            24 void
            25 init()
            26 {
            27     int i;
            28     scanf("%d"&total);
            29     for(i=0; i<total; i++)
            30         scanf("%d %d"&points[i].x, &points[i].y);
            31     qsort(points, total, sizeof(struct Point), compare);
            32 }
            33 
            34 void
            35 solve()
            36 {
            37     int i, j, tmp, max = 0;
            38     int diff_x, diff_y;
            39     struct Point p1, p2, next;
            40     struct Point *ptr;
            41     for(i=0; i<total; i++) {
            42         for(j=i+1; j<total; j++) {
            43             tmp = 2;
            44             p1 = points[i];
            45             p2 = points[j];
            46             diff_x = p2.x - p1.x;
            47             diff_y = p2.y - p1.y;
            48             if(is_valid(p1.x-diff_x, p1.y-diff_y)) /* starting outside */
            49                 continue;
            50             if(!is_valid(p1.x+max*diff_x, p1.y+max*diff_y)) /* pruning */
            51                 continue;
            52             next.x = p2.x + diff_x;
            53             next.y = p2.y + diff_y;
            54             while(is_valid(next.x, next.y)) {
            55                 if((ptr=(struct Point *)bsearch(&next, points, total, sizeof(struct Point), compare)) == NULL) {
            56                     tmp = 0/* ending outside */
            57                     break;
            58                 }
            59                 ++tmp;
            60                 next.x += diff_x;
            61                 next.y += diff_y;
            62             }
            63             max = tmp>max ? tmp : max;
            64         }
            65     }
            66     printf("%d\n", max>2 ? max : 0);
            67 }
            68 
            69 int
            70 main(int argc, char **argv)
            71 {
            72     while(scanf("%d %d"&R, &C) != EOF) {
            73         init();
            74         solve();
            75     }
            76 }

            posted on 2010-09-07 17:18 simplyzhao 閱讀(207) 評論(0)  編輯 收藏 引用 所屬分類: G_其他

            導航

            <2010年9月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲综合精品香蕉久久网97| 久久99精品久久久久婷婷| 国产精品久久久久无码av| 中文字幕无码免费久久| 伊人久久大香线蕉综合网站| 亚洲欧洲精品成人久久奇米网| 亚洲中文字幕无码久久2020| 久久亚洲欧美日本精品| 婷婷久久综合| 色妞色综合久久夜夜| 国产精品久久久香蕉| 国产成人无码精品久久久性色| 久久久国产精品亚洲一区| 大香网伊人久久综合网2020| 久久亚洲精品无码aⅴ大香| 99久久99久久精品国产片果冻| 伊人色综合久久天天人守人婷| 久久久久久久人妻无码中文字幕爆| 久久99久久无码毛片一区二区| 亚洲国产精品18久久久久久| 国产A级毛片久久久精品毛片| 欧美熟妇另类久久久久久不卡 | 色偷偷88888欧美精品久久久| 久久r热这里有精品视频| 日韩精品久久无码中文字幕| 欧美与黑人午夜性猛交久久久 | 久久免费视频1| 久久久久一级精品亚洲国产成人综合AV区| A级毛片无码久久精品免费| 亚洲国产日韩综合久久精品| 99久久精品费精品国产| 亚洲国产成人久久综合碰碰动漫3d | AV无码久久久久不卡蜜桃| 日本五月天婷久久网站| 青青久久精品国产免费看| 国产成人无码精品久久久免费| 青青草国产成人久久91网| 国产99久久精品一区二区| 999久久久免费精品国产| 国产综合久久久久久鬼色| 97精品国产91久久久久久|