题意:田忌和齐王有n匹马,进行n局比赛,每局比赛输者给胜者200,问田忌最多能得多少钱. 分析:如果田忌最下等的马比齐王最下等的马好,是没必要拿最下等的马和齐王最好的马比的.(最上等马同理) 因此,如果田忌最下等的马>齐王最下等的马或者田忌最上等的马>齐王最上等的马,直接得200,如果不满足该条件,那么才让田忌最下等的马与齐王最上等的马来比. #pragma comment(linker, "/STACK:102400000, 102400000") #include<…
/* * POJ_2287.cpp * * Created on: 2013年10月9日 * Author: Administrator */ #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; int main() { int n; int a[1010]; int b[1010]; while (scanf(&qu…
Tian Ji -- The Horse Racing Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 17662   Accepted: 5452 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 Q…
Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 40477    Accepted Submission(s): 12148 Problem Description Here is a famous story in Chinese history. "That was about…
题目来源:1052 题目分析:题目说的权值匹配算法,有点误导作用,这道题实际是用贪心来做的. 主要就是规则的设定: 1.田忌最慢的马比国王最慢的马快,就赢一场 2.如果田忌最慢的马比国王最慢的马慢,就让这两匹马比一场,输一场 3.如果田忌最慢的马和国王最慢的马相等,就看 如果田忌最快的马比国王最快的马快,那就比一场,赢 如果田忌最快的马比国王最快的马慢,就让最慢的马和国王最快的马比一场,这一场输 如果田忌最快的马和国王最快的马相等,就看田忌最慢的马是否比国王最快的马慢,如果是,输一场,否则就是所…
题意:田忌赛马,每胜一局就得200,负一局少200,问最多得多少钱. 析:贪心,如果最快的马比齐王的还快,就干掉它,如果最慢的马比齐王的马快,就干掉它,否则用最慢的马去和齐王最快的马比. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cma…
题目链接:https://cn.vjudge.net/problem/HDU-1052 题意 田忌赛马问题扩展版 给n匹马,马的能力可以相同 问得分最大多少 思路 贪心做得还是太少,一开始一点思虑都没有的 这里稍微总结一下如何打开思路吧 从特殊位置开始考虑是否存在某种必然性,包括不限于序列首尾 若讨论难以进行,试着把这个讨论点展开,换个角度(或者换个特殊位置)讨论 首先排序 其次的关键是讨论尾元素是否必胜或必败,思考贪心 在一个关键是双方尾元素相同时,展开考虑首元素是否必胜或必败,思考贪心 当首…
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1267 题意 田忌赛马,问最多能赢到多少钱?每局200元 思路 明显,把田忌的赛马排列一下,从速度高到低,齐王的也从高到低排列,当前田忌最高的赛马无法处理齐王最高的赛马,则换成田忌最慢的赛马去碰瓷. 难在如何处理平局-也就是速度相同的赛马. 有的时候本可以平局,但是最好先…
Tian Ji -- The Horse Racing 田忌赛马,还是English,要不是看题目,我都被原题整懵了,直接上Chinese吧 Descriptions: 田忌和齐王赛马,他们各有n匹马,依次派出一匹马比赛,赢了加200,输了减200,平局不加钱,问如何安排马的出场顺序,使得田忌赢的钱最多 Input 输入最多包含 50 组测试数据.对于每组测试数据,第一行包括一个正整数 n (n ≤ 1000),表示每一方的马的数目.第二行中的 n 个整数,表示田忌的马的速度.第三行中的 n 个…
Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) 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 cou…
算法分析: 这个问题很显然可以转化成一个二分图最佳匹配的问题.把田忌的马放左边,把齐王的马放右边.田忌的马A和齐王的B之间,如果田忌的马胜,则连一条权为200的边:如果平局,则连一条权为0的边:如果输,则连一条权为-200的边. 然而我们知道,二分图的最佳匹配算法的复杂度很高,无法满足N=2000的要求. 我们不妨用贪心思想来分析一下问题.因为田忌掌握有比赛的“主动权”,他总是根据齐王所出的马来分配自己的马,所以这里不妨认为齐王的出马顺序是按马的速度从高到低出的.由这样的假设,我们归纳出如下贪心…
Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11572    Accepted Submission(s): 3239 Problem Description Here is a famous story in Chinese history. "That was about 2…
Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 41290 Accepted Submission(s): 12427 Problem Description Here is a famous story in Chinese history. "That was about 2300…
思路:先按从小到大排序, 然后从最快的開始比(如果i, j 是最慢的一端, flag1, flag2是最快的一端 ),田的最快的大于king的 则比較,如果等于然后推断,有三种情况: 一:大于则比較,二等于在推断田的最慢的是不是比king的最快的慢,三小于则与king的最快的比較: Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe…
Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 18291    Accepted Submission(s): 5327 Problem Description Here is a famous story in Chinese history. "That was about 2…
Tian Ji -- The Horse Racing Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 19   Accepted Submission(s) : 5 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description Here is a…
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 and the king have three…
Tian Ji -- The Horse Racing HDU - 1052 (有平局的田忌赛马,田忌赢一次得200块,输一次输掉200块,平局不得钱不输钱,要使得田忌得到最多(如果只能输就输的最少)) 首先,实际是要求两人马的配对关系.那么不妨设齐王是按从快到慢的顺序出马的.因此先将齐王的马排序. 关键在于田忌最慢的马,能先赢就先赢,不能赢就去消耗齐王最快的马,然后再来考虑最快的马,能先赢就先赢,不能赢说明现在田忌和齐王最快的马和最慢的马都相等,再来考虑把田忌最慢的马和齐王最快的马比较. 可以…
Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 37056    Accepted Submission(s): 11153 Problem Description Here is a famous story in Chinese history. "That was about…
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1052">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): 17346    Acc…
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): 18058    Accepted Submission(s): 5239 Problem Description Here is a f…
Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 37436    Accepted Submission(s): 11248 Problem Description Here is a famous story in Chinese history. "That was about…
Tian Ji -- The Horse Racing Time Limit: 5 Seconds      Memory Limit: 32768 KB 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 kin…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1052 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…
题意: 田忌和齐王各有n匹马,如果马的速度比齐王的快就赢200,慢则输200,相等不赔不赚. 已知两人每匹马的速度(为整数)和齐王所排出的马的顺序,问田忌该如何应对才能使收益最大. 分析: 本以为是一道很简单的贪心,上来就贪,结果什么都没贪出来. 看了题解才发现贪心是比较复杂的. 这里贴上poj某牛的神分析. 贪心策略: 1,如果田忌的最快马快于齐王的最快马,则两者比. (因为若是田忌的别的马很可能就赢不了了,所以两者比) 2,如果田忌的最快马慢于齐王的最快马,则用田忌的最慢马和齐王的最快马比.…
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,…
题目链接 题意 两人赛马,每居获胜得200,平局无事发生,输了也输200.求最优的策略使赢的钱最多. 分析 排序,从最快的开始比,若比不过,则用最弱的消耗最强的.模拟即可. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<algorithm> #include<cstring> #include <queue> #…
题目 这道题主要是需要考虑到各种情况:先对马的速度进行排序,然后分情况考虑: 1.当田忌最慢的马比国王最慢的马快则赢一局 2.当田忌最快的马比国王最快的马快则赢一局 3.当田忌最快的马比国王最快的马慢 则用田忌最慢的马和国王最快的马比,输一局 4.当他们最快的马相等时则用 田忌最慢的马和国王最快的马比.[因为自己后面的队友很有可能战胜此时对方的这匹慢马,所以就算自己输一场,队友也能帮忙赢回一场,而胜一场,输一场的收益和打平一场的收益是一样的,而且自己输的时候可以拉对方最快的马下水,给己方最快的马…
题目大意:田忌赛马问题,给出田忌和齐威王的马的数量$n$和每匹马的速度$v$,求田忌最多赢齐威王多少钱(赢一局得200,输一局扣200,平局不得不扣). 思路:贪心. 1.若田忌最慢的马可以战胜齐王最慢的马,那么就让它战胜那匹慢马,胜利场次加1.(田忌最慢马 > 齐王最慢马) 2.若田忌最慢的马不能战胜齐王最慢的马,那么它更加不能战胜其他的马,那就让它输给齐王最快的马,失败场次加1.(田忌最慢马 < 齐王最快马) 3.若田忌最慢的马与齐王最慢的马速度相等.此时,打平是错误的. 因为自己的快马很…
#include<iostream> #include<cmath> #include<algorithm> #define REP(i,n) for(int i=0;i<(n);i++) using namespace std; ],b[],n; int main(){ while (cin>>n,n){ REP(i,n)cin>>a[i]; REP(i,n)cin>>b[i]; sort(a,a+n); sort(b,b+n…