zoukankan      html  css  js  c++  java
  • 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
    ",ans1,n*2-ans2);
        return 0;
    }
  • 相关阅读:
    ios开发之--把秒转换为天时分秒
    网络爬虫的类型
    网络爬虫的组成
    为什么要学网络爬虫
    什么是网络爬虫
    Windows 下安装 Python3
    Linux 下安装 Python3
    HTTP 代理
    HTTP Cookies
    爬虫的基本原理
  • 原文地址:https://www.cnblogs.com/yanlifneg/p/5538268.html
Copyright © 2011-2022 走看看