青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

ACM___________________________

______________白白の屋
posts - 182, comments - 102, trackbacks - 0, articles - 0
<2010年10月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

常用鏈接

留言簿(24)

隨筆分類(332)

隨筆檔案(182)

FRIENDS

搜索

積分與排名

最新隨筆

最新評論

閱讀排行榜

評論排行榜

MiYu原創, 轉帖請注明 : 轉載自 ______________白白の屋    

 

題目地址:

http://acm.hdu.edu.cn/showproblem.php?pid=1512

題目描述 :

代碼
Monkey King

Time Limit: 
10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 
914    Accepted Submission(s): 426


Problem Description
Once 
in a forest, there lived N aggressive monkeys. At the beginning, they each does things in its own way and none of them knows each other. But monkeys can't avoid quarrelling, and it only happens between two monkeys who does not know each other. And when it happens, both the two monkeys will invite the strongest friend of them, and duel. Of course, after the duel, the two monkeys and all of there friends knows each other, and the quarrel above will no longer happens between these monkeys even if they have ever conflicted.

Assume that every money has a strongness value, which will be reduced to only half of the original after a duel(that 
is10 will be reduced to 5 and 5 will be reduced to 2).

And we also assume that every monkey knows himself. That 
is, when he is the strongest one in all of his friends, he himself will go to duel.
 

Input
There are several test cases, and each 
case consists of two parts.

First part: The first line contains an integer N(N
<=100,000), which indicates the number of monkeys. And then N lines follows. There is one number on each line, indicating the strongness value of ith monkey(<=32768).

Second part: The first line contains an integer M(M
<=100,000), which indicates there are M conflicts happened. And then M lines follows, each line of which contains two integers x and y, indicating that there is a conflict between the Xth monkey and Yth.

 

Output
For each of the conflict, output 
-1 if the two monkeys know each other, otherwise output the strongness value of the strongest monkey in all friends of them after the duel.
 

Sample Input
5
20
16
10
10
4
5
2 3
3 4
3 5
4 5
1 5
 

Sample Output
8
5
5
-1
10
 

 

 

題目分析:

/*
Mail to   : miyubai@gamil.com
My Blog   : www.baiyun.me
Link      : http://www.cnblogs.com/MiYu  || http://m.shnenglu.com/MiYu
Author By : MiYu
Test      : 1
Complier  : g++ mingw32-3.4.2
Program   : HDU_1512
Doc Name  : Monkey King
    
    
題目意思: 

有N只猴子, 每只都有一個力量值. 開始的時候互不認識, 它們之間會發生M次斗爭. 每次發生a, b的斗爭時, a, b都會從各自的朋友圈里拉出一個最強的, 之后兩只猴子打, 打完后這兩只猴子的力量值各減半. 并且打完后, 兩只猴子的朋友圈的所有人都互相認識(也就是不會再打).

你的任務就是對于每個斗爭, 若a, b是朋友, 那么輸出-1, 否則輸出打完后它們的朋友圈的最強猴子的力量值.

 使用 普通 優先隊列的話 估計會超時, 因為數據量很大 100000 ! !, 等下有空試試看. 

對于每一個節點, 定義dis 表示X節點到最右邊的空節點的距離的最小值

對于每個節點X, 要求X的左兒子的dis >= 右兒子的dis, 那么容易發現, 對于N個節點的左偏樹, 其右兒子最多只有logN個節點.

合并操作就是讓復雜度落在右兒子上, 從而達到logN的合并復雜度.

首先對于兩個堆, 若其中一個為空, 返回另一個.

否則(這里以大根堆為例), a指向堆頂較大的堆, b指向另一個. 讓a的右兒子和b合并, 合并后的子樹作為a的右兒子.

接下來, 檢查a的兩個兒子是否滿足dis, 不滿足就交換兩個兒子.

最后, 更新a的dis.

這樣就容易實現堆的其他操作 ( 比如插入, 刪除頂等 ).

另外 還需要用到 并查集.    
    
    
*/
//#pragma warning( disable:4789 )
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <utility>
#include <queue>
#include <stack>
#include <list>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;
const int MM = 100010;
struct left {
        int l,r,dis,val,dad;
} heap[MM];

int N, M;

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

inline int find ( int &x ) {
    return heap[x].dad == x ? x : heap[x].dad = find ( heap[x].dad );
}

inline void swap(int &a, int &b) {
     a ^= b ^= a ^= b;
}

inline int merge ( int x, int y ) {
    if ( x == 0 ) return y;
    if ( y == 0 ) return x;
    if ( heap[y].val > heap[x].val ) swap ( x, y );    
    heap[x].r = merge ( heap[x].r, y );
    heap[heap[x].r].dad = x;
    if ( heap[ heap[x].l ].dis < heap[ heap[x].r ].dis ) 
         swap ( heap[x].l, heap[x].r );
    if ( heap[x].r == 0 ) heap[x].dis = 0;
    else heap[x].dis = heap[ heap[x].r ].dis + 1;
    return x;
}

inline int push ( int x, int y ) {
       return merge ( x, y );       
}

inline int pop ( int &x ) {
       int l = heap[x].l; 
       int r = heap[x].r; 
       heap[l].dad = l;
       heap[r].dad = r;
       heap[x].l = heap[x].r = heap[x].dis = 0;   
       return merge ( l, r );  
}

inline bool scan_d(int &num) {
        char in;bool IsN=false;
        in=getchar();
        if(in==EOF) return false;
        while(in!='-'&&(in<'0'||in>'9')) in=getchar();
        if(in=='-'){ IsN=true;num=0;}
        else num=in-'0';
        while(in=getchar(),in>='0'&&in<='9'){
                num*=10,num+=in-'0';
        }
        if(IsN) num=-num;
        return true;
}

int main() {
    while ( scan_d ( N ) ) {
         for ( int i = 1; i <= N; ++ i ) {
              scan_d ( heap[i].val );
              heap[i].l = heap[i].r = heap[i].dis = 0;
              heap[i].dad = i;    
         }
         scan_d ( M );
         int a, b, x, y;
         while ( M -- ) {
                scan_d (a); scan_d (b);
                x = find ( a );
                y = find ( b ); 
                if ( x == y ) {
                    puts ( "-1" );     
                } else {
                    heap[x].val /= 2;
                    int xx = push ( pop ( x ), x );  
                    heap[y].val /= 2;
                    int yy = push ( pop ( y ), y );  
                    
                    printf ( "%d\n", heap[ merge ( xx, yy ) ].val );      
                }    
         } 
    }
    return 0;
}


 

 

 


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲一区二区不卡免费| 亚洲性感激情| 欧美高清不卡| 久久综合久久综合久久综合| 黄色亚洲在线| 欧美不卡在线| 欧美黄在线观看| 在线亚洲观看| 亚洲欧美国内爽妇网| 国产亚洲成av人片在线观看桃| 欧美亚洲色图校园春色| 欧美一级欧美一级在线播放| 一区二区在线不卡| 亚洲国产一区二区精品专区| 欧美电影在线观看| 亚洲女女女同性video| 欧美一区中文字幕| 精品福利电影| 日韩视频在线观看一区二区| 国产人成精品一区二区三| 久久久久久亚洲精品中文字幕 | 99国产精品久久久久久久成人热 | 午夜久久黄色| 久久精品二区三区| 日韩写真视频在线观看| 亚洲免费影视| 亚洲国产欧美一区二区三区久久 | 久久婷婷蜜乳一本欲蜜臀| 亚洲激情成人网| 一区二区三区日韩精品| 黑人一区二区三区四区五区| 亚洲免费电影在线| 今天的高清视频免费播放成人 | 久久日韩精品| 欧美日本在线| 久热精品在线视频| 国产精品久久77777| 欧美大片一区二区| 国产精品一区二区女厕厕| 欧美激情亚洲自拍| 国产精品亚洲成人| 最新成人av在线| 在线观看视频欧美| 午夜精品一区二区三区在线视 | 国产一区二区中文| 亚洲精品视频二区| **欧美日韩vr在线| 亚洲一区免费在线观看| 亚洲精品久久久久久下一站 | 欧美高清视频www夜色资源网| 欧美一区二区精美| 欧美日韩三区| 91久久夜色精品国产网站| 激情综合色综合久久综合| 亚洲网址在线| 亚洲无线一线二线三线区别av| 久久午夜激情| 久久免费视频在线| 国产日韩欧美日韩大片| 亚洲一区中文| 亚洲一区二区视频| 欧美日韩亚洲高清| 亚洲精品在线三区| 亚洲理论在线观看| 另类激情亚洲| 欧美成人久久| 亚洲激情专区| 久久成人国产精品| 久久精品国产精品亚洲综合| 欧美日韩国产麻豆| 亚洲福利在线看| 黄色精品一区| 久久亚洲综合色| 麻豆乱码国产一区二区三区| 国内精品美女av在线播放| 欧美亚洲一区二区在线观看| 欧美一区二区女人| 国产午夜久久久久| 久久国产日韩| 欧美成人高清视频| 亚洲人成小说网站色在线| 欧美国产精品一区| 亚洲激精日韩激精欧美精品| 中文网丁香综合网| 国产精品美女一区二区在线观看| 亚洲一二三四区| 久久久久9999亚洲精品| 在线看成人片| 欧美日韩国产系列| 亚洲午夜一区二区三区| 久久精品国内一区二区三区| 狠狠色狠狠色综合日日91app| 久久久之久亚州精品露出| 欧美激情亚洲综合一区| 亚洲视频在线免费观看| 国产丝袜美腿一区二区三区| 久久精品亚洲乱码伦伦中文| 亚洲高清一二三区| 亚洲一区二区欧美| 激情丁香综合| 欧美精品日韩综合在线| 亚洲欧美日韩网| 欧美电影电视剧在线观看| 在线视频日韩| 国产一区二区三区四区hd| 免费在线亚洲| 亚洲欧美在线磁力| 亚洲青色在线| 久久久久九九视频| 亚洲一区3d动漫同人无遮挡| 国内精品视频在线播放| 欧美日韩第一区| 久久九九精品99国产精品| 日韩网站在线| 免费观看在线综合| 午夜亚洲精品| 99国产精品久久| 在线国产亚洲欧美| 国产精品视频免费观看| 欧美粗暴jizz性欧美20| 欧美一区二区在线免费观看| 亚洲免费大片| 亚洲国产精品一区二区三区| 久久视频在线免费观看| 亚洲欧美日韩一区| 99av国产精品欲麻豆| 伊人久久婷婷色综合98网| 国产精品私拍pans大尺度在线| 欧美国产视频在线观看| 久久久久9999亚洲精品| 亚洲男人的天堂在线aⅴ视频| 亚洲人成艺术| 欧美大片免费久久精品三p| 久久久伊人欧美| 久久精品理论片| 欧美伊人久久大香线蕉综合69| 中日韩美女免费视频网站在线观看| 精品999日本| 好吊成人免视频| 久久免费视频在线| 国产欧美日韩一区| 欧美午夜免费影院| 欧美日本在线一区| 麻豆av福利av久久av| 欧美在线免费视频| 欧美一区二区三区在线播放| 午夜精品久久久久久久男人的天堂| 亚洲欧洲日韩在线| 亚洲欧洲综合另类| 91久久夜色精品国产九色| 亚洲国产精品久久久久婷婷884| 免费成年人欧美视频| 蜜桃av一区| 欧美第一黄色网| 亚洲欧洲日韩综合二区| 亚洲精品免费电影| 一区二区三区四区五区在线| 亚洲一区二区三区在线| 亚洲欧美日本另类| 久久不射2019中文字幕| 毛片av中文字幕一区二区| 免费日韩av| 欧美日韩免费高清| 亚洲欧美日韩直播| 91久久精品国产91久久性色| 免费观看成人| 欧美激情综合| 亚洲毛片在线| 亚洲一区二区三区精品视频| 午夜宅男久久久| 久热精品视频在线| 欧美区亚洲区| 国产日韩精品一区二区三区在线| 国产最新精品精品你懂的| 亚洲第一网站| 亚洲视频一二| 另类亚洲自拍| 亚洲美女黄色片| 欧美有码在线观看视频| 欧美成在线观看| 国产精品自拍三区| 亚洲欧洲在线播放| 亚洲欧美国产精品专区久久| 另类欧美日韩国产在线| 一区二区三区国产在线| 久久狠狠一本精品综合网| 亚洲国产老妈| 一本大道久久精品懂色aⅴ | 欧美国产日韩在线| 国产女人精品视频| 亚洲精品日本| 久久免费黄色| 一区二区三区 在线观看视| 久久精品一区二区三区四区| 欧美视频一区二区三区…| 韩日精品中文字幕| 亚洲欧美日韩精品久久久久| 欧美电影美腿模特1979在线看| 亚洲欧美综合一区| 欧美精品综合|