题意就是你有n和m两个上限 吃一个东西会同时增加两个东西 m的值不能超过给定的m 问最后的n m值和每个东西吃了多少

贪心一下就好了 算一下性价比 从最大的开始吃 直到吃满了m n也一定是最大了

只是想借这道题说一下经常卡题的小bug 因为这道题一开始卡精度 后来又卡除零 很诡异……

粗心bug小总结~

1.double除零是有返回值的 int除零才是RE 同时注意数据范围有没有0

2.精度可能要比题意中小一点

3.两组数据之间也有换行

4.两层for里i j用混了

5.define的用法

6.三目运算符可能会RE也可能超时

7.预处理数组时越界

8.case记得打

9.有的地方爆了int要用long long

(10.想起来再补充……)

贴代码

 #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<map>
#include<vector>
#include<queue>
#define M(a,b) memset(a,b,sizeof(a))
using namespace std;
const double eps=1e-;
struct thing {
double z,m,ha,uh,val,sum,sum2,need;
} th[];
bool cmp(thing a,thing b) {
return a.ha*b.uh>a.uh*b.ha;
}
bool cmp1(thing a,thing b) {
return a.z<b.z;
}
int main() {
// printf("%f\n",1.0/0);
freopen("burrito.in","r",stdin);
freopen("burrito.out","w",stdout);
int n,a,b;
while(~scanf("%d%d%d",&n,&a,&b)) {
for(int i=; i<n; i++) {
th[i].z=i;
scanf("%lf%lf%lf",&th[i].m,&th[i].ha,&th[i].uh);
th[i].sum=th[i].m*th[i].ha;
th[i].sum2=th[i].m*th[i].uh;
th[i].need=;
}
sort(th,th+n,cmp);
double nowa=,nowb=;
for(int i=; i<n; i++) {
if(th[i].uh==) {
nowa+=th[i].sum;
th[i].need=th[i].m;
} else if(nowb+th[i].sum2>=b) {
if(nowb+th[i].sum2==b) {
th[i].need=th[i].m;
nowb+=th[i].sum2;
nowa+=th[i].sum;
} else {
th[i].need=(b-nowb)*1.0/th[i].uh*1.0;
nowa+=th[i].need*th[i].ha;
nowb=b;
}
break;
} else {
nowa+=th[i].sum;
nowb+=th[i].sum2;
th[i].need=th[i].m;
}
}
if(nowa<a-eps) printf("-1 -1\n");
else {
sort(th,th+n,cmp1);
printf("%.10lf %.10lf\n",nowa,nowb);
for(int i=; i<n; i++)
printf("%.10lf%c",th[i].need,i==n-?'\n':' ');
}
}
return ;
}
/* 2 5 5
2 2 1
2 2 4
2 5 5
2 2 2
2 2 4 */

Gym 100553B Burrito King 无脑背包的更多相关文章

  1. 【原】无脑操作:express + MySQL 实现CRUD

    基于node.js的web开发框架express简单方便,很多项目中都在使用.这里结合MySQL数据库,实现最简单的CRUD操作. 开发环境: IDE:WebStorm DB:MySQL ------ ...

  2. Go语言及Web框架Beego环境无脑搭建

    [原]Go语言及Web框架Beego环境无脑搭建 本文涉及软件均以截至到2013年10月12日的最新版本为准 1. 相关软件准备: 1) go1.2rc1.windows-386.msi,对应32位w ...

  3. 【原】无脑操作:eclipse + maven搭建SSM框架

    网上看到一些Spring + Spring MVC + MyBatis框架的搭建教程,不是很详细或是时间久远了,自己动手整一个简单无脑的! 0.系统环境 1)Windows 10 企业版 2)JDK ...

  4. 计蒜客 无脑博士 bfs

    题目链接无脑博士的试管们 思路:直接模拟倒水过程即可,但是需要记忆判断当前的情况是否已经处理过.dfs和bfs都ok AC代码 #include <cstdio> #include < ...

  5. CodeForces 909E Coprocessor(无脑拓扑排序)

    You are given a program you want to execute as a set of tasks organized in a dependency graph. The d ...

  6. 【原】无脑操作:ElasticSearch学习笔记(01)

    开篇来自于经典的“保安的哲学三问”(你是谁,在哪儿,要干嘛) 问题一.ElasticSearch是什么?有什么用处? 答:截至2018年12月28日,从ElasticSearch官网(https:// ...

  7. 【原】无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础授权权限

    上一篇<[原]无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础认证权限>介绍了实现Shiro的基础认证.本篇谈谈实现 ...

  8. 【原】无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础认证权限

    开发环境搭建参见<[原]无脑操作:IDEA + maven + SpringBoot + JPA + Thymeleaf实现CRUD及分页> 需求: ① 除了登录页面,在地址栏直接访问其他 ...

  9. 【原】无脑操作:EasyUI Tree实现左键只选择叶子节点、右键浮动菜单实现增删改

    Easyui中的Tree组件使用频率颇高,经常遇到的需求如下: 1.在树形结构上,只有叶子节点才能被选中,其他节点不能被选中: 2.在叶子节点上右键出现浮动菜单实现新增.删除.修改操作: 3.在非叶子 ...

随机推荐

  1. canvas实现画板功能(渐变、动画、阴影...)

    刚刚在博客园落户了,希望能在这认识更多大神,希望能和大家交好朋友. 闲来无事,把以前用canvas写的画板代码改进了一番,用Html5提供的表单标签给其 加了一个选择颜色的功能,因此发现了该标签的一个 ...

  2. YUM变量

    有一个简单的python命令可以看到yum的 releaserver.arch.basearch的值 /usr/bin/python -c 'import yum, pprint; yb = yum. ...

  3. (转载)html中div使用自动高度

    为什么要使用div标签 1.更多的配置项,那就意味着更灵活,当然,难度也更高: 2.可以方便的容纳其他html标签:     static定位就是不定位,出现在哪里就显示在哪里,这是默认取值,只有在你 ...

  4. angular-file-upload+springMVC的使用

    最近项目中需要用到文件上传,使用了angular-file-upload插件完成 首先来介绍下这个插件的一些属性(参考官方文档) FileUploader 属性 url {String}: 上传文件的 ...

  5. hdu 5207 BestCoder Round #38 ($) Greatest Greatest Common Divisor

    #include<stdio.h> #include<string.h> #include<math.h> ]; ]; int main() { int sb; s ...

  6. json的遍历

    第一种json结构: var jsongood = {"goods":[{"parentId":"null","productId ...

  7. trove,测试,db小解析

    # Copyright 2014 Tesora Inc.# All Rights Reserved.## Licensed under the Apache License, Version 2.0 ...

  8. jQuery Validate【强大的表单验证】

    一.引入菜鸟教程提供的 1.14.0 版本下载地址:http://static.runoob.com/download/jquery-validation-1.14.0.zip <script ...

  9. (ASP.NET )去除字符串中的HTML标签

    string strDoContent = "执行增加<a href="/AdminCX/Admin_CompanyDetail.aspx?CompanyGuid=cd8e1 ...

  10. 【卷二】网络二—TCP服务器与客户端

    经过上回简单地介绍,大家对服务器多少应该清楚一些了吧!还记得TCP: (Transmission Control Protocol) 传输控制协议? 还记得IP: (Internet Protocol ...