HDU1052——Tian Ji -- The Horse Racing
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相关推荐
- hdu-1052 Tian Ji -- The Horse Racing
HOT!!! 欢迎参加"金山西山居-2013创意游戏程序挑战赛"! Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Ja ...
- hdu 1052 Tian Ji -- The Horse Racing
Tian Ji -- The Horse Racing Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Jav ...
- 贪心法田忌赛马问题Java代码,hdoj 1052 Tian Ji - The Horse Racing【田忌赛马】 【贪心】...
hdoj 1052 Tian Ji -- The Horse Racing[田忌赛马] [贪心] 思路:先按从小到大排序, 然后从最快的开始比(假设i, j 是最慢的一端, flag1, flag2是 ...
- Tian Ji -- The Horse Racing(田忌赛马)/贪心算法
Tian Ji – The Horse Racing(田忌赛马) 田忌赛马的故事 (可以直接看题) Here is a famous story in Chinese history. "T ...
- OpenJudge Tian Ji -- The Horse Racing
目录 Tian Ji -- The Horse Racing 要求: 描述: 输入 : 输出: 样例输入: 样例输出: 问题分析: 情况一: 情况二: 情况三: 最终代码: 总结: 其他思路: Tia ...
- Tian Ji -- The Horse Racing(贪心+STL)
Problem:Tian Ji – The Horse Racing Description: Here is a famous story in Chinese history. "Tha ...
- 贪心算法 003:Tian Ji -- The Horse Racing
003:Tian Ji – The Horse Racing 总时间限制: 5000ms 内存限制: 65536kB 描述 Here is a famous story in Chinese hist ...
- 杭电1042c语言循环,HDU杭电1052 Tian Ji - The Horse Racing答题报告
HDU杭电1052 Tian Ji -- The Horse Racing解题报告 本人第一次写博客,希望各位大神多多指导与包涵,不足的地方还请指出,新手在此谢过啦!!! 题目描述: Time Lim ...
- LA 3266 Tian Ji -- The Horse Racing
题目 LA 3266 Tian Ji – The Horse Racing 题解 这神奇的贪心我是并没有想出来,只会做没有平局的情况,感觉自己太傻比,不知道怎么冲省选了.找的是这篇题解:http:// ...
- Tian Ji -- The Horse Racing 贪心算法
Problem Description Here is a famous story in Chinese history. "That was about 2300 years ago. ...
最新文章
- python3.0视频教程_python中文视频教程(全38集),全套视频教程学习资料通过百度云网盘下载...
- python3 语法再学习
- PHP类的静态(static)方法和静态(static)变量使用介绍
- 六级范文背诵50篇_清华附小校长:小学生日记写作训练,附经典范文50篇,家长收藏...
- python 解压js压缩的图片_20行Python代码,无损压缩千百张图片!Python有多强!就不用说了...
- 用于在Synology NAS上测试Spring Boot Web应用程序的JUnit模拟文件
- powershell加win的dns服务器,解决网站负载均衡问题
- linux应用小技巧
- Java虚拟机(十三)——垃圾回收概述
- SAP License:物料类型的划分标准
- Netty 中的心跳机制,还有谁不会?
- [心得]分布式系统概念与设计知识整理
- Java获取List长度
- 火遍全网的2000款热门短视频剪辑素材+经典音效包素材来了
- 21、随机调整锐度 transforms.RandomAdjustSharpness()
- Redis键-值数据库 nosql 数据建模(3)------ 如何存储主从表数据 一对多关系
- 开源LLM领域变天!LLaMa惊天泄露引爆ChatGPT平替狂潮
- 高德地图(AMap)JavaScript API的使用
- RedisTemplate与jedis
- 2021-IP地址详解02
热门文章
- 关于margin的数值是百分比,参照对象
- dbvisualizer连接达梦_Dbvisualizer怎么使用,Dbvisualizer使用教程解析
- 学习单片机入门以后可以做什么?
- 解决:Maven resources compiler: Maven project configuration required for module ‘c,不识别Maven项目
- top刷新间隔_还在用top监控CPU?我们都在用glances
- 频率与振幅的关系图怎么画_手拉手模型怎么画?5步教你分分钟完成模型图
- Ubuntu安装RabbitMQ及RabbitMQ基于使用
- MyBatis集合Spring(四)之使用Spring处理事务
- MyBatis集合Spring(三)之mapper
- 操作系统原理(四)死锁和进程调度