【题目链接】

  http://www.lydsy.com/JudgeOnline/problem.php?id=1034

【题意】

 

  给两个序列以任意顺序比较,求出最大和最小得分。

【思路】

  

  排序后使用贪心。

  最小的能赢就赢,最大的能赢就赢,否则用最小的比最大的。

【代码】

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; const int N = 3e5+; int a[N],b[N],n; void read(int& x)
{
char c=getchar(); int f=;x=;
while(!isdigit(c)) { if(c=='-')f=-; c=getchar(); }
while(isdigit(c)) x=x*+c-'',c=getchar();
x*=f;
}
int solve(int* a,int* b)
{
int l1=,r1=n,l2=,r2=n;
int res=;
while(l1<=r1&&l2<=r2)
{
if(a[l1]>b[l2]) { res+=; l1++; l2++; }
else if(a[r1]>b[r2]) { res+=; r1--,r2--; }
else {
res+=a[l1]==b[r2];
l1++,r2--;
}
}
return res;
} int main()
{
read(n);
for(int i=;i<=n;i++) read(a[i]);
for(int i=;i<=n;i++) read(b[i]);
sort(a+,a+n+);
sort(b+,b+n+);
printf("%d %d",solve(a,b),*n-solve(b,a));
return ;
}

最新文章

  1. 学习设计模式第二十七 - GoF之外简单工厂模式
  2. [moka同学笔记]二、Yii2.0课程笔记(魏曦老师教程)
  3. SQL查询 练习题
  4. 161205、win10安装mysql5.7.16数据库
  5. Solr部署准备
  6. Red and Black ---路线问题
  7. xml有哪些解析技术?区别是什么?
  8. nginx 1.3.9/1.4.0 x86 Brute Force Remote Exploit
  9. pager-taglib使用示范
  10. 在CentOS下源码安装 Xen并搭建Windows虚拟机
  11. PHP5.3 里面数组的的实现方式
  12. mysql 千万量级的表的优化
  13. Java IO学习笔记四
  14. PHP flock() 函数
  15. Django模板语言初识
  16. org.activiti.engine.activitiexception:version of activiti database(5.22) is more recent than the engine(5.12)
  17. HTML5 播放器
  18. C++的STL之map自动排序特性
  19. 记一次给nginx的web服务器目录加软链接
  20. jms版本

热门文章

  1. SpringJUnit4加载类目录下(src)和WEF-INF目录下的配置文件
  2. asp.net单点登录(SSO)解决方案
  3. js中批量处理样式——cssText的使用
  4. 解决Oracle ORA-00984: column not allowed here
  5. State Management
  6. 【形式化方法:VDM++系列】2.VDMTools环境的搭建
  7. 意外发现,VC断点可加在构造函数的左括号上
  8. Android:控件布局(绝对布局)AbsoluteLayout
  9. Android studio中不同颜色代表什么意思
  10. 手动添加 memcached.jar包