Tian Ji -- The Horse Racing

GCJ02坐标系转WGS84坐标系(已实地测试基本无偏差) 坐标系转化,GCJ02坐标系,WGS84坐标系 阅读详情

Here is a famous story in Chinese history.

“That was about 2300 years ago. General Tian Ji was a high official in the country Qi. He likes to play horse racing with the king and others.”

“Both of Tian and the king have three horses in different classes, namely, regular, plus, and super. The rule is to have three rounds in a match; each of the horses must be used in one round. The winner of a single round takes two hundred silver dollars from the loser.”

“Being the most powerful man in the country, the king has so nice horses that in each class his horse is better than Tian’s. As a result, each time the king takes six hundred silver dollars from Tian.”

“Tian Ji was not happy about that, until he met Sun Bin, one of the most famous generals in Chinese history. Using a little trick due to Sun, Tian Ji brought home two hundred silver dollars and such a grace in the next match.”

“It was a rather simple trick. Using his regular class horse race against the super class from the king, they will certainly lose that round. But then his plus beat the king’s regular, and his super beat the king’s plus. What a simple trick. And how do you think of Tian Ji, the high ranked official in China?”

Were Tian Ji lives in nowadays, he will certainly laugh at himself. Even more, were he sitting in the ACM contest right now, he may discover that the horse racing problem can be simply viewed as finding the maximum matching in a bipartite graph. Draw Tian’s horses on one side, and the king’s horses on the other. Whenever one of Tian’s horses can beat one from the king, we draw an edge between them, meaning we wish to establish this pair. Then, the problem of winning as many rounds as possible is just to find the maximum matching in this graph. If there are ties, the problem becomes more complicated, he needs to assign weights 0, 1, or -1 to all the possible edges, and find a maximum weighted perfect matching…

However, the horse racing problem is a very special case of bipartite matching. The graph is decided by the speed of the horses — a vertex of higher speed always beat a vertex of lower speed. In this case, the weighted bipartite matching algorithm is a too advanced tool to deal with the problem.

In this problem, you are asked to write a program to solve this special case of matching problem.

Input

The input consists of up to 50 test cases. Each case starts with a positive integer n (n <= 1000) on the first line, which is the number of horses on each side. The next n integers on the second line are the speeds of Tian’s horses. Then the next n integers on the third line are the speeds of the king’s horses. The input ends with a line that has a single 0 after the last test case.

Output

For each input case, output a line containing a single number, which is the maximum money Tian Ji will get, in silver dollars.

Sample Input

3
92 83 71
95 87 74
2
20 20
20 20
2
20 19
22 18
0

Sample Output

200
0
0

解题报告

我是类图论里面Bellman-Ford算法写的,方法有点笨,应该有更好的贪心算法。
总感觉我的方法有点悬,因为我无法证明方法的可行性,可能是运气好躲过了大量数据。

#include<stdio.h>
#include<algorithm>
#define MAX_N 1002
using namespace std;
int a[MAX_N],b[MAX_N];

int cmp(int x,int y){
    if(x>y) return 1;
    else if(x==y) return 0;
    return -1;
}

int main()
{
    int n;
    while(~scanf("%d",&n)&&n){
        for(int i=0;i<n;i++) scanf("%d",&a[i]);
        for(int i=0;i<n;i++) scanf("%d",&b[i]);
        sort(a,a+n);
        sort(b,b+n);
        for(int u=0;u<n;u++){
            bool update=false;
            for(int i=0;i<n;i++){
                for(int j=i+1;j<n;j++){
                    int x0=a[j],y0=b[j];
                    int x1=a[i],y1=b[i];

                    int val01=cmp(x0,y0);
                    int val02=cmp(x1,y1);
                    int val11=cmp(x0,y1);
                    int val12=cmp(x1,y0);

                    if(val11+val12>val01+val02||x0==y0&&x1==y1){
                        int tmp=b[j];b[j]=b[i];b[i]=tmp;
                        bool update=true;
                    }
                }
            }
            if(!update) break;
        }

        int ans=0;
        for(int i=0;i<n;i++){
            ans+=cmp(a[i],b[i]);
        }
        printf("%d\n",ans*200);
    }
    return 0;
}
模型训练篇 | 手把手教你使用ResNet训练自己数据集和推理,ResNet50通用物体分类识别,含完整代码和数据集,全网最详细教程 手把手教你使用ResNet训练自己数据集和推理,ResNet50通用物体分类识别,含完整代码和数据集,全网最详细教程。本篇文章将带你学习 ResNet50 模型构建、ResNet50训练自己数据集、数据集处理、推理和验证、模型剪枝与模型改进等。 本篇教程适配各种分类识别任务,可以说是一个通用的教程,只需修改自己的数据集即可完成自己领域的任务和系统实现。 阅读详情

相关推荐

SAP项目结算核心:结果分析码配置与KKA2/CJ88排错实战

结果分析码(RA Key)是SAP CO模块中实现项目收入确认与成本分摊的核心机制,其本质是一套融合时间逻辑、价值计算与责任归属的动态规则引擎。它并非简单映射会计科目,而是驱动KKA2和CJ88执行项目实际结算的关键算法,直接影响毛利真实性与财务合规性。在EPC、工程服务及多阶段合同场景下,错误选用RA01等默认配置极易导致收入虚增、税务风险与管理失真。本文结合sap ko88 增强与sap mdvp主数据校验等高频实践痛点,系统解析时间确定方法、值确定方法与结果分析类型三大维度,并提供五层穿透式排查链路,

weixin_34355559的博客 349

Tian Ji -- The Horse Racing(田忌赛马)/贪心算法

Tian Ji – The Horse Racing(田忌赛马) 田忌赛马的故事 (可以直接看题) Here is a famous story in Chinese history. “That was about 2300 years ago. General Tian Ji was a high official in the country Qi. He likes to play hor...

一直努力 1705

关于STM32编译报错:Error: L6218E: Undefined symbol SystemInit (referred from startup_stm32f10x_md.o).

今天新建工程发现出现一个错误 —— …\Output\CG.axf: Error: L6218E: Undefined symbol SystemInit (referred from startup_stm32f10x_md.o). 但我觉得我的操作没有任何问题,而且配置和上一个文件比较是一模一样的。 于是我开始百度查询,然后发现了下面几个博客—— @weixin_44133391——STM32 编译错误 @dorlolok——iel5 编译报错 error: L6235E: More than one

纯粹,学术,热爱。 9410

杭电oj1052题:Tian Ji -- The Horse Racing

题目:Here is a famous story in Chinese history."That was about 2300 years ago. General Tian Ji was a high official in the country Qi. He likes to play horse racing with the king and others.""Both of Tia

blingzlh的博客 735

elmos 524系列芯片笔记

芯片的工作工作原理:集成芯片Elmos524.03有发射回路和接收回路,手册有关的内部原理图,大致如下: 芯片会产生固有频率的电压信号,信号通过引脚DRV1、2输出给外部压电陶瓷片,产生固定频率的机械波,也就是所谓的超声波,超声波遇到障碍物时会反射,反射信号经过AINS、D引脚进入芯片,在芯片内部先后经过GAIN放大,滤波然后进入比较器,滤波后的信号(signal)同预先设定的阈值(threshold)比较产生信号输出。此信号最终会连接MCU处理器,需要重点关注。 基于这个内部的工作原

qq_38230916的博客 2523

【Spring Cloud Alibaba】Linux安装RocketMQ以及RocketMQ Dashboard可视化工具

在当今分布式架构的开发中,消息队列成为了一种常见的解决方案。RocketMQ是阿里巴巴开源的分布式消息中间件,具有高吞吐量、高可用性和强大的扩展性,因此在构建大规模、高可靠性的应用系统时备受推崇。而在使用RocketMQ时,为了更好地了解消息的流动和监控,RocketMQ Dashboard成为了一个不可或缺的可视化工具。本篇博客将带大家一步步在Linux系统中安装RocketMQ,并介绍如何配置和使用RocketMQ Dashboard。

编码人生 3392

Tian Ji -- The Horse Racing(贪心)

Tian Ji – The Horse Racing 题意: 田忌和齐王都有三匹不同类型的赛马,即下等马,中等马和上等马。规则是有三轮比赛,每一匹马只能在一轮中使用。单轮胜者从失败者那里获得两百银元。 因为齐王是齐国最有权势的人,齐王有很好的马,在每类赛马中他的马都比田忌的马好。因此,每次都是齐王赢田忌六百银元。 田忌为此很不高兴,直到他遇见了孙膑,孙膑是中国历史上最有名的军事家之一。由于孙膑使用...

百般回首曾经的相遇,留下的只是一缕残忆 1550

【FPGA教程案例89】编译码2——使用vivado核实现RS信道编译码

RS编码,又称里所码,即Reed-solomon codes,是一种前向纠错的信道编码,对由校正过采样数据所产生的多项式有效。当接收器正确的收到足够的点后,它就可以恢复原来的多项式,即使接收到的多项式上有很多点被噪声干扰失真。

FPGA/MATLAB学习教程/源码/项目合作开发 3550

1052 Tian Ji -- The Horse Racing

题目详情: 题目大意: 田忌和国王赛马看谁的马快,匹数均为n,田忌每赢国王一局,+200元,输一局-200元,平局+0元, 问如何安排比赛马的出场比赛顺序可以使田忌尽可能多赢钱。 解题思路: 先把田忌的马和国王的马分别降序排序,如果田忌的快马比国王的快马快,则胜局+1,否则, 拿田忌的慢马和国王的慢马比较,慢马能赢就赢,如果田忌的慢马输了再拿田忌的慢马和国王的快马进行比较,这里贪心比较明显,用自己最慢的马去浪费对方最快的马,反正走到这步肯定没有马可以跑赢对面的快马,干脆拿...

m0_52796585的博客 733

利用PaddleOCR识别增值税发票平台验证码(开箱即用)

下面直接讲解利用paddleocr识别的思路,为什么使用paddleocr,因为paddle中集成了较好的ocr文字识别模型,开箱即用即可,废话不多说,剑指主题,识别思路步骤如下。

码王吴彦祖的博客 5553

OpenCV开发笔记(〇):使用mingw530_32编译openCV3.4.1源码,搭建Qt5.9.3的openCV开发环境

欢迎技术交流和帮助,提供IT相关服务,索要源码请联系博主QQ: 21497936,若该文为原创文章,未经允许不得转载 原博主博客地址:https://blog.csdn.net/qq21497936 本文章博客地址:https://blog.csdn.net/qq21497936/article/details/79641510 目录 OpenCV开发笔记(一):使用mingw530_32编译...

长沙红胖子 Qt・西安|省级科研团队从业背景,深耕双一流体系高精尖技术配套研发|剥离高精尖机理,沉淀高端特种行业领域 Qt 工程化落地经验|博文仅分享通用技术总结,输出公开普适工程思路。 5万+

【杭电oj】1052 - Tian Ji -- The Horse Racing(田忌赛马,贪心 & 双端队列)

Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 25177    Accepted Submission(s): 7348 Problem Description

wyg1997 1194

uniapp(vue3):实现手机拍照或相册图片上传后给图片添加水印,uniapp实现多端图片上传、拍照上传自定义插入水印内容,调用手机摄像头打开相机并在周围悬挂自定义水印(支持文字水印/图片水印等)

uni-app,h5移动端网页,微信小程序,支付宝小程序,Android安卓,苹果ios,app,nvue,uni-app为图片添加自定义水印(解决生成图片不全问题),uniapp上传图片添加水印,uniapp H5实现手机拍照或相册上传图像并添加自定义水印,uniapp水印相机,uni-app为图片添加自定义水印,怎么在图片上加水印,图片水印,上传照片带水印,从相册选择图片加水印功能,拍完照片给图片加水印,添加照片水印,uniapp图片加水印,为图片添加自定义水印,uni-app上传图片并添加水印,上传图

✅ 精选推荐文章 3271

hdu 1052 Tian Ji -- The Horse Racing

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1052   题目描述: Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13

心之所向,无惧无悔! 1572

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

hdu1052——Tian Ji -- The Horse Racing

Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 19020    Accepted Submission(s): 5557 Problem Description H

Alex 1231

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

HDOJ 1052 Tian Ji -- The Horse Racing

Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 26223    Accepted Submission(s): 7726 Problem Description H

A_ice 507

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

hdu1052 Tian Ji -- The Horse Racing (贪心)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1052 Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Jav...

3308
上一篇: A Knight's Journey [dfs]
下一篇: 免费馅饼 [dp]
畅小卓
博客等级 码龄15年 78粉丝 252原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值