码迷,mamicode.com
首页 > 其他好文 > 详细

Luogu P1650 田忌赛马

时间:2019-09-24 15:55:16      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:char   main   tlb   reg   gis   class   题目   tchar   https   

题目
如果我们最大比对面最大大,那么直接用。
如果我们最小比对面最小大,那么直接用。
否则用我们最小去换对面最大。

#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    register int x=0;
    register char c=getchar();
    while(c>'9'||c<'0')
        c=getchar();
    while(c>='0'&&c<='9')
       x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x;
}
int a[10001],b[10001],n,ans,hda,tla,hdb,tlb;
bool aa[10001],bb[10001];
int  main()
{
    n=read();
    int ans=0;
    for(int i=1;i<=n;i++)
        a[i]=read();
    for(int i=1;i<=n;i++)
        b[i]=read();
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    hda=1,hdb=1,tla=n,tlb=n;
    while(n--)
        if(a[tla]>b[tlb])
            ans+=200,tla--,tlb--;
        else 
            if(a[hda]>b[hdb])
                ans+=200,hda++,hdb++;
            else 
                if(a[hda]<b[tlb])
                    ans-=200,hda++,tlb--;
    cout<<ans;
    return 0;
}

Luogu P1650 田忌赛马

标签:char   main   tlb   reg   gis   class   题目   tchar   https   

原文地址:https://www.cnblogs.com/cjoierShiina-Mashiro/p/11578429.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!