【解题思路】

  广义田忌赛马的贪心模型。如果当前实力最差的马比对手实力最差的马强,则匹配;如果当前实力最强的马比对手实力最强的马强,亦匹配;若上述两点均不成立,拿己方最差的马去匹配对手最强的马。复杂度O(nlog2n)。

【参考代码】

 #include <algorithm>
#include <cstdio>
#define REP(i,low,high) for(register int i=(low);i<=(high);++i)
#define __function__(type) __attribute__((optimize("-O2"))) inline type
#define __procedure__ __attribute__((optimize("-O2"))) inline void
using namespace std; __function__(int) score(const int&x,const int&y) {return x==y?:(x>y)*;} static int n; int a[],b[]; int main()
{
scanf("%d",&n); REP(i,,n) scanf("%d",a+i); REP(i,,n) scanf("%d",b+i);
sort(a+,a+n+),sort(b+,b+n+); int la=,ra=n,lb=,rb=n,ans=;
while(la<=ra)
{
if(a[la]>b[lb]) {ans+=score(a[la++],b[lb++]); continue;}
if(a[ra]>b[rb]) {ans+=score(a[ra--],b[rb--]); continue;}
ans+=score(a[la++],b[rb--]);
}
printf("%d ",ans),la=,ra=n,lb=,rb=n,ans=;
while(la<=ra)
{
if(a[la]<b[lb]) {ans+=score(a[la++],b[lb++]); continue;}
if(a[ra]<b[rb]) {ans+=score(a[ra--],b[rb--]); continue;}
ans+=score(a[ra--],b[lb++]);
}
return printf("%d\n",ans),;
}

最新文章

  1. nodejs复习04
  2. test spring in category
  3. linux学习8 第八章 权限管理
  4. Windows Azure Web Site (14) Azure Web Site IP白名单
  5. 二进制流 最后一段数据是最后一次读取的byte数组没填满造成的
  6. JQuery基础教程:事件(下)
  7. excel VLOOKUP函数的用法
  8. ASP.NET服务器控件OnClientClick事件中Eval()作为js方法的参数的一种写法
  9. 2014-02-27WPF学习笔记
  10. iOS开发 autoResizingMask使用
  11. poj 2488A Knight&#39;s Journey
  12. rac 10g 加入节点具体解释
  13. mysql主键设置成auto_increment时,进行并发性能測试出现主键反复Duplicate entry &amp;#39;xxx&amp;#39; for key &amp;#39;PRIMARY&amp;#39;
  14. 【Sort】HeapSort
  15. speedment 入门教程
  16. 小子给大家分享一个或者多个新手创建tableview经常会遇到的坑(动态创建控件,xib的重用)
  17. new function
  18. New UWP Community Toolkit - RadialGauge
  19. JDK安装:CentOS和Windows环境
  20. flask 异步发送邮件

热门文章

  1. 第1篇Kubernetes介绍
  2. 【TJOI/HEOI2016】求和
  3. hibernate3.6异常
  4. spring接收文件资源
  5. Linux常用查看日志命令tail
  6. php-数据库-分页类-上传类
  7. table标签详解
  8. centos coreseek
  9. [NOIP模拟16]题解
  10. C++语言编程基础