bzoj 1034 (田忌赛马++)

/*
这类题的最优策略:
自己最好的干掉对方最好的 或者 自己最差的干掉对方最差的
不能的话 用自己最差的 对阵对方最好的 
这样是最优的 实现嘛 搞两个队列跑一跑
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100010
using namespace std;
int n,q1[maxn],q2[maxn],ans1,ans2,h1,h2,t1,t2;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
      scanf("%d",&q1[i]);
    for(int i=1;i<=n;i++)
      scanf("%d",&q2[i]);
    sort(q1+1,q1+1+n);
    sort(q2+1,q2+1+n);
    h1=h2=1;t1=t2=n;
    while(h1<=t1)
      {
          if(q1[h1]>q2[h2])ans1+=2,h1++,h2++;
          else if(q1[t1]>q2[t2])ans1+=2,t1--,t2--;
          else 
            {
                if(q1[h1]==q2[t2])ans1++;
            h1++,t2--;
          }
      }
    h1=h2=1;t1=t2=n;
    while(h2<=t2)
      {
          if(q2[h2]>q1[h1])ans2+=2,h1++,h2++;
          else if(q2[t2]>q1[t1])ans2+=2,t1--,t2--;
          else 
            {
                if(q2[h2]==q1[t1])ans2++;
            h2++,t1--;
          }
      }
    printf("%d %d\n",ans1,n*2-ans2);
    return 0;
}

 

转载于:https://www.cnblogs.com/yanlifneg/p/5538268.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值