比赛时水过的,现在贴一下正规做法。

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <vector>
#include <map>
#include <algorithm>#define LL long long
#define LLU unsigned long long
#define INF 0x7fffffffusing namespace std;int main()
{double ans = -1e30, temp, a, b;int ansk, anskk, k;scanf("%lf%lf%d", &a, &b, &k);for(int x = 0; x <= k; ++x){int y = b/2;if(x+y>k) y = k-x;if(y<0) y = 0;temp = a*x+b*y-x*x-y*y;if(temp>ans) { ans = temp; ansk = x; anskk = y; }}printf("%.2lf\n%d %d\n", ans, ansk, anskk);return 0;
}

比较数学化的另一种做法

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <vector>
#include <map>
#include <algorithm>#define LL long long
#define LLU unsigned long long
#define INF 0x7fffffff
#define eps 1e-9using namespace std;double calcu(double a, double b, double x, double y)
{return a*x + b*y - x*x - y*y;
}
int main()
{double a, b;int k, x, y;scanf("%lf%lf%d", &a, &b, &k);int ta = 0, tb = 0;if(fmod(a/2,1)>0.5) ta = int(a/2+0.5);else ta = int(a/2);if(fmod(b/2,1)>0.5) tb = int(b/2+0.5);else tb = int(b/2);if(a<=0&&b<=0) { x = 0; y = 0; }else if(a>0&&b<=0) { x = min(k,ta); y = 0; }else if(a<=0&&b>0) { x = 0; y = min(k,tb); }else if(a>0&&b>0){if(ta+tb<=k) { x = ta; y = tb; }else{double temp, max = -1e30;int xx, yy;for( x = 0; x <= k; ++x){y = min(tb, k-x);temp = calcu(a,b,x,y);if(temp>max) { max = temp; xx = x; yy = y; }}x = xx; y = yy;}}printf("%.2lf\n%d %d\n", calcu(a,b,x,y), x, y);return 0;
}

URAL 1200 - Horns and Hoofs(暴力+剪枝)相关推荐

  1. URAL 1200 Horns and Hoofs 枚举

    设horns和hoofs的数量分别为 x 和 y ,题目要求: 满足 x+y <= K,使得A*x + B*y - x*x - y*y 最大. 枚举 i 从0~K,直接解方程得对称轴 x = ( ...

  2. URAL:1200 Horns and Hoofs

    虽然原题给了250MS,看似很短,其实暴力也是跑能过去的... 应该坑了不少人. #include <iostream> #include <cstdio> #include ...

  3. URAL 1200. Horns and Hoofs 枚举+数学

    接触的东西越来越来反而变得不够灵活了,以前碰到的这样的题都要暴力,枚举,两个for循环试试的,今天看到时脑子里接着想暴力会超时的,但是好几个人都200+ms过了,我一直在推导,证明,最后越推越麻烦,一 ...

  4. 让我想到微观经济学的一个题 1200. Horns and Hoofs

    原文链接:  http://acm.timus.ru/problem.aspx?space=1&num=1200 背景: 最优化问题:  一个人养a, b两种东西,   单只的收益分别为 A, ...

  5. [BOI2019][第K大问题][暴力剪枝]D2T1 Olympiads

    目录 题意 输入格式 输出格式 样例 Input Output 数据范围 时间限制 思路 代码 题意 有\(N\)个人,现在你要从中选出\(K\)个人出来,然后让这\(K\)个人一起参加\(K\)场比 ...

  6. CodeForces 1138B暴力+剪枝

    [题目链接]Circus [题目分析]理解题意以后发现并没有什么思路,没有什么算法能用,这个时候就应该想到计算机解题的本质--暴力求解.相应的就要想到剪枝的条件,肯定不能盲目的暴力求解. 总共有四种人 ...

  7. UVA 10074 Take the Land dp/暴力+剪枝

    原题传送门:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...

  8. 【NOIP模拟题】【DP】【同余最短路】【暴力剪枝】2016.11.15 第二题 小L的牛栏 题解

    小L的牛栏 [题目描述] 小L通过泥萌的帮助,成功解决了二叉树的修改问题,并因此写了一篇论文, 成功报送了叉院(羡慕不?).勤奋又勤思的他在研究生时期成功转系,考入了北京大学光华管理学院!毕业后,凭着 ...

  9. POJ - 3080 Blue Jeans(暴力+KMP)

    题目链接:点击查看 题目大意:给出n组长度为60的字符串,问这n组中最长的公共连续子串是什么,若有多个不同的最长公共子串,输出字典序最小的那个 题目分析:一开始看到这个题目的时候我是没有想到暴力的.. ...

最新文章

  1. Unity 简单示例代码和向导/Unity Aplication Block
  2. Android Studio 简介
  3. AIX系统管理--关于unsuccessful login attempts和account_locked
  4. linux-windows主动推送文件同步目录数据 linux-windows数据目录同步
  5. springboot jwt token前后端分离_为什么要 前后端分离 ?
  6. Opencv--CalcOpticalFlowPyrLK实现的光流法理解
  7. Destoon数据库配置文件在哪_SpringBoot中yml配置文件说明和一些常用配置项说明
  8. 一条命令关掉centos所有不必要的服务和端口号
  9. UI_storyboard实现页面回调
  10. EXT4中恢复使用rm命令误删除的文件
  11. 洪峰:泛系、自由与“一、百、万”工程(一)
  12. phpwind测试之phpwind安装(二)
  13. PTA 数据结构与算法题目集(中文) 7-49 打印学生选课清单 (25分)题解
  14. 大规模定制基本思想和特点介绍
  15. movs 数据传送指令_数据传送指令之:MOV指令-嵌入式系统-与非网
  16. RK3568 Android11 去除长按power键弹框的emergency按键
  17. RabbitMQ:消费者ACK机制、生产者消息确认
  18. 深入浅出matplotlib(96):标记的疏密控制
  19. php separator,PHP常量DIRECTORY_SEPARATOR原理及用法解析
  20. 能把百度玩出花样的人肯定不简单,分享几个鲜为人知的搜索引擎高级语法

热门文章

  1. Failed to launch ‘xxxxxx‘ because the scheme does not have
  2. 查看MYSQL中数据表占用的空间
  3. python爬虫(三)12306自动抢票--- selenium
  4. Js写的二级联动和三级联动
  5. Springboot 接受参数,控制台乱码
  6. 2017中国国际智慧城市、物联网、大数据博览会会刊(参展商名录)
  7. 天九集团卢俊卿:一位热衷慈善的成功企业家
  8. 【Python实战】全球疫情数据采集, 并做可视化展示
  9. postionfixed固定_position:fixed定位问题的解决
  10. VLAN间通信全家桶