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

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


 

 

 

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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级片网| 亚洲视频在线观看三级| 亚洲摸下面视频| 激情文学一区| 亚洲欧洲一区二区天堂久久| 欧美精选一区| 午夜日韩电影| 久久久水蜜桃| 国产精品99久久久久久久vr | 国产亚洲毛片在线| 狼人天天伊人久久| 欧美日韩国产小视频在线观看| 亚洲精品亚洲人成人网| 亚洲精选一区二区| 国产一区二区精品| 美女视频黄a大片欧美| 欧美精品一区二区在线观看| 亚洲一区二区三区免费视频| 亚洲欧美激情诱惑| 亚洲国产综合视频在线观看| 99国产精品国产精品久久| 国产麻豆精品视频| 亚洲欧洲精品天堂一级| 国产女主播一区| 亚洲丰满少妇videoshd| 国产伦精品一区二区三区免费| 久久视频免费观看| 国产精品xnxxcom| 麻豆精品视频| 欧美亚洲第一页| 久久综合给合| 国产精品日韩电影| 亚洲精品国精品久久99热| 国产一区视频观看| 亚洲午夜精品一区二区三区他趣 | 欧美成人免费播放| 久久精彩免费视频| 欧美午夜激情视频| 亚洲精品国精品久久99热一| 伊人久久婷婷色综合98网| 亚洲综合国产| 亚洲一区二区不卡免费| 欧美风情在线| 欧美国产视频一区二区| 国产综合色产在线精品| 一区二区三区国产| aa国产精品| 欧美**人妖| 久久综合九色99| 国产日韩欧美一区在线| 亚洲免费激情| 亚洲国产福利在线| 亚洲欧美卡通另类91av | 欧美视频一区二区三区在线观看| 久久久久中文| 国产精品久久久久久久久久久久久| 亚洲人成7777| 亚洲欧洲日韩在线| 久久另类ts人妖一区二区| 久久国内精品视频| 国产亚洲一本大道中文在线| 亚洲桃色在线一区| 亚洲少妇中出一区| 欧美日韩免费一区二区三区视频| 亚洲国产99| 亚洲激情网站免费观看| 麻豆精品在线观看| 亚洲高清不卡av| 99国产麻豆精品| 欧美日韩a区| 99视频+国产日韩欧美| 亚洲一区视频| 国产精品主播| 欧美中文字幕在线视频| 久久人人97超碰国产公开结果| 国模一区二区三区| 久久激情久久| 欧美激情亚洲视频| 亚洲精品一区二| 欧美国产精品va在线观看| 亚洲高清久久网| 一区二区三区高清在线| 欧美韩日一区二区三区| 艳妇臀荡乳欲伦亚洲一区| 西西裸体人体做爰大胆久久久 | 亚洲午夜一区二区| 久久精品亚洲精品| 亚洲电影免费观看高清完整版| 免费观看成人网| 亚洲区免费影片| 亚洲综合精品四区| 国产精品视频999| 久久精品国产96久久久香蕉| 免费看成人av| 亚洲视频大全| 国产精品日韩欧美| 久久久国产一区二区| 欧美大片在线看免费观看| 亚洲一区二区三区高清| 国产视频精品va久久久久久| 久久午夜视频| 99在线精品视频| 久久国产精品网站| 亚洲人成毛片在线播放| 欧美日韩国产成人精品| 欧美一区影院| 亚洲美女在线国产| 久久综合网络一区二区| 亚洲午夜在线观看视频在线| 在线播放日韩欧美| 国产精品嫩草99av在线| 免费不卡亚洲欧美| 欧美与欧洲交xxxx免费观看 | 欧美/亚洲一区| 亚洲私人黄色宅男| 亚洲国产综合在线看不卡| 欧美视频在线一区| 欧美精品亚洲二区| 久久亚洲精品伦理| 午夜精品福利一区二区蜜股av| 亚洲国产二区| 欧美成人网在线| 久久精品国产一区二区三| 中国成人黄色视屏| 亚洲福利视频专区| 韩国一区二区三区美女美女秀| 欧美视频免费| 欧美激情一区二区三区蜜桃视频| 久久精品视频播放| 午夜精品久久久久久久99樱桃 | 午夜在线观看欧美| 在线亚洲一区| 99国产精品国产精品久久| 韩国久久久久| 狠狠色丁香婷婷综合| 国产综合亚洲精品一区二| 国产情侣久久| 国产精品日韩欧美一区| 国产精品国产三级国产普通话99| 美女精品自拍一二三四| 久久免费黄色| 久久精品免费看| 欧美亚洲在线播放| 香蕉久久夜色精品国产| 午夜久久影院| 欧美在线播放一区| 久久久久99精品国产片| 欧美亚洲午夜视频在线观看| 亚洲综合不卡| 亚洲一区在线观看视频| 99在线热播精品免费99热| 亚洲国产经典视频| 亚洲片在线资源| 99国产精品久久久久老师| 99精品久久| 亚洲欧美欧美一区二区三区| 午夜精品婷婷| 久久精品国产清高在天天线| 久久免费少妇高潮久久精品99| 久久先锋影音| 奶水喷射视频一区| 欧美日本一区| 国产毛片久久| 在线看日韩欧美| 亚洲精品日韩综合观看成人91| 日韩午夜av在线| 亚洲欧美日韩综合| 久久免费99精品久久久久久| 欧美大片在线看免费观看| 9人人澡人人爽人人精品| 亚洲一区二区三区免费在线观看 | 亚洲精品在线观看免费| 一区二区国产日产| 欧美一区2区三区4区公司二百| 久久免费观看视频| 欧美日韩一区国产| 国产亚洲欧美aaaa| 黄色精品一二区| 日韩一级片网址| 欧美一区二区黄色| 欧美激情第三页| 一区二区三区四区五区视频 | 亚洲免费视频中文字幕| 久久综合久久久久88| 国产精品v日韩精品v欧美精品网站| 国产日韩欧美日韩| 亚洲欧洲久久| 麻豆久久婷婷| 亚洲综合视频1区| 欧美三级午夜理伦三级中视频|