题意:田忌和齐王有n匹马,进行n局比赛,每局比赛输者给胜者200,问田忌最多能得多少钱。

分析:如果田忌最下等的马比齐王最下等的马好,是没必要拿最下等的马和齐王最好的马比的。(最上等马同理)

因此,如果田忌最下等的马>齐王最下等的马或者田忌最上等的马>齐王最上等的马,直接得200,如果不满足该条件,那么才让田忌最下等的马与齐王最上等的马来比。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {, , -, };
const int dc[] = {-, , , };
const int MOD = 1e9 + ;
const double pi = acos(-1.0);
const double eps = 1e-;
const int MAXN = + ;
const int MAXT = + ;
using namespace std;
deque<int> a, b;
int main(){
int n;
while(scanf("%d", &n) == ){
if(n == ) return ;
a.clear();
b.clear();
int x;
for(int i = ; i < n; ++i){
scanf("%d", &x);
a.push_back(x);
}
for(int i = ; i < n; ++i){
scanf("%d", &x);
b.push_back(x);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int ans = ;
while(n--){
if(a.front() > b.front()){
ans += ;
a.pop_front();
b.pop_front();
}
else if(a.back() > b.back()){
ans += ;
a.pop_back();
b.pop_back();
}
else{
if(a.front() < b.back()){
ans -= ;
a.pop_front();
b.pop_back();
}
}
}
printf("%d\n", ans);
}
return ;
}

POJ 2287 Tian Ji -- The Horse Racing(贪心)的更多相关文章

  1. (贪心5.1.2)POJ 2287 Tian Ji -- The Horse Racing

    /* * POJ_2287.cpp * * Created on: 2013年10月9日 * Author: Administrator */ #include <iostream> #i ...

  2. POJ-2287.Tian Ji -- The Horse Racing (贪心)

    Tian Ji -- The Horse Racing Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 17662   Acc ...

  3. hdu_1052 Tian Ji -- The Horse Racing 贪心

    Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  4. HDU 1052 Tian Ji -- The Horse Racing(贪心)

    题目来源:1052 题目分析:题目说的权值匹配算法,有点误导作用,这道题实际是用贪心来做的. 主要就是规则的设定: 1.田忌最慢的马比国王最慢的马快,就赢一场 2.如果田忌最慢的马比国王最慢的马慢,就 ...

  5. UVaLive 3266 Tian Ji -- The Horse Racing (贪心)

    题意:田忌赛马,每胜一局就得200,负一局少200,问最多得多少钱. 析:贪心,如果最快的马比齐王的还快,就干掉它,如果最慢的马比齐王的马快,就干掉它,否则用最慢的马去和齐王最快的马比. 代码如下: ...

  6. HDU-1052 Tian Ji -- The Horse Racing 贪心 考虑特殊位置(首尾元素)的讨论

    题目链接:https://cn.vjudge.net/problem/HDU-1052 题意 田忌赛马问题扩展版 给n匹马,马的能力可以相同 问得分最大多少 思路 贪心做得还是太少,一开始一点思虑都没 ...

  7. UVa LA 3266 - Tian Ji -- The Horse Racing 贪心,不只处理一端,也处理另一端以理清局面 难度: 2

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  8. 【OpenJ_Bailian - 2287】Tian Ji -- The Horse Racing (贪心)

    Tian Ji -- The Horse Racing 田忌赛马,还是English,要不是看题目,我都被原题整懵了,直接上Chinese吧 Descriptions: 田忌和齐王赛马,他们各有n匹马 ...

  9. 【贪心】[hdu1052]Tian Ji -- The Horse Racing(田忌赛马)[c++]

    Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...

随机推荐

  1. UVA 1069 - Always an integer(数论)

    1069 - Always an integer 题意:给定一个多项式,推断是否总是整数 思路:LRJ大白上的例题,上面给出了证明,仅仅要1到k + 1(k为最高次数)带入方程都是整数,那么整个方程就 ...

  2. Creating Your Own Server: The Socket API, Part 1

    转:http://www.linuxforu.com/2011/08/creating-your-own-server-the-socket-api-part-1/ By Pankaj Tanwar  ...

  3. 遍历List remove方法,雨露均沾

    /** * 要求:去掉List中为 0 的元素 */ //创建数组和空List Integer[] ars = {1,0,0,0,5,0,8,9,0,0,0,65,3,0,0}; List<In ...

  4. eclipse[downloads]

    下载J2EE:http://www.eclipse.org/downloads/ 下载WPT插件:http://download.eclipse.org/webtools/updates 下载TOMC ...

  5. Redis操作的封装类

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using ServiceS ...

  6. NSDate简单介绍

    NSDate简单介绍 一:NSDate是一个日期\时间方面的类,主要用来创建\获取时间 1.NSDate对象的创建: date 创建一个当前系统日期和时间的对象 dateWithTimeInterva ...

  7. Zendstudio 9.0.2 安装Aptana3 并且配置 jQuery

    Zendstudio 9.0.2 安装Apnata3 并且配置 jQuery aptana-javascript-jquery.ruble文件夹下载地址: http://dl.dbank.com/c0 ...

  8. hdu 4711 动态规划

    思路:其实这题是个挺水的动态规划,一开始就能AC,可是不知道错哪了,瞎改瞎交,WA了数十次.AC之后怎么改都是AC,也不知道改了什么地方,郁闷死了~~~难道开始时的测试数据有问题??? dp[i][j ...

  9. 关于ios项目沙盒中的文件和Xcode项目创建的文件

    //1.1获取在Xcode项目打开的情况下创建的Plist文件 NSString *path = [[NSBundle mainBundle]pathForResource:@"Profes ...

  10. 【转】关于loadrunner中设置进程和线程的区别

    loadrunner中,在进行运行设置中有一项选择,是按进程运行Vuser或按线程运行Vuser?下面进行分别来讲: 1.按进程运行Vuser:Controller将使用驱动程序mdrv运行Vuser ...