UVALive - 3266 Tian Ji -- The Horse Racing(贪心)
题意
两人赛马,每居获胜得200,平局无事发生,输了也输200。求最优的策略使赢的钱最多。
分析
排序,从最快的开始比,若比不过,则用最弱的消耗最强的。模拟即可。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include <queue>
#include <vector>
#include<bitset>
#include<map>
#include<deque>
#include<stack>
using namespace std;
typedef pair<int,int> pii;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define ms(a,b) memset(a,b,sizeof(a))
const int inf = 0x3f3f3f3f;
const int maxn = 1e6+;
const int mod = +;
#define lson l,m,2*rt
#define rson m+1,r,2*rt+1
typedef long long ll;
int a[],b[];
int main(){
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
int n;
while(scanf("%d",&n)&&n){
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=n;i++) scanf("%d",&b[i]);
int sta=,stb=,eda=n,edb=n;
sort(a+,a++n);
sort(b+,b++n);
int ans=;
for(int i=;i<=n;i++){
if(a[eda]>b[edb]){
ans+=;
eda--;
edb--;
}else if(a[eda]<b[edb]){
ans-=;
sta++;
edb--;
}else{
if(a[sta]>b[stb]){
ans+=;
sta++;
stb++;
}else if(a[sta]<b[edb]){
ans-=;
sta++;
edb--;
}else{
sta++;
edb--;
}
}
}
printf("%d\n",ans);
}
return ;
}
UVALive - 3266 Tian Ji -- The Horse Racing(贪心)的更多相关文章
- UVaLive 3266 Tian Ji -- The Horse Racing (贪心)
题意:田忌赛马,每胜一局就得200,负一局少200,问最多得多少钱. 析:贪心,如果最快的马比齐王的还快,就干掉它,如果最慢的马比齐王的马快,就干掉它,否则用最慢的马去和齐王最快的马比. 代码如下: ...
- UVa LA 3266 - Tian Ji -- The Horse Racing 贪心,不只处理一端,也处理另一端以理清局面 难度: 2
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- POJ-2287.Tian Ji -- The Horse Racing (贪心)
Tian Ji -- The Horse Racing Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 17662 Acc ...
- 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 ...
- HDU 1052 Tian Ji -- The Horse Racing(贪心)
题目来源:1052 题目分析:题目说的权值匹配算法,有点误导作用,这道题实际是用贪心来做的. 主要就是规则的设定: 1.田忌最慢的马比国王最慢的马快,就赢一场 2.如果田忌最慢的马比国王最慢的马慢,就 ...
- HDU-1052 Tian Ji -- The Horse Racing 贪心 考虑特殊位置(首尾元素)的讨论
题目链接:https://cn.vjudge.net/problem/HDU-1052 题意 田忌赛马问题扩展版 给n匹马,马的能力可以相同 问得分最大多少 思路 贪心做得还是太少,一开始一点思虑都没 ...
- 【贪心】[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 ...
- HDU 1052 Tian Ji -- The Horse Racing【贪心在动态规划中的运用】
算法分析: 这个问题很显然可以转化成一个二分图最佳匹配的问题.把田忌的马放左边,把齐王的马放右边.田忌的马A和齐王的B之间,如果田忌的马胜,则连一条权为200的边:如果平局,则连一条权为0的边:如果输 ...
- 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 ...
随机推荐
- JHipster - Generate your Spring Boot + Angular/React applications!
JHipster - Generate your Spring Boot + Angular/React applications!https://www.jhipster.tech/
- shell of leetcode
1.Tenth Line How would you print just the 10th line of a file? For example, assume that file.txt has ...
- Delphi编程中动态菜单要点归纳
一.创建菜单并添加项目 在设计程序时,有时需要动态创建菜单, 通常使用以下的语句: PopupMenu1 := TPopupMenu.Create(Self); Item := TMenuIte ...
- Ajax+JSP登陆后带参数跳转
点击提交按钮后使用Ajax将用户名和密码传至后台校验,然后判断返回结果进行跳转或提示错误. <%@ taglib prefix="form" uri="http:/ ...
- Nginx referer防盗链模块
L75 referer模块 ngx_http_referer_module 默认编译进nginx valid_referers 指令 Syntax: valid_referers none | blo ...
- Maven环境配置及简单使用(二)
Maven环境变量配置 配置Maven前先从官网下载相关版本,Maven下载地址:http://maven.apache.org/download.cgi,笔者使用最新版本apache-maven-3 ...
- Laravel框架简单的用户管理[CURD]操作
一个基于laravel和bootstrap的简单的用户管理,适合刚入门的我们,在做的过程中可以加深自己对laravel基础理解,里面存在一些问题,还未修改,比如css和js的引入,表单提交地址等不规范 ...
- JS通过键盘点击事件实现div移动
页面内容:文本框模拟键盘点击 div元素实现移动: <body> <textarea id="myarea"></textarea> < ...
- 自学Linux Shell15.1-处理信号
点击返回 自学Linux命令行与Shell脚本之路 15.1-处理信号 Linux使用信号与系统上运行的进程进行通信.可以使用这些信号控制Shell脚本的运行,只需要让shell脚本在接收到来自Lin ...
- emwin 解决在A窗口上新建B窗口后‘只激活’B窗口问题
@2018-08-08 问题来源: 要实现A窗口上的参数修改,通过A窗口上新建的B窗口小键盘实现数据录入,但结果是只要点击A窗口上的任何地方(包括B窗口上的任意位置),则B窗口就消失了 解决办法: 使 ...