poi 1017 Packets 贪心+模拟
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 48349 | Accepted: 16392 |
Description
of the expenses it is the interest of the factory as well as of the customer to minimize the number of parcels necessary to deliver the ordered products from the factory to the customer. A good program solving the problem of finding the minimal number of parcels
necessary to deliver the given products according to an order would save a lot of money. You are asked to make such a program.
Input
size 6*6. The end of the input file is indicated by the line containing six zeros.
Output
``null'' line of the input file.
Sample Input
0 0 4 0 0 1
7 5 1 0 0 0
0 0 0 0 0 0
Sample Output
2
1
Source
<span style="font-size:32px;">#include <iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
int a[8],u[4]={0,5,3,1};
int main()
{
while(~scanf("%d%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6]))
{
if(!a[1]&&!a[2]&&!a[3]&&!a[4]&&!a[5]&&!a[6])
return 0;
int cnt=a[6]+a[5]+a[4]+(a[3]+3)/4;/*先装好能“独当一面的”大快 递物品,初步确定至少要的箱子数目/
int t2=a[4]*5+u[a[3]%4];/*确定好再上一行代码的情况下,能额外放 入2*2物品的数目*/
if(a[2]>t2)
cnt+=(a[2]-t2+8)/9;/*需要为a[2]单独再开箱子*/
int t1=cnt*36-a[6]*36-a[5]*25-a[4]*16-a[3]*9-a[2]*4;/*补a[1]*/
if(a[1]>t1)
cnt+=(a[1]-t1+35)/36;
printf("%d\n",cnt);
}
return 0;
}
</span>
最后附上本人起初写的wrong
answe代码,一步一步暴力。。
#include <iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
int a[8];
int main()
{
while(~scanf("%d%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6]))
{
if(a[1]+a[2]+a[3]+a[4]+a[5]+a[6]==0)
return 0;
int cnt=a[6]+a[5]+a[4];
a[1]-=a[5]*11;
a[2]-=a[4]*5;
int t3=(a[3]-1+4)/4;
cnt+=t3;
if(a[3]%4!=0)
{
int yu=4-a[3]%4;
if(yu==3)
{
if(a[2]>0)
if(a[2]>=5)
{
a[2]-=5;
a[1]-=7;
}
else
{
a[1]-=27-a[2]*4;
a[2]=0;
}
}
else if(yu==2)
{
if(a[2]>0)
if(a[2]>=3)
{
a[2]-=3;
a[1]-=6;
}
else
{
a[1]-=12-a[2]*4;
a[2]=0;
}
}
else if(yu==1)
{
if(a[2]>=1)
{
a[2]-=1;
a[1]-=3;
}
else
a[1]-=9;
}
}
if(a[2]>0)
{
cnt+=(a[2]-1+9)/9;
a[2]%=9;
a[1]-=36-a[2]*4;
}
if(a[1]>0)
{
cnt+=(a[1]-1+36)/36;
}
printf("%d\n",cnt);
}
return 0;
}
poi 1017 Packets 贪心+模拟的更多相关文章
- UVA 311 Packets 贪心+模拟
题意:有6种箱子,1x1 2x2 3x3 4x4 5x5 6x6,已知每种箱子的数量,要用6x6的箱子把全部箱子都装进去,问需要几个. 一开始以为能箱子套箱子,原来不是... 装箱规则:可以把箱子都看 ...
- Poj 1017 Packets(贪心策略)
一.题目大意: 一个工厂生产的产品用正方形的包裹打包,包裹有相同的高度h和1*1, 2*2, 3*3, 4*4, 5*5, 6*6的尺寸.这些产品经常以产品同样的高度h和6*6的尺寸包袱包装起来运送给 ...
- poj 1017 Packets 贪心
题意:所有货物的高度一样,且其底面积只有六种,分别为1*1 2*2 3*3 4*4 5*5 6*6的,货物的个数依次为p1,p2,p3,p4,p5,p6, 包裹的高度与货物一样,且底面积就为6*6,然 ...
- POJ:1017-Packets(贪心+模拟,神烦)
传送门:http://poj.org/problem?id=1017 Packets Time Limit: 1000MS Memory Limit: 10000K Total Submissions ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
- 贪心+模拟 ZOJ 3829 Known Notation
题目传送门 /* 题意:一串字符串,问要最少操作数使得成为合法的后缀表达式 贪心+模拟:数字个数 >= *个数+1 所以若数字少了先补上在前面,然后把不合法的*和最后的数字交换,记录次数 岛娘的 ...
- CodeForces ---596B--Wilbur and Array(贪心模拟)
Wilbur and Array Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Su ...
- poj 1017 Packets 裸贪心
Packets Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43189 Accepted: 14550 Descrip ...
- POJ 1017 Packets【贪心】
POJ 1017 题意: 一个工厂制造的产品形状都是长方体,它们的高度都是h,长和宽都相等,一共有六个型号,他们的长宽分别为 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. 这些产品通常 ...
随机推荐
- HTML 标签的 for 属性
HTML 标签的 for 属性 for 属性规定 label 与哪个表单元素绑定. 隐式和显式的联系 label通常以下面两种方式中的一种来和表单控件相联系: 将表单控件作为标记标签的内容,这样的就是 ...
- 并不对劲的bzoj4538:loj2049:p3250:[HNOI2016]网络
题意 有一棵\(n\)(\(n\leq 10^5\))个点的树,\(m\)(\(m\leq 2\times 10^5\))个操作.操作有三种:1.给出\(u,v,k\),表示加入一条从\(u\)到\( ...
- Neo4j图数据库配置文件详解
For more details and a complete list of settings, please see https://neo4j.com/docs/operations-manua ...
- .NET CORE API 使用Postman中Post请求获取不到传参问题
开发中遇到个坑 记录下. 使用Postman请求core api 接口时,按之前的使用方法(form-data , x-www-form-urlencoded)怎么设置都无法访问. 最后采用raw写入 ...
- 【原创】大数据基础之Chronos
官方:https://mesos.github.io/chronos/ mesos集群中替换crontab Chronos A fault tolerant job scheduler for Mes ...
- Makefile速查笔记
Makefile速查笔记 Makefile中的几个调试方法 一. 使用 info/warning/error 增加调试信息 a. $(info "some text")打印 &qu ...
- golang(7):文件读写 & json & 错误处理
终端读写 操作终端相关文件句柄常量 os.Stdin // 标准输入 os.Stdout // 标准输出 (输出到终端) os.Stderr // 标准错误输出 (输出到终端) fmt 常见用法 fm ...
- 服务端相关知识学习(二)之Zookeeper可以干什么
Zookeeper主要可以干哪些事情 配置管理,名字服务,提供分布式同步以及集群管理.那这些服务又到底是什么呢?我们为什么需要这样的服务?我们又为什么要使用Zookeeper来实现呢,使用Zookee ...
- 与 QWidget 有关的 Qt 可视化组件的继承关系图
与 QWidget 有关的 Qt 可视化组件的继承关系图
- Spring中常用的设计模式之:代理模式
看了tom老师讲的深入分析spring源码,讲的挺好,做个小总结 代理模式的定义: 为其他对象提供一种代理以控制对这个对象的访问.在某些情况下,一个对象不适合或者不能直接引用另一个对象,而代理对象可以 ...