题意:田忌赛马,每胜一局就得200,负一局少200,问最多得多少钱。

析:贪心,如果最快的马比齐王的还快,就干掉它,如果最慢的马比齐王的马快,就干掉它,否则用最慢的马去和齐王最快的马比。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#define debug() puts("++++");
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e3 + 5;
const int mod = 2000;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int a[maxn], b[maxn]; int main(){
while(scanf("%d", &n) == 1 && n){
for(int i = 0; i < n; ++i) scanf("%d", a+i);
for(int i = 0; i < n; ++i) scanf("%d", b+i);
sort(a, a + n, greater<int>());
sort(b, b + n, greater<int>());
int ans = 0;
int fro1 = 0, fro2 = 0;
int rear1 = n-1, rear2 = n-1;
while(fro1 <= rear1){
if(a[fro1] > b[fro2]){
ans += 200;
++fro1;
++fro2;
}
else if(a[rear1] > b[rear2]){
ans += 200;
--rear1;
--rear2;
}
else if(a[rear1] <= b[rear2]){
if(a[rear1] < b[fro2]) ans -= 200;
--rear1;
++fro2;
}
}
printf("%d\n", ans);
}
return 0;
} /*
3
15 12 9
16 13 9 5
7 8 9 12 15
7 8 9 13 16 4
1 2 4 5
2 3 3 4
*/

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

  1. UVALive - 3266 Tian Ji -- The Horse Racing(贪心)

    题目链接 题意 两人赛马,每居获胜得200,平局无事发生,输了也输200.求最优的策略使赢的钱最多. 分析 排序,从最快的开始比,若比不过,则用最弱的消耗最强的.模拟即可. #include<i ...

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

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

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

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

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

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

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

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

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

  7. 【贪心】[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 ...

  8. HDU 1052 Tian Ji -- The Horse Racing【贪心在动态规划中的运用】

    算法分析: 这个问题很显然可以转化成一个二分图最佳匹配的问题.把田忌的马放左边,把齐王的马放右边.田忌的马A和齐王的B之间,如果田忌的马胜,则连一条权为200的边:如果平局,则连一条权为0的边:如果输 ...

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

随机推荐

  1. java 对象变量 c++对象指针 初始化对象变量的2中方法

    java 对象变量 c++对象指针 java null引用 c++ null指针 Date deadline  是 对象变量,它可以引用Date类型的对象,但它不是一个对象,实际上它也没有引用对象. ...

  2. lvs虚拟服务器

    NAT模式 1.模拟环境: LVS服务器有两块网卡,连接外网(用户端)和内网(服务器),充当"交警"角色. 优点: 节省ip开销 缺点: LVS服务器负载过高,数据吞吐量降低 三台 ...

  3. json (js对象标记)

    基础 JSON: JavaScript Object Notation (JavaScript对象表示法) 网络媒体类型是 application/json,文件名扩展是 .json JSON 独立于 ...

  4. 【docker】学习笔记一:制作自己的centos6.9镜像

    前言: 最近开始研究docker,在这里做一个记录. 本来开始想用centos7系列做镜像,毕竟是最新版本的centos,但是centos7有一个严重的bug,就是正常启动的镜像不能使用systemc ...

  5. Java for LeetCode 111 Minimum Depth of Binary Tree

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  6. iOS本地数据存取,看这里就够了

    本文授权转载,作者:hosea_zhou(简书) 应用沙盒 1)每个iOS应用都有自己的应用沙盒(应用沙盒就是文件系统目录),与其他文件系统隔离.应用必须待在自己的沙盒里,其他应用不能访问该沙盒 2) ...

  7. IIS反向代理实现Revel域名访问

    Revel实现域名访问 1.在cmd中启动revel项目,我设置的端口为8000 2.下载IIS的Application Request Routing Cache组件下载地址 3.安装ARR 4.打 ...

  8. 51Nod 1294 修改数组 —— LIS

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1294 1294 修改数组  题目来源: HackerRank ...

  9. c#使用itextsharp输出pdf(动态填充表单内容,显示中文)

    相关链接: iText的简单应用-字体 c#程序为PDF文件填写表单内容 示例代码: static void Main(string[] args) { BaseFont font = BaseFon ...

  10. c语言学习的第12天

    #include <stdio.h> int main(void) { int *p; int i=5; char ch='A'; p=&i; *p=99; printf(&quo ...