bzoj1034题解
【解题思路】
广义田忌赛马的贪心模型。如果当前实力最差的马比对手实力最差的马强,则匹配;如果当前实力最强的马比对手实力最强的马强,亦匹配;若上述两点均不成立,拿己方最差的马去匹配对手最强的马。复杂度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),;
}
bzoj1034题解的更多相关文章
- 【题解】BZOJ1034 [ZJOI2008]泡泡堂BNB(贪心)
[题解]BZOJ1034 [ZJOI2008]泡泡堂BNB(贪心) 考虑直接模拟田忌赛马... 我的最小比你的大,直接上 我的最大比你的大,直接上 otherwise,我小换你大 考虑最劣,由于每次比 ...
- 【BZOJ1034】泡泡堂(贪心)
[BZOJ1034]泡泡堂(贪心) 题面 BZOJ 洛谷 题解 很基础的贪心,然而我竟然没写对...身败名裂. 大概就是类似田忌赛马. 先拿看当前最大值是否能否解决对面最大值,否则检查能否用最小值来兑 ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- poj1399 hoj1037 Direct Visibility 题解 (宽搜)
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...
随机推荐
- 【Luogu】【关卡2-14】 树形数据结构(2017年10月)【AK】
任务说明:由一个根节点分叉,越分越多,就成了树.树可以表示数据之间的从属关系 P1087 FBI树 给一个01字符串,0对应B,1对应I,F对应既有0子节点又有1子节点的根节点,输出这棵树的后序遍历. ...
- PHP多参数方法的重构
假设我们要完成一个保存文章的功能,如果采用函数编程的方式,大概会是下面这个样子: <?php function saveArticle($title, $content, $categoryId ...
- 【架构】spring framework核心框架体系结构
Spring官方文档,用的版本为4.3.11版本. 一.引用官方文档 2.2.1核心集装箱 所述核心容器由以下部分组成spring-core, spring-beans,spring-context, ...
- Yii2中应用子模块下的内容
public function actionIndex(){ $article=\YII::$app->getModule('article'); $article->runAction( ...
- 欧拉降幂,基本计算定理——cf615D
用基本算数定理求约数和的思想来计算, 首先用pi,ci来表示第i个质数,指数为i,然后对于每个pi,pi^2...都有指数为mul{(c_1+1)(c_2+1)(c_i-1+1)(c_i+1+1).. ...
- 使用PHP curl模拟浏览器抓取网站信息
curl是一个利用URL语法在命令行方式下工作的文件传输工具.curl是一个利用URL语法在命令行方式下工作的文件传输工具.它支持很多协议:FTP, FTPS, HTTP, HTTPS, GOPHER ...
- 训练集(train set) 验证集(validation set) 测试集(test set)。
训练集(train set) 验证集(validation set) 测试集(test set). http://blog.sina.com.cn/s/blog_4d2f6cf201000cjx.ht ...
- Makefile中的函数
Makefile 中的函数 Makefile 中自带了一些函数, 利用这些函数可以简化 Makefile 的编写. 函数调用语法如下: $(<function> <arguments ...
- 关于C语言命令行参数问题
1 int main(int argc,char** argv) 参数: argc:命令行参数的个数 argv:保存命令行参数:argv[0]保存本程序自己的名称 现在自己只知道这些以后再有学习继续补 ...
- tensorflow 训练最后预测结果为一个定值,可能的原因
训练一个分类网络,没想到预测结果为一个定值. 找了很久发现,是因为tensor的维度的原因. 注意:我说的是我的label数据的维度. 我的输入是: y_= tf.placeholder(tf.in ...