Gym 100553B Burrito King 无脑背包

题意就是你有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.想起来再补充……)

贴代码

 1 #include<stdio.h>
 2 #include<iostream>
 3 #include<algorithm>
 4 #include<math.h>
 5 #include<string.h>
 6 #include<map>
 7 #include<vector>
 8 #include<queue>
 9 #define M(a,b) memset(a,b,sizeof(a))
10 using namespace std;
11 const double eps=1e-10;
12 struct thing {
13     double z,m,ha,uh,val,sum,sum2,need;
14 } th[100005];
15 bool cmp(thing a,thing b) {
16     return a.ha*b.uh>a.uh*b.ha;
17 }
18 bool cmp1(thing a,thing b) {
19     return a.z<b.z;
20 }
21 int main() {
22 //    printf("%f\n",1.0/0);
23     freopen("burrito.in","r",stdin);
24     freopen("burrito.out","w",stdout);
25     int n,a,b;
26     while(~scanf("%d%d%d",&n,&a,&b)) {
27         for(int i=0; i<n; i++) {
28             th[i].z=i;
29             scanf("%lf%lf%lf",&th[i].m,&th[i].ha,&th[i].uh);
30             th[i].sum=th[i].m*th[i].ha;
31             th[i].sum2=th[i].m*th[i].uh;
32             th[i].need=0;
33         }
34         sort(th,th+n,cmp);
35         double nowa=0,nowb=0;
36         for(int i=0; i<n; i++) {
37             if(th[i].uh==0) {
38                 nowa+=th[i].sum;
39                 th[i].need=th[i].m;
40             } else if(nowb+th[i].sum2>=b) {
41                 if(nowb+th[i].sum2==b) {
42                     th[i].need=th[i].m;
43                     nowb+=th[i].sum2;
44                     nowa+=th[i].sum;
45                 } else {
46                     th[i].need=(b-nowb)*1.0/th[i].uh*1.0;
47                     nowa+=th[i].need*th[i].ha;
48                     nowb=b;
49                 }
50                 break;
51             } else {
52                 nowa+=th[i].sum;
53                 nowb+=th[i].sum2;
54                 th[i].need=th[i].m;
55             }
56         }
57         if(nowa<a-eps) printf("-1 -1\n");
58         else {
59             sort(th,th+n,cmp1);
60             printf("%.10lf %.10lf\n",nowa,nowb);
61             for(int i=0; i<n; i++)
62                 printf("%.10lf%c",th[i].need,i==n-1?‘\n‘:‘ ‘);
63         }
64     }
65     return 0;
66 }
67 /*
68
69 2 5 5
70 2 2 1
71 2 2 4
72 2 5 5
73 2 2 2
74 2 2 4
75
76 */
时间: 2024-08-01 10:26:39

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

计蒜客 无脑博士和他的试管们

无脑博士有三个容量分别是A,B,C升的试管,A,B,C分别是三个从1到20的整数,最初,A和B试管都是空的,而C试管是装满硫酸铜溶液的.有时,无脑博士把硫酸铜溶液从一个试管倒到另一个试管中,直到被灌试管装满或原试管空了.当然每一次灌注都是完全的.由于无脑博士天天这么折腾,早已熟练,溶液在倒的过程中不会有丢失. 写一个程序去帮助无脑博士找出当A是个是空的时候,C试管中硫酸铜溶液所剩量的所有可能性. 输入包括一行,为空格分隔开的三个数,分别为整数A,B和C. 输出包括一行,升序地列出当A试管是空的时

VS2013+openCV3.0无脑配置方法+解决警告问题【windows平台】

VS2013+openCV3.0无脑配置方法+解决警告问题[windows平台] 本文介绍如何配置VS+openCV环境,并解决“opencv 3.0 warning C4819: 该文件包含不能在当前代码页(936)中表示的字符.请将该文件保存为 Unicode 格式以防止数据丢失的”警告 参考博客: http://my.phirobot.com/blog/2014-02-opencv_configuration_in_vs.html 下载 openCV 下载 Opencv for Windo

智慧解析第13集:无脑盲从者

智慧解析第13集:无脑盲从者,布布扣,bubuko.com

有个学霸找我这个脑残要这道题的无脑代码——立体图

#include<iostream> #include<cstring> #include<cstdio> using namespace std; int v[52][52]; char s[2001][2001]; int n,m,x,y; void wri(int a,int b) { s[a][b]='+'; s[a+1][b]='-'; s[a+2][b]='-'; s[a+3][b]='-'; s[a+4][b]='+'; s[a][b-1]='|'; s[

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

You are given a program you want to execute as a set of tasks organized in a dependency graph. The dependency graph is a directed acyclic graph: each task can depend on results of one or several other tasks, and there are no directed circular depende

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

开发环境搭建参见<[原]无脑操作:IDEA + maven + SpringBoot + JPA + Thymeleaf实现CRUD及分页> 需求: ① 除了登录页面,在地址栏直接访问其他URL,均跳转至登录页面 ② 登录涉及帐号和密码,帐号错误提示帐号错误,密码错误提示密码错误 ③ 登录成功跳转至首页,首页显示登录者帐号信息,并有注销帐号功能,点击注销退出系统 ------------------------------------------------------------------

CF gym 101933 K King&#39;s Colors —— 二项式反演

题目:http://codeforces.com/gym/101933/problem/K 其实每个点的颜色只要和父亲不一样即可: 所以至多 i 种颜色就是 \( i * (i-1)^{n-1} \),设为 \( f(i) \),设恰好 i 种颜色为 \( g(i) \) 那么 \( f(i) = \sum\limits_{j=0}^{i} C_{i}^{j} * g(j) \) 二项式反演得到 \( g(i) = \sum\limits_{j=0}^{k} (-1)^{k-j} * C_{k}

k8s无脑系列(三)-NFS存储(简单版本)

k8s无脑系列(三)-NFS存储(简单版本) 1.概念 搞清楚pv,pvc pv = PersistentVolume 持久化存储控制器,面向集群而不是namespace. pvc = PersistentVolumeClaim 对接pod与pv, 关系,官方说明 A PVC to PV binding is a one-to-one mapping, using a ClaimRef which is a bi-directional binding between the Persisten

实锤,无脑定投指数基金真的可以赚钱么?

投资有风险,入市需谨慎,本文不构成任何投资理财建议,仅做交流学习使用. 不知道大家有没有在网上见过各种理财课程,说什么小白入门最简单的就是定投指数基金,还说人家巴菲特也这么投,这种课程介绍是越写越夸张,后面最夸张说还能打成一个小目标. 过分了啊,如果打成小目标这么简单,那不是中国打成小目标的怎么地也有个百分之十左右了吧,但是我身边好像没见过达成小目标的人啊,难道是因为我太 qiong 的缘故? 还有那种用巴菲特举例子的课程介绍,拜托下次介绍的时候把故事讲完好不好,人家老巴是在美股定投基金,美股是