[bzoj] 1034: [ZJOI2008]泡泡堂BNB 发表于 Mar 18 2015 | 分类于 bzoj | 题意 传送门 分析与”田忌赛马”类似.最弱或最强能赢则赢,不能赢则最弱打对方最强 代码12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152#include <cstdio>int CH , NEG ;inline void read(int& ret) { ret = NEG = 0 ; while (CH=getchar() , CH<'!') ; if (CH == '-') NEG = true , CH = getchar() ; while (ret = ret*10+CH-'0' , CH=getchar() , CH>'!') ; if (NEG) ret = -ret ;}inline void reads(int& ret) {truewhile (ret=getchar() , ret<'!') ;truewhile (CH=getchar() , CH>'!') ;}#include <algorithm>#define maxn 100010LLint n ;int a[maxn] , b[maxn] ;int calc(int* a , int* b) {trueint ret = 0 , l1 , l2 , r1 , r2 ;truel1 = l2 = 1 , r1 = r2 = n ;truewhile (l1 <= r1)true if (a[l1] > b[l2]) ret += 2 , l1 ++ , l2 ++ ;true else if (a[r1] > b[r2]) ret += 2 , r1 -- , r2 -- ;true else ret += (a[l1]==b[r2]) , l1 ++ , r2 -- ;truereturn ret ;}int main() {int i ;// #define READtrue#ifdef READtruetruefreopen(".in" ,"r",stdin ) ;truetruefreopen(".out","w",stdout) ;true#endiftrueread(n) ;truefor (i = 1 ; i <= n ; i ++ ) read(a[i]) ;truefor (i = 1 ; i <= n ; i ++ ) read(b[i]) ;truestd::sort(a+1 , a+n+1) ;truestd::sort(b+1 , b+n+1) ;trueprintf("%d %d\n", calc(a , b) , 2*n-calc(b , a)) ;true#ifdef READtruetruefclose(stdin) ; fclose(stdout) ;true#elsetruetruegetchar() ; getchar() ;true#endiftruereturn 0 ;}