Description
于是他们开始玩排火车了。。。
现在假设Apple和Gaga各有N张牌,Apple先出牌。请你给出一轮下来Apple和Gaga各获得的牌数。
Input
第一行T,表示T组测试数据,接下来有T部分。
每部分开头是一个整数N(1 <= N <= 50000),表示Apple和Gaga的牌数。接下来有2行,给出Apple和Gaga的牌的情况。首先给出Apple的牌,有N个整数,第i个整数xi(1 <= xi <= 100000)表示Apple的第i张牌面。其次给出Gaga的牌,格式类似。
Output
Sample Input
Sample Output
Hint
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stack>
using namespace std;
const int maxn=110000;
int flag[maxn];
int a[maxn];
int main(){
int t,cnt=0;
scanf("%d",&t);
while(t--){
memset(flag,0,sizeof(flag));
int n,aa=0,bb=0;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i*2]);
}
for(int i=0;i<n;i++){
scanf("%d",&a[i*2+1]);
}
stack<int>S;
while(!S.empty()){
S.pop();
}
for(int i=0;i<2*n;i++){
if(!flag[a[i]]){
flag[a[i]]=1;
S.push(a[i]);
}else{
int tmp=0,num=0;
while(!S.empty()){
tmp=S.top();
flag[tmp]=0;
if(tmp!=a[i]){
S.pop();
num++;
}else{
break;
}
}
S.pop();
num+=2;
if(i%2==0){
aa+=num;
}else{
bb+=num;
}
}
}
printf("Case %d:Apple:%d Gaga:%d\n",++cnt,aa,bb);
}
return 0;
}
原文:http://www.cnblogs.com/chengsheng/p/4368872.html