hdu 1052 Tian Ji -- The Horse Racing

基于Python+OpenCV中文及符号检测 一、项目背景与意义在图像处理、文档识别、自动翻译等场景中,中文及符号的准确检测是一个重要且复杂的任务。传统的字符检测方法往往对英文等拉丁字母系的识别效果较好,但对中文及特殊符号的识别准确率较低。本项目旨在利用Python编程语言结合OpenCV库,开发一个能够高效、准确地检测图像中中文及符号的系统,为相关领域的研究和应用提供技术支撑。二、技术实现图像预处理:利用OpenCV的图像处理功能,对输入的图像进行灰度化、二值化、滤波去噪等预处理操作,以提高中文及符号检测的准确性[1]。 阅读详情

题目地址: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): 13412    Accepted Submission(s): 3775


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

 

题意:田忌赛马......问给出两列马的战斗力,问田忌最多能赚多少。

 

题解:明显贪心了,一开始自己贪心策略想简单了,想得是尽快将能将就吧大王的马赢了的就尽管赢,赢不了的马就拿去抵掉大王的那些很牛逼的马。实际上基本策略是这样贪的。

 

 

 

但根据几组实验的测试数据要注意:

一、

2
1 2
1 3

若最慢的马相等,看最快的马如果最快的马田忌比不了大王的,就用最慢的田忌马去抵掉大王的最快马

 

二、

 9
80 140 76 58 93 140 146 74 173
97 80 135 72 0 107 155 66 141

若最慢的马相等,若最快的马田忌的比大王的快,那么就让最快马比,接着放空这组最慢相等马,继续从最快比。注意这里的最慢最快都是递归的,因为,一旦一对马比完就被淘汰了,不能参加两次比赛,这样最慢 最快的马会变成另外的。所以这里的最慢最快都是递归的。

 

 

所以综合这两种测试数据 得出完整的贪心策略:(把马从大到小排序)

先从最慢的马依次比:1、田忌最慢马比大王最慢马快,直接比赛

                                        2、田忌最慢马比大王最慢马慢,让田忌最慢马与大王最快马比赛(反正它都是输,就让它输得更有价值一点,把对面的一个强劲的对手pass掉)

                                        3、田忌最慢马与大王最慢马相等:(这时放空最慢马,从最快马来讨论)

                                                            (1)、田忌最快马比大王最快马快,直接比赛

                                                            (2)、田忌最快马比大王最快马慢,让刚才的田忌最慢马与大王最快马比赛

                                                            (3)、田忌最快马与大王最快马相等,让刚才的田忌最慢马与大王最快马比赛

按照这样的策略将所有马都比一次就是田忌能赚最多的钱了,即最优方案。

 

关于贪心策略的证明:(还没想好,等想好再写 标记下###########################################)

 

代码:

/*
acm
hdu:Tian Ji -- The Horse Racing


the test data
2
1 2
1 3
 will let my program produce the WA
 
 
 9
80 140 76 58 93 140 146 74 173
97 80 135 72 0 107 155 66 141

this data also make it be WA

*/
#include<stdio.h>
#include<stdlib.h>

int n=0;

int Tian[1000+5]={0},King[1000+5]={0};

int money=0;

/*compare for the qsort*/
int qcmp(const void * a,const void * b)
{
	int * A=(int *)a;
	int * B=(int *)b;
	return(*B-*A);//from big to small
}

/*for test*/
int test()
{
	return(0);
}

/*main process*/
int MainProc()
{
	while(scanf("%d",&n)!=EOF&&n>0)
	{
		int i=0;
		money=0;
		for(i=0;i<=n-1;i++)
		{
			scanf("%d",&Tian[i]);
		}
		qsort(Tian,n,sizeof(Tian[0]),qcmp);
		for(i=0;i<=n-1;i++)
		{
			scanf("%d",&King[i]);
		}
		qsort(King,n,sizeof(King[0]),qcmp);
		int ti=n-1,ki=n-1,kj=0,tj=0;
		while(ti>=tj)
		{
			if(Tian[ti]>King[ki])
			{
				ki--;
				ti--;
				money+=200;
			}
			else if(Tian[ti]<King[ki])
			{
				money-=200;
				kj++;//the bigest has been matched
				ti--;
			}
			else//if the result is equal it may not come to a match
			{
				if(Tian[tj]>King[kj])
				{
					tj++;
					kj++;
					money+=200;
				}
				else if(Tian[tj]<King[kj])
				{
					if(Tian[ti]<King[kj])
					{
						money-=200;
					}
					ti--;
					kj++;
				}
				else
				{
					if(Tian[ti]<King[kj])
					{
						money-=200;
					}
					ti--;
					kj++;
				}
			}
		}
		printf("%d\n",money);
	}
	return(0);
}

int main()
{
	MainProc();
	return(0);
}


 

 

 

 

 

MIPI D-PHY TX 一致性测试实例解析 Part 03 本文之前,已经讨论了MIPI D-PHY TX的1.3.x和1.4.x的测试项,1.5.x的测试项相对较少,主要是用于时钟和数据通道相关的时序测量 阅读详情

相关推荐

用Multisim复刻经典收音机:从零搭建超外差中波调幅接收机(附仿真源文件)

本文详细介绍了如何使用Multisim软件从零搭建超外差中波调幅接收机,复刻经典收音机的设计过程。通过模块化搭建、稳定性优化和增益分配等实战指南,帮助读者掌握超外差架构的核心技术,并附赠仿真源文件供实践参考。

weixin_28744423的博客 475

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

一直努力 1703

cartographer基于3d地图的纯定位模式

关于纯定位模式呢,本人试过2d和3d,怎么说呢,有条件的话,建议直接上3d,因为博主当初在做定位时针对室内和室外都尝试过,2d只在室内环境下效果会很棒,但是在室外就呵呵啦!所以这里直接讲解3d室外定位(建图篇请自己查看我之前的博客:[3d建图](https://blog.youkuaiyun.com/qq_40216084/article/details/105531983) 看了我之前的博客大概知道配置文件和源文件路径了,我这里就不把路径写出来了,挺麻烦的。直接讲怎么做把,有不懂的留言,看到了我一定知无不言。 **首

qq_40216084的博客 5552

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 Tian

chutzpah 388

移动通信基础(13)TDL、CDL、信道相关性

参考《U型槽无线信道多径传播特性测量与建模方法的研究》、《5G信号源中的信道模拟与仿真研究》衰落衰落理解为信号幅度在时间和频率上的不断波动,是无线信道一个重要的恶化特性。信道幅度恶化的两个主要来源分别是加性噪声和信号衰落,高斯白噪声信道模型就是典型的加性噪声,信号衰落引起的是乘性的信号扰动,与加性噪声从原理上完全不同。信道的频率选择性衰落组为无线信道的重要特征之一,是人们进行无线系统设计考虑的重要因素,决定了导频隔间的大小。...

tybAly的博客 2万+

C语言 在合并编译 ( 多.c文件 ) 情况下 实现 linked list ( 链表 ) 教程 . 更新ing

写在前面  依旧是参考借鉴了 浙江大学 温老师 的视频教程,很不错,在中国大学MOOC上,强力推荐!  虽说有借鉴,但是能保证的是每一行代码都是我自己经过理解后手敲出来的,所以才来做了这部分的教程。  最后,带 * 字符是我个人觉得可以添加的功能,按理来讲是可以不看的,而且大概率是可以有更好的改进的。  PS: 文章还在更新,如果文字蓝了(有超链接),说明写完了,如果没蓝,说明我在开军舰.jpg 源代码:  这里→源代码. 第一步:前置工作  先说一下每一篇都会出现 main 函数的,stage1 只是给没

weixin_47287635的博客 527

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

DC综合中set_dft_signal的实战配置与优化策略

本文深入解析了DC综合中set_dft_signal命令的实战配置与优化策略。文章从命令的核心作用出发,详细拆解了-view、-type、-usage等关键参数,并通过扫描使能与时钟门控的实战案例,展示了如何正确配置以实现测试模式下的功耗优化。同时,文章总结了高级优化策略、与低功耗流程的协同方法以及常见错误排查清单,旨在帮助数字芯片设计工程师构建高可测性、低功耗的稳健DFT基础。

weixin_28347369的博客 403

Tian Ji -- The Horse Racing(贪心)

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

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

torchsparse安装

torchsparse安装以及安装失败原因分析和解决

AI_BING_的博客 1万+

OFDM接收机同步——分组检测

上一篇讲了OFDM发射机中的长短训练序列生成原理,基于此可以得到长短训练序列的准确数值,为接收机中的符号同步中的相关运算提供基础。 进入符号同步前,首先来看OFDM接收机中的第一步——分组检测。分组检测就是检测突发传输方式的信道上是否有新的数据到达,算法的好坏直接影响着接收机的后续工作性能。 一、本文意义 基于《基于xilinx fpga 的ofdm的通信系统基带设计》这本教材中分组检测算法原理,通过matlab编程仿真验证“延时相关+保持长度”分组检测算法的有效性。同时,通过仿真证明教材上的判决公式的问题

boayel的博客 2202

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 1229

labelImg使用教程

Anaconda环境 安装 Anaconda 之后,在开始菜单下找到 Anaconda 文件夹 找到 Anaconda Prompt 点击运行 安装 labelImg pip install labelImg #直接命令行输入 启动 labelImg labelImg #直接命令行输入名称即可 labelImg界面 开始标注 快捷键:W(创建方框),A(上一张),D(下一张) XML文件示例 <annotation> <folder>夜读</folder>

G果的博客 3万+

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的专栏 958

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

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

转载请注明出处:http://blog.youkuaiyun.com/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...

3300

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

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

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

闲停 613

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

HDU1052——Tian Ji -- The Horse Racing

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

aozhe0658的博客 131

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!荣耀之路! 2333

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

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的专栏 907

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

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

←_← 336

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

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

楚江枫 664

HDU 1052 Tian Ji -- The Horse Racing

Tian Ji -- The Horse Racing Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description Here is a famous story in Chinese history.  "That

※夏日星空※ 321

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 1049 Climbing Worm
下一篇: uva 592 Island of Logic
hackerwin7
博客等级 码龄14年 115粉丝 144原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值