bzoj 1034 [ZJOI2008]泡泡堂BNB(贪心)
2024-09-02 03:53:25
【题目链接】
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 ;
}
最新文章
- 学习设计模式第二十七 - GoF之外简单工厂模式
- [moka同学笔记]二、Yii2.0课程笔记(魏曦老师教程)
- SQL查询 练习题
- 161205、win10安装mysql5.7.16数据库
- Solr部署准备
- Red and Black ---路线问题
- xml有哪些解析技术?区别是什么?
- nginx 1.3.9/1.4.0 x86 Brute Force Remote Exploit
- pager-taglib使用示范
- 在CentOS下源码安装 Xen并搭建Windows虚拟机
- PHP5.3 里面数组的的实现方式
- mysql 千万量级的表的优化
- Java IO学习笔记四
- PHP flock() 函数
- Django模板语言初识
- org.activiti.engine.activitiexception:version of activiti database(5.22) is more recent than the engine(5.12)
- HTML5 播放器
- C++的STL之map自动排序特性
- 记一次给nginx的web服务器目录加软链接
- jms版本
热门文章
- SpringJUnit4加载类目录下(src)和WEF-INF目录下的配置文件
- asp.net单点登录(SSO)解决方案
- js中批量处理样式——cssText的使用
- 解决Oracle ORA-00984: column not allowed here
- State Management
- 【形式化方法:VDM++系列】2.VDMTools环境的搭建
- 意外发现,VC断点可加在构造函数的左括号上
- Android:控件布局(绝对布局)AbsoluteLayout
- Android studio中不同颜色代表什么意思
- 手动添加 memcached.jar包