/* * 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…
题意:田忌和齐王有n匹马,进行n局比赛,每局比赛输者给胜者200,问田忌最多能得多少钱. 分析:如果田忌最下等的马比齐王最下等的马好,是没必要拿最下等的马和齐王最好的马比的.(最上等马同理) 因此,如果田忌最下等的马>齐王最下等的马或者田忌最上等的马>齐王最上等的马,直接得200,如果不满足该条件,那么才让田忌最下等的马与齐王最上等的马来比. #pragma comment(linker, "/STACK:102400000, 102400000") #include<…
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: 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…