请大牛帮忙看一下代码,哪个地方错了。。不胜感激

hechenghai 2012-03-01 09:24:12

http://poj.org/problem?id=1017
poj1017
code:

#include<iostream>
#include<stdio.h>
using namespace std;
int a[10];
int main()
{
freopen("in.txt","r",stdin);
while(1)
{
bool temp=false;
for(int i=1;i<=6;i++)
{
cin>>a[i];
if(a[i]>0)temp=true;
}
if(!temp)break;
int sum=0;
sum+=a[6];
sum+=a[5];
if(a[1]>=a[5]*11)a[1]-=a[5]*11;
else a[1]=0;
sum+=a[4];
if(a[2]>=a[4]*5)a[2]-=a[4]*5;
else
{
int t=a[4]*5-a[2];
if(a[1]>=t*4)a[1]-=t*4;
else a[1]=0;
a[2]=0;
}
if(a[3]>=4)
{
sum+=a[3]/4;a[3]=a[3]%4;
}
if(a[3]>0)sum++;
if(a[3]==1)
{
if(a[1]>=7)a[1]-=7;
else a[1]=0;
if(a[2]>=5)a[2]-=5;
else
{
if(a[1]>=(5-a[2])*4)a[1]-=(5-a[2])*4;
else a[1]=0;
a[2]=0;
}
}
if(a[3]==2)
{
if(a[1]>=6)a[1]-=6;
else a[1]=0;
if(a[2]>=3)a[2]-=3;
else
{
int t=(3-a[2])*4;
if(a[1]>=t)a[1]-=t;
else a[1]=0;
a[2]=0;
}
}
if(a[3]==3)
{
if(a[1]>=5)a[1]-=5;
else a[1]=0;
if(a[2]>=1)a[2]-=1;
else
{
if(a[1]>=4)a[1]-=4;
else a[1]=0;
a[2]=0;
}
}
if(a[2]>=9)
{
sum+=a[2]/9;
a[2]=a[2]%9;
}
if(a[2]>0)sum++;
if(a[1]>=4*(9-a[2]))a[1]-=(9-a[2])*4;
else a[1]=0;
if(a[1]>=36)
{
sum+=a[1]/36;
a[1]%=36;
}
if(a[1]>0)sum++;
cout<<sum<<endl;
}
return 0;
}
...全文
206 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
AndyZhang 2012-03-20
  • 打赏
  • 举报
回复

#include<stdio.h>
int main(){
int n,a,b,c,d,e,f,x,y;
int u[4]={0,5,3,1};
while(1){
scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0)
break;
n=d+e+f+(c+3)/4;
y=5*d+u[c%4];
if(b>y)
n+=(b-y+8)/9;
x=36*n-36*f-25*e-16*d-9*c-4*b;
if(a>x)
n+=(a-x+35)/36;
printf("%d\n",n);
}
return 0;
}
DeDeWo 2012-03-20
  • 打赏
  • 举报
回复
弟啊,把代码的格式写好点,再加点注释吧
hechenghai 2012-03-05
  • 打赏
  • 举报
回复
上面是题目。。
hechenghai 2012-03-05
  • 打赏
  • 举报
回复

Language:
Packets
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 34109 Accepted: 11280
Description

A factory produces products packed in square packets of the same height h and of the sizes 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. These products are always delivered to customers in the square parcels of the same height h as the products have and of the size 6*6. 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 1*1 to the biggest size 6*6. 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 1
7 5 1 0 0 0
0 0 0 0 0 0
Sample Output

2
1
Source
wizard_tiger 2012-03-05
  • 打赏
  • 举报
回复
LZ最好先说清楚你这段程序要作什么。
Furney 2012-03-02
  • 打赏
  • 举报
回复
ACM的题目,期待高手
TMAC10052120353 2012-03-02
  • 打赏
  • 举报
回复
代码写的实在是晦涩难懂啊~~而且不易维护
danhuang 2012-03-02
  • 打赏
  • 举报
回复
这代码,亲何以堪,哥我错了!这代码真的很难看懂你要干什么!
这段代码有问题首先

bool temp=false;
for(int i=1;i<=6;i++)
{
cin>>a[i];
if(a[i]>0)temp=true;
}
if(!temp)break;

你for循环的话只能得到最后一个temp的值,也就是说如果你a[6]<0程序才会跳出while语句
如果a[1]、a[2]、a[3]、a[4]、a[5]小于0程序是不会跳出while语句的,因为你的temp是最后一个的值!

33,008

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧