锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国产欧美日韩精品在线,一区视频在线,欧美日韩在线播放三区四区http://m.shnenglu.com/MiYu/category/14428.html ______________鐧界櫧銇眿zh-cnSun, 24 Oct 2010 12:54:19 GMTSun, 24 Oct 2010 12:54:19 GMT60HDU 1512 HDOJ 1512 Monkey King ( 宸﹀亸鏍?) ACM 1512 IN HDUhttp://m.shnenglu.com/MiYu/archive/2010/10/24/131043.htmlMiYuMiYuSun, 24 Oct 2010 03:43:00 GMThttp://m.shnenglu.com/MiYu/archive/2010/10/24/131043.htmlhttp://m.shnenglu.com/MiYu/comments/131043.htmlhttp://m.shnenglu.com/MiYu/archive/2010/10/24/131043.html#Feedback0http://m.shnenglu.com/MiYu/comments/commentRss/131043.htmlhttp://m.shnenglu.com/MiYu/services/trackbacks/131043.htmlMiYu鍘熷垱, 杞笘璇鋒敞鏄?: 杞澆鑷?nbsp;______________鐧界櫧銇眿    

 

棰樼洰鍦板潃:

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

棰樼洰鎻忚堪 :

浠g爜
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
    
    
棰樼洰鎰忔? 

鏈塏鍙尨瀛? 姣忓彧閮芥湁涓涓姏閲忓? 寮濮嬬殑鏃跺欎簰涓嶈璇? 瀹冧滑涔嬮棿浼氬彂鐢烳嬈℃枟浜? 姣忔鍙戠敓a, b鐨勬枟浜夋椂, a, b閮戒細浠庡悇鑷殑鏈嬪弸鍦堥噷鎷夊嚭涓涓渶寮虹殑, 涔嬪悗涓ゅ彧鐚村瓙鎵? 鎵撳畬鍚庤繖涓ゅ彧鐚村瓙鐨勫姏閲忓煎悇鍑忓崐. 騫朵笖鎵撳畬鍚? 涓ゅ彧鐚村瓙鐨勬湅鍙嬪湀鐨勬墍鏈変漢閮戒簰鐩歌璇?涔熷氨鏄笉浼氬啀鎵?.

浣犵殑浠誨姟灝辨槸瀵逛簬姣忎釜鏂椾簤, 鑻, b鏄湅鍙? 閭d箞杈撳嚭-1, 鍚﹀垯杈撳嚭鎵撳畬鍚庡畠浠殑鏈嬪弸鍦堢殑鏈寮虹尨瀛愮殑鍔涢噺鍊?

 浣跨敤 鏅?浼樺厛闃熷垪鐨勮瘽 浼拌浼氳秴鏃? 鍥犱負鏁版嵁閲忓緢澶?100000 ! !, 絳変笅鏈夌┖璇曡瘯鐪? 

瀵逛簬姣忎竴涓妭鐐? 瀹氫箟dis 琛ㄧずX鑺傜偣鍒版渶鍙寵竟鐨勭┖鑺傜偣鐨勮窛紱葷殑鏈灝忓?/div>

瀵逛簬姣忎釜鑺傜偣X, 瑕佹眰X鐨勫乏鍎垮瓙鐨刣is >= 鍙沖効瀛愮殑dis, 閭d箞瀹規(guī)槗鍙戠幇, 瀵逛簬N涓妭鐐圭殑宸﹀亸鏍? 鍏跺彸鍎垮瓙鏈澶氬彧鏈塴ogN涓妭鐐?

鍚堝茍鎿嶄綔灝辨槸璁╁鏉傚害钀藉湪鍙沖効瀛愪笂, 浠庤岃揪鍒發(fā)ogN鐨勫悎騫跺鏉傚害.

棣栧厛瀵逛簬涓や釜鍫? 鑻ュ叾涓竴涓負絀? 榪斿洖鍙︿竴涓?

鍚﹀垯(榪欓噷浠ュぇ鏍瑰爢涓轟緥), a鎸囧悜鍫嗛《杈冨ぇ鐨勫爢, b鎸囧悜鍙︿竴涓? 璁゛鐨勫彸鍎垮瓙鍜宐鍚堝茍, 鍚堝茍鍚庣殑瀛愭爲浣滀負a鐨勫彸鍎垮瓙.

鎺ヤ笅鏉? 媯鏌鐨勪袱涓効瀛愭槸鍚︽弧瓚砫is, 涓嶆弧瓚沖氨浜ゆ崲涓や釜鍎垮瓙.

鏈鍚? 鏇存柊a鐨刣is.

榪欐牱灝卞鏄撳疄鐜板爢鐨勫叾浠栨搷浣?( 姣斿鎻掑叆, 鍒犻櫎欏剁瓑 ).

鍙﹀ 榪橀渶瑕佺敤鍒?騫舵煡闆?    
    
    
*/
//#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;
}


 

 

 



MiYu 2010-10-24 11:43 鍙戣〃璇勮
]]> 青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
              国语自产精品视频在线看一大j8| 久久av红桃一区二区小说| 欧美成人中文字幕在线| 欧美在线观看日本一区| 香蕉国产精品偷在线观看不卡| 亚洲天堂av高清| 亚洲私人影吧| 欧美一区免费视频| 久久蜜桃精品| 欧美日韩视频不卡| 国产精品系列在线| 黄色国产精品| 亚洲欧洲免费视频| 午夜激情一区| 免费毛片一区二区三区久久久| 亚洲国产精品久久久久| 日韩手机在线导航| 亚洲综合首页| 久久夜色精品亚洲噜噜国产mv| 欧美freesex8一10精品| 欧美图区在线视频| 一区二区亚洲精品国产| 亚洲二区在线观看| 亚洲视频导航| 免费在线播放第一区高清av| 99精品视频免费全部在线| 午夜精品国产精品大乳美女| 欧美成人精品一区| 国产精品制服诱惑| 亚洲激情一区二区| 亚洲欧美日韩国产精品| 蜜臀av在线播放一区二区三区| 99在线观看免费视频精品观看| 久久爱www.| 欧美视频日韩| 亚洲国产天堂网精品网站| 亚洲欧美日韩一区二区三区在线观看 | 久久久不卡网国产精品一区| 欧美紧缚bdsm在线视频| 韩日精品视频一区| 欧美一区二区成人| 91久久久久久久久| 久久综合五月| 国色天香一区二区| 久久成人国产| 亚洲欧美在线视频观看| 国产精品色一区二区三区| 正在播放欧美视频| 亚洲欧洲午夜| 老司机免费视频久久| 亚洲私人影院| 国产精品爱久久久久久久| 亚洲乱码国产乱码精品精可以看| 久久免费国产| 久久爱www久久做| 国产日韩欧美成人| 久久国产精品黑丝| 午夜精品理论片| 国产精品久久久久999| 日韩一区二区福利| 亚洲国产mv| 久久久精品久久久久| 国产一区91| 亚洲欧美在线播放| 99re8这里有精品热视频免费| 久久久久久久成人| 久久青草欧美一区二区三区| 亚洲高清视频在线观看| 久久综合国产精品| 欧美一区1区三区3区公司| 国产精品久久久久久亚洲毛片| 一区二区欧美视频| 亚洲精品国产系列| 欧美激情按摩在线| 日韩视频一区| 欧美成人资源| 欧美日韩三级一区二区| 亚洲另类在线视频| 亚洲国产成人午夜在线一区| 久久人人精品| 亚洲黄色在线看| 欧美国产日韩一区| 欧美成人免费va影院高清| 亚洲高清在线视频| 欧美一区二区视频在线观看| 欧美在线日韩精品| 在线播放亚洲| 欧美韩日一区二区| 欧美高清视频一区二区| 一本久久a久久免费精品不卡| 亚洲欧洲综合另类| 欧美日韩国产精品成人| 亚洲欧美国产77777| 亚洲人成高清| 国产主播一区二区| 欧美激情精品| 欧美日韩美女| 久久久99国产精品免费| 久久久伊人欧美| 亚洲精品视频免费| 夜夜夜久久久| 国产欧美精品一区二区色综合 | 媚黑女一区二区| 亚洲欧美日韩国产成人| 亚洲欧美在线免费| 韩国精品在线观看| 亚洲国产另类精品专区 | 欧美福利电影在线观看| 欧美高清成人| 午夜视频在线观看一区| 欧美一区二区大片| 国产日韩欧美二区| 一区二区三区你懂的| 黄色成人av网站| 夜夜嗨av一区二区三区中文字幕 | 欧美国产大片| 国产精品福利网| 噜噜噜91成人网| 欧美视频一区二区三区四区| 美女爽到呻吟久久久久| 国产精品久久999| 久久国产精品久久久久久电车| 欧美人与性动交cc0o| 久久天天躁夜夜躁狠狠躁2022 | 亚洲欧美日韩在线| 久久免费视频在线观看| 国产精品美女在线| 亚洲精品色婷婷福利天堂| 狠狠色狠狠色综合人人| 99xxxx成人网| 亚洲人成网站999久久久综合| 亚洲综合日本| 亚洲天堂网在线观看| 亚洲午夜黄色| 午夜日韩在线| 欧美精品自拍偷拍动漫精品| 久久亚洲精品网站| 国产欧美日韩另类一区| 亚洲精品一区二| 91久久国产自产拍夜夜嗨| 久久国产精品久久久久久久久久| 亚洲欧美日韩一区在线观看| 老司机精品导航| 亚洲国产精品久久久久久女王| 精品91视频| 久久精品五月| 老牛嫩草一区二区三区日本| 国产亚洲一区精品| 欧美亚洲网站| 久久国产精品网站| 国产乱码精品一区二区三区不卡| 农村妇女精品| 亚洲第一在线视频| 久久亚洲私人国产精品va| 久久伊人免费视频| 国产一区二区你懂的| 午夜视频在线观看一区| 亚洲一区二区不卡免费| 欧美日韩国产美女| 亚洲欧美卡通另类91av| 国产一区视频观看| 久久久午夜视频| 欧美韩国日本一区| 亚洲精品国产精品乱码不99| 亚洲精品美女在线观看播放| 国产欧美一级| 久久视频精品在线| 欧美激情一区二区三区四区| 亚洲激情在线激情| 欧美大片在线观看一区| 亚洲毛片av在线| 午夜精品福利电影| 狠狠干狠狠久久| 欧美午夜精品理论片a级按摩| 亚洲视频观看| 久久久一区二区| 亚洲青涩在线| 国产精品卡一卡二卡三| 欧美一级片在线播放| 鲁鲁狠狠狠7777一区二区| 黄色成人在线网址| 欧美日韩亚洲一区二区三区在线| 亚洲在线播放电影| 久热精品视频在线观看| 亚洲精品乱码久久久久| 国产精品久久久久国产a级| 欧美一区二区在线播放| 亚洲国产天堂久久综合| 午夜国产欧美理论在线播放| 亚洲综合三区| 一区二区三区黄色| 久久久蜜桃一区二区人| 99re6这里只有精品| 国产亚洲欧美一区二区| 欧美国产欧美综合 | 久久久久se| aⅴ色国产欧美| 老巨人导航500精品| 久久亚洲欧美| 久久另类ts人妖一区二区|