joj1538
来源:互联网 发布:mac校园网客户端 编辑:程序博客网 时间:2024/06/05 16:44
1538: Packets
A factory produces products packed in square packets of the same height h and of the sizes , , , , , . These products are always delivered to customers in the square parcels of the same height h as the products have and of the size . Because 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
The input file consists of several lines specifying orders. Each line specifies one order. Orders are described by six integers separated by one space representing successively the number of packets of individual size from the smallest size to the biggest size . The end of the input file is indicated by the line containing six zeros.
Output
The output file contains one line for each line in the input file. This line contains the minimal number of parcels into which the order from the corresponding line of the input file can be packed. There is no line in the output file corresponding to the last ``null'' line of the input file.
Sample Input
0 0 4 0 0 17 5 1 0 0 00 0 0 0 0 0
Sample Output
21
#include<stdio.h>
int a[7];
int main()
{
freopen("in.txt","r",stdin);
while(scanf("%d%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6])==6)
{
if(a[1]+a[2]+a[3]+a[4]+a[5]+a[6]==0) break;
int count=0;
int temp;
count+=a[6]+a[5]+a[4];
int left3=0;
if(a[3]%4==0)
{
count+=a[3]/4;
left3=0;
}
else
{
count+=a[3]/4+1;
left3+=(4-a[3]%4);
}
int left2=a[4]*5;
int left1=a[5]*11;
if(left3==3)
{
left2+=5;
left1+=7;
}
if(left3==2)
{
left2+=3;
left1+=6;
}
if(left3==1)
{
left2+=1;
left1+=5;
}
if(a[2]>left2)
{
a[2]-=left2;
if(a[2]%9==0)
count+=a[2]/9;
else
{
count+=a[2]/9+1;
left1+=4*(9-a[2]%9);
}
}
else
{
left2-=a[2];
left1+=left2*4;
}
if(a[1]>left1)
{
a[1]-=left1;
if(a[1]%36==0)
count+=a[1]/36;
else
count+=a[1]/36+1;
}
printf("%d\n",count);
}
return 0;
}
对于这道题目我是感触颇深,这个题目一开始我就想错了,以为可以将整个6*6的
方格进行划分结果弄了一个小时也没有调试出来,最后是换了一种思路才调试出来
下面是我第一次的错误代码。对于1个3*3和5个2*2的题目下面的代码将是错误的。
/*#include<stdio.h>
int packet[7];
bool exam()
{
for(int i=1;i<=6;i++)
{
if(packet[i]!=0)
return false;
}
return true;
}
void cal(int u,int v)
{
for(int i=6;i>0;i--)
{
if(packet[i]!=0)
{
if(u>=i&&v>=i)
{
packet[i]--;
if(u>v)
{
if(u-i>v)
cal(u-i,v);
else
cal(v,u-i);
if(i>v-i)
cal(i,v-i);
else
cal(v-i,i);
v=v-i;
u=u-i;
}
else
{
if(i>u-i)
cal(i,u-i);
else
cal(u-i,i);
if(v-i>u)
cal(v-i,u);
else
cal(u,v-i);
v=v-i;
u=u-i;
}
}
}
}
}
int main()
{
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
bool first=true;
while(1)
{
bool temp=false;
for(int i=1;i<=6;i++)
{
scanf("%d",&packet[i]);
if(packet[i]!=0)
temp=true;
}
if(!temp)break;
if(!first)
printf("\n");
first=false;
int num=0;
while(!exam())
{
cal(6,6);
num++;
}
printf("%d",num);
}
return 0;
}
*/
- joj1538
- POJ 2411 Mondriaan's Dream 状态压缩(DP)
- 新概念英语 Lesson 15
- ASP.NET 基础(7)
- 浅谈学习计划
- ASP.NET之:序列化
- joj1538
- Error the user data image is used by another emulator. aborting
- 正则表达式技巧,快速度上手!
- 1.2.两个链表的合并
- 数据库连接查询类型(左连接、右连接、全连接、内连接和交叉连接)
- LANMP安装总结
- 分析PA日志程序
- flex tree 怎么在java后台组合成合适的数据,我使用的是flex spring hibernate
- 9月22日LINUX作业