题意:田忌和齐王有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. vsftpd虚拟用户创建实例(转载)

    vsftpd虚拟用户创建实例 发布:theboy   来源:net     [大 中 小] vsftpd虚拟用户创建实例,有需要的朋友可以参考下.  vsftpd虚拟用户创建实例,有需要的朋友可以参考 ...

  2. Game: Map Design Considerations 游戏地图设计指南

    依据前文伏击战场景手稿, 用Tile Studio "草草"制作出该场景的地图: 生成的C源码: #ifndef _open_war_1Gfx_c #define _open_wa ...

  3. 两种方式连接mysql

    一种方式:运行命令符后,mysql -u root -p(如果不成功,说明环境变量没配,命令行到 mysql的bin目录下,然后运行mysql -u root -p 应该成功了) 另外一种方式,直接有 ...

  4. Using ASP.Net WebAPI with Web Forms

    Asp.Net WebAPI is a framework for building RESTful HTTP services which can be used across a wide ran ...

  5. jquery . fancybox()

    1.父页面 function chooseTopic(btn) {//选择议题 $.fancybox({ type : 'iframe', href : '', fitToView : false, ...

  6. Windows下memcache安装使用

    Windows下Memcache安装 随着时间的推移,网上现在能找到的在 Windows下安装 Memcache 的文档大多已经过时.雪峰这里再简要介绍一下当下最新版的安装和配置方法. Memcach ...

  7. C# 使用代码来操作 IIS

    由于需要维护网站的时候,可以自动将所有的站点HTTP重定向到指定的静态页面上. 要操作 IIS 主要使用到的是“Microsoft.Web.Administration.dll”. 该类库不可以在引用 ...

  8. mysql模糊查询 like/REGEXP

    原文:mysql模糊查询like/REGEXP 增删改查是mysql最基本的功能,而其中查是最频繁的操作,模糊查找是查询中非常常见的操作,于是模糊查找成了必修课. like模式 like意思是长得像, ...

  9. React Native教程 - 调用Web API

    react-native官网Fetch介绍:https://facebook.github.io/react-native/docs/network.html#content react-native ...

  10. 【递归】数字三角形 简单dp

    [递归]数字三角形 题目描述 对于大多数人来说,“我们是这么的正常,因此也就这么的平庸.”而天才总是与众不同的,所以当邪狼问修罗王:“老大,你蹲在那儿一动不动看了有半个小时了,蚂蚁有那么好看吗?” 修 ...