http://acm.hdu.edu.cn/showproblem.php?pid=1052

这道题用的是贪心策略,

将双方的马按照速度排序,从小到大,最大的先比,

如果能赢就赢,不能的话就比较两个小的,能赢就赢,不能的话就用这个弱马消耗那个速度快的马。

策略就是我要尽量赢,不能赢就拿弱马消耗。

#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int a[1001],b[1001],n;
int main(){while(~scanf("%d",&n)&&n!=0){memset(a,0,sizeof(a));memset(b,0,sizeof(b));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);sort(b,b+n);int x=n-1,y=0,w=0,i=n-1,j=0;while(i>=j&&x>=y){if(a[i]>b[x]){//a的好马比b的好马强w+=200;i--;x--;}elseif(a[j]>b[y]){//a的差马比b的差马强j++;y++;w+=200;}elseif(a[j]<b[x]){//a的差马比b的好马弱的话(消耗b的好马)j++;x--;w-=200;}  elseif(a[j]==b[y]){//a的差马和b的差马一样j++;y++;}elseif(a[i]==b[x]){//a的好马和b的一样i--;x--;}} printf("%d\n",w);}
}

转载于:https://www.cnblogs.com/Yvettey-me/p/4523606.html

HDU1052——Tian Ji -- The Horse Racing相关推荐

  1. hdu-1052 Tian Ji -- The Horse Racing

    HOT!!! 欢迎参加"金山西山居-2013创意游戏程序挑战赛"! Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Ja ...

  2. hdu 1052 Tian Ji -- The Horse Racing

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

  3. 贪心法田忌赛马问题Java代码,hdoj 1052 Tian Ji - The Horse Racing【田忌赛马】 【贪心】...

    hdoj 1052 Tian Ji -- The Horse Racing[田忌赛马] [贪心] 思路:先按从小到大排序, 然后从最快的开始比(假设i, j 是最慢的一端, flag1, flag2是 ...

  4. Tian Ji -- The Horse Racing(田忌赛马)/贪心算法

    Tian Ji – The Horse Racing(田忌赛马) 田忌赛马的故事 (可以直接看题) Here is a famous story in Chinese history. "T ...

  5. OpenJudge Tian Ji -- The Horse Racing

    目录 Tian Ji -- The Horse Racing 要求: 描述: 输入 : 输出: 样例输入: 样例输出: 问题分析: 情况一: 情况二: 情况三: 最终代码: 总结: 其他思路: Tia ...

  6. Tian Ji -- The Horse Racing(贪心+STL)

    Problem:Tian Ji – The Horse Racing Description: Here is a famous story in Chinese history. "Tha ...

  7. 贪心算法 003:Tian Ji -- The Horse Racing

    003:Tian Ji – The Horse Racing 总时间限制: 5000ms 内存限制: 65536kB 描述 Here is a famous story in Chinese hist ...

  8. 杭电1042c语言循环,HDU杭电1052 Tian Ji - The Horse Racing答题报告

    HDU杭电1052 Tian Ji -- The Horse Racing解题报告 本人第一次写博客,希望各位大神多多指导与包涵,不足的地方还请指出,新手在此谢过啦!!! 题目描述: Time Lim ...

  9. LA 3266 Tian Ji -- The Horse Racing

    题目 LA 3266 Tian Ji – The Horse Racing 题解 这神奇的贪心我是并没有想出来,只会做没有平局的情况,感觉自己太傻比,不知道怎么冲省选了.找的是这篇题解:http:// ...

  10. Tian Ji -- The Horse Racing 贪心算法

    Problem Description Here is a famous story in Chinese history. "That was about 2300 years ago. ...

最新文章

  1. python3.0视频教程_python中文视频教程(全38集),全套视频教程学习资料通过百度云网盘下载...
  2. python3 语法再学习
  3. PHP类的静态(static)方法和静态(static)变量使用介绍
  4. 六级范文背诵50篇_清华附小校长:小学生日记写作训练,附经典范文50篇,家长收藏...
  5. python 解压js压缩的图片_20行Python代码,无损压缩千百张图片!Python有多强!就不用说了...
  6. 用于在Synology NAS上测试Spring Boot Web应用程序的JUnit模拟文件
  7. powershell加win的dns服务器,解决网站负载均衡问题
  8. linux应用小技巧
  9. Java虚拟机(十三)——垃圾回收概述
  10. SAP License:物料类型的划分标准
  11. Netty 中的心跳机制,还有谁不会?
  12. [心得]分布式系统概念与设计知识整理
  13. Java获取List长度
  14. 火遍全网的2000款热门短视频剪辑素材+经典音效包素材来了
  15. 21、随机调整锐度 transforms.RandomAdjustSharpness()
  16. Redis键-值数据库 nosql 数据建模(3)------ 如何存储主从表数据 一对多关系
  17. 开源LLM领域变天!LLaMa惊天泄露引爆ChatGPT平替狂潮
  18. 高德地图(AMap)JavaScript API的使用
  19. RedisTemplate与jedis
  20. 2021-IP地址详解02

热门文章

  1. 关于margin的数值是百分比,参照对象
  2. dbvisualizer连接达梦_Dbvisualizer怎么使用,Dbvisualizer使用教程解析
  3. 学习单片机入门以后可以做什么?
  4. 解决:Maven resources compiler: Maven project configuration required for module ‘c,不识别Maven项目
  5. top刷新间隔_还在用top监控CPU?我们都在用glances
  6. 频率与振幅的关系图怎么画_手拉手模型怎么画?5步教你分分钟完成模型图
  7. Ubuntu安装RabbitMQ及RabbitMQ基于使用
  8. MyBatis集合Spring(四)之使用Spring处理事务
  9. MyBatis集合Spring(三)之mapper
  10. 操作系统原理(四)死锁和进程调度