hdu1052——Tian Ji -- The Horse Racing

PXE 批量安装 Ubuntu 20.04 原文链接:https://www.cpweb.top/1698 一、介绍   Ubuntu 20.04 的服务器安装程序支持新的操作模式:自动安装(automated installation)。自动安装可以通过自动安装配置提前回答所有这些配置问题,并使安装过程无需任何交互即可运行。   在 Ubuntu 18.04 中,用的应答文件是 preseeds(预配置文件),它基于 debian-installer(aka di)来实现自动安装的。需要注意的是,如果你使用的是 cobbler,那你应.... 阅读详情

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
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
 

Source
 

Recommend
JGShining   |   We have carefully selected several similar problems for you:   1050  2037  1045  1800  1257 
 

Statistic | Submit | Discuss | Note


贪心

      如果田忌最快的马比国王最快的马要快,那么直接比

      如果田忌最快的马比国王最快的马要慢,那么用田忌最慢的马去和国王最快的马比,(反正一定要输一场,而田忌最快的马可能还能在其他比赛中胜出,所以用田忌最慢的去比至少不会吃亏)

      如果田忌最快的马和国王最快的马一样快,那么要分情况

      A.如果田忌最慢的马的速度小于国王最慢的马,那么就用田忌最慢的马去和国王现在最快的马比(因为田忌最慢的马现在一场也赢不了,所以还不如来抵抗国王最快的,留下自己最快的可能还能在其他比赛中胜出)

      B.如果田忌最慢的马速度和国王最慢的马的速度一样,那么此时,我们还是应该用这匹最慢的马去和国王最快的马比(如果是快对快,慢对慢这样比,虽然不会亏,但是田忌最快的马已经用掉,不可能在去盈利,而如果是用田忌最慢的马去和国王最快的马比,虽然这里可能吃亏了,但是存在一种情况,即使田忌最快的马在面对除国王最慢以外的其他马时,无法盈利,但是此时田忌最快的马面对国王最慢的马时,至少不会吃亏,所以2种策略对比,后者更可取,因为除上述情况外, 田忌还是可能获利的)

       C. 如果田忌最慢的马的速度大于国王最慢的马,那么就应该用田忌最慢的马去和国王最慢的马比(这里至少可以获利,去除所有C的情况,我们把情况转化为A,B,即使采取A,B策略亏本了(面对国王最快的马然后输掉比赛),C策略下的盈利还是大于等于亏本的)


#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1010;
int tianji[N], king[N];

int main()
{
	int n;
	while (~scanf("%d", &n), n)
	{
		for (int i = 0; i < n; ++i)
		{
			scanf("%d", &tianji[i]);
		}
		for (int i = 0; i < n; ++i)
		{
			scanf("%d", &king[i]);
		}
		sort(tianji, tianji + n);
		sort(king, king + n);
		int king_max = n - 1, tianji_min = 0, king_min = 0;
		int ans = 0, i = n - 1;
		while (i >= tianji_min && king_max >= king_min)
		{
			if (tianji[i] > king[king_max])
			{
				ans += 200;
				king_max--;
				i--;
			}
			else if (tianji[i] < king[king_max])
			{
				king_max--;
				tianji_min++;
				ans -= 200;
			}
			else
			{
				if (tianji[tianji_min] < king[king_min])
				{
					king_max--;
					tianji_min++;
					ans -= 200;
				}
				else
				{
					for (int j = tianji_min; j < n; ++j)
					{
						if (tianji[j] > king[king_min])
						{
							ans += 200;
							king_min++;
						}
						else
						{
							tianji_min = j;
							if (tianji[tianji_min] < king[king_max])
							{
								ans -= 200;
							}
							king_max--;
							tianji_min++;
							break;
						}
					}
				}

			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


PX4飞控神经网络控制:从仿真到嵌入式部署实战 神经网络控制正逐步革新传统PID在无人机领域的统治地位。通过将深度学习模型部署到PX4飞控硬件,实现了从传感器数据直接生成电机指令的端到端控制。这种架构依赖TensorFlow Lite Micro等轻量级推理框架,在STM32等嵌入式处理器上可达到93μs级推理速度。关键技术突破包括:基于NVIDIA Isaac Gym的高效仿真训练、模型量化压缩技术(如8位整数量化)、以及与PX4原生安全架构的无缝集成。该方案在mRobotics Pixracer Pro等硬件上验证了可行性,为无人机姿态控制、视觉导航 阅读详情

相关推荐

别再死记硬背了!用Wireshark抓包实战,5分钟搞懂GRE、L2TP、IPsec的区别

本文通过Wireshark抓包实战,详细解析GRE、L2TP和IPsec三大隧道协议的核心差异与应用场景。从报文结构到配置示例,帮助网络工程师快速掌握这些协议的本质,提升VPN部署与故障排查能力。特别适合准备HCIP认证的工程师深化理解。

weixin_30352645的博客 441

1052 Tian Ji -- The Horse Racing 田忌赛马 贪心算法

/如果我方慢的大,直接吃了对方,比完后田忌最慢的马被消耗了。}else{//假如田忌最慢的马全宇宙最慢,则只能拿去当炮灰,消耗国王最快的马。}else{//表示田忌最快的马更快,则直接赢过往最快的马。//假如相等,则田忌不知道拿最慢的马去和国王最慢的马比,// total-=200;4.当田忌最快的马比齐王最快的马慢时,拿最慢的马和齐王最快的马比,输一场。5.当田忌最快的马和齐王最快的马相等时,拿最慢的马来和齐王最快的马比.马和最慢的马都相等,再来考虑把田忌最慢的马和齐王最快的马比较。

m0_72431373的博客 545

QGC二次开发实战指南(一):从零构建自定义地面站界面

本文详细介绍了QGC二次开发实战指南,从零开始构建自定义地面站界面。通过QT和QML技术结合MAVLINK协议,开发者可以打造适合特定业务场景的无人机监控系统,提升操作效率与用户体验。文章包含环境搭建、界面设计、数据绑定等完整开发流程,是QGC二次开发的实用教程。

weixin_28693683的博客 499

ACMSTEP 1.3.3 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):

天道酬勤 1360

PMAC上位机通信原理(C#)

基础是引用 两个 ODT dll 原理是先注册到communication.AsyncDataAvailable事件中去 if (bSuccess1) { communication.AsyncDataAvailable += communication_AsyncDataAvailable; } bool bSuccess2 = communication1.GPAsciiConnect(strIP, iPort, strName, strPassword); i

weixin_45507349的博客 1092

使用everything出现mem_virtual_alloc(): Fatal Error: out of memory解决方案

本文主要介绍了使用everything出现mem_virtual_alloc(): Fatal Error: out of memory解决方案,希望能对使用everything的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 1万+

hdu-1052Tian 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): 15678    Accepted Submission(s): 4529 Problem De

Just do IT! 826

资源分享·病毒样本下载资源分享

一、微步云沙箱 微步在线云沙箱https://s.threatbook.cn/ 使用病毒sha256即可寻找病毒样本;该站点也可上传可疑文件/可疑URL地址到沙箱中,进行分析 。 以永恒之蓝为例,样本sha256是:ed01ebfbc9eb5bbea545af4d01bf5f1071661840480439c6e5babe8e080e41aa 下载样本或流量监控,需要消耗积分: 二、AnyRun Interactive Online Malware Analysis Sandbox.

不忘初心,护天下安全! 2万+

【杭电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

AutosarMCAL开发——基于EB MCU驱动

本文为博主个人学习总结记录,如有不正,欢迎指正。

qq_45583706的博客 925

STM32入门教程:无人机控制

我们将会一步一步引导您完成无人机的控制代码,包括无人机的姿态控制、飞行控制和通信控制等。第三步:配置无人机姿态控制 无人机的姿态控制是指控制无人机在空中的倾斜和转向。为了实现姿态控制,我们需要使用加速度计和陀螺仪传感器来获取无人机的姿态信息,并使用PID控制算法来控制无人机的姿态。在这一步骤中,您需要根据您使用的具体传感器和控制算法的要求进行更详细的配置和编码。在通信控制中,您需要考虑到通信的稳定性和可靠性。第五步:通信控制 无人机的通信控制是指与地面站或其他设备进行通信,传输飞行数据和接收飞行指令。

m0_75244442的博客 751

【杭电1052】Tian Ji -- The Horse Racing

应该算是贪心里的思维题,这种题没有固定的模板,选对贪心的标准就对了,本题标准就是每一步都要尽可能的为下一步的比赛创造赢的条件。#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int ti[1002],ki[1002],c[1002]; int main() { int T=50;

better_space的博客 650

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

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

心之所向,无惧无悔! 1573

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

hdu1052-Tian Ji -- The Horse Racing

http://acm.hdu.edu.cn/showproblem.php?pid=1052 这题容易被题目里面所说的二分匹配误导,其实就是利用贪心的思想来做; 下面解释是直接转的,因为我怕我描写的可能不是很清楚,下面那个描写很详细,逻辑也非常缜密 /* HDU 1052 一、如果a的最慢速度大于b的最慢,则直接a的最慢与b的最慢比赛,赢一场; 二、如果a的最慢速度小于b的最慢,则用

bo-jwolf的专栏 959

Statistics and Machine Learning Toolbox

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

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

HDU1052:Tian Ji -- The Horse Racing

Problem Description 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 an

ACM!荣耀之路! 2334

[HDU1052]Tian Ji -- The Horse Racing[贪心]

题目链接:[HDU1052]Tian Ji -- The Horse Racing[贪心] 题意分析:国王和田忌赛马,如果田忌胜利则他将得200银元,如果失败则失去200银元,如果平手,那么一毛也得不到XD。问:怎样使田忌得到的银元最多? 解题思路:首先对两人的赛马进行按速度从小到大排序。从田忌的第一匹马开始,如果这匹马注定失败,那么让这匹马与国王最厉害的马去比赛;如果这匹马并不是注定失败(还

闲停 613

HDU1052——Tian Ji -- The Horse Racing

http://acm.hdu.edu.cn/showproblem.php?pid=1052 这道题用的是贪心策略, 将双方的马按照速度排序,从小到大,最大的先比, 如果能赢就赢,不能的话就比较两个小的,能赢就赢,不能的话就用这个弱马消耗那个速度快的马。 策略就是我要尽量赢,不能赢就拿弱马消耗。 #include<cstring> #include<cm...

aozhe0658的博客 131

HDU 1052 Tian Ji -- The Horse Racing

Tian Ji -- The Horse RacingTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4184    Accepted Submission(s): 1100Problem DescriptionHere is

-- bird -- 1577

Hdu1052 Tian Ji -- The Horse Racing

Problem Description 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

Megumin的博客 445

HDU 1052 Tian Ji -- The Horse Racing

Description 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 othe

u013087645的专栏 909

HDU1052Tian 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): 32276    Accepted Submission(s): 9803 Problem Des

←_← 337

【杭电】HDU 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): 26252 Accepted Submission(s): 7735Problem Description Here is a

楚江枫 665

hdu-1052 Tian Ji -- The Horse Racing

HOT!!! 欢迎参加“金山西山居-2013创意游戏程序挑战赛”! Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13712    Accepted Su

起航 591

HDU 1052Tian 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): 20809 Accepted Submission(s): 6081 Problem Description Here

小寒 443

HDU 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): 38958    Accepted Submission(s): 11672 Problem Description Here ...

YIU 261
上一篇: hdu3339——In Action
下一篇: hdu2059——龟兔赛跑
tokers
博客等级 码龄12年 71粉丝 700原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值