poj 1017 wa的问题
代码如下:#include<iostream>usingnamespacestd;intmain(void){int_1x1,_2x2,_3x3,_4x4,_5x5,_6...
代码如下:
#include <iostream>
using namespace std;
int main(void)
{
int _1x1 , _2x2 , _3x3 , _4x4 , _5x5 , _6x6;
int Sum;
int Sum1x1;
int Sum2x2;
int Identifier1x1[4] = { 0 , 7 , 6 , 5 };
int Identifier2x2[4] = { 0 , 5 , 3 , 1 };
for(;;)
{
cin>> _1x1 >> _2x2 >> _3x3 >> _4x4 >> _5x5 >> _6x6 ;
if(_1x1 + _2x2 + _3x3 + _4x4 + _5x5 + _6x6 == 0)
break;
Sum = _6x6 + _5x5 + _4x4 + (_3x3 + 3) / 4;
Sum1x1 = 11 * _5x5 + Identifier1x1[_3x3 % 4];
Sum2x2 = 5 * _4x4 + Identifier2x2[_3x3 % 4];
if(Sum2x2 < _2x2)
{
Sum += (_2x2 - Sum2x2 + 8) / 9;
Sum1x1 += 4 * ( 9 * (_2x2 - Sum2x2 + 8) / 9 - ( _2x2 - Sum2x2 ) );
}
else
Sum1x1 += 4 * (Sum2x2 - _2x2);
if(Sum1x1 < _1x1)
Sum += (_1x1 - Sum1x1 + 35) / 36;
cout<<Sum<<endl;
}
return 0;
} 展开
#include <iostream>
using namespace std;
int main(void)
{
int _1x1 , _2x2 , _3x3 , _4x4 , _5x5 , _6x6;
int Sum;
int Sum1x1;
int Sum2x2;
int Identifier1x1[4] = { 0 , 7 , 6 , 5 };
int Identifier2x2[4] = { 0 , 5 , 3 , 1 };
for(;;)
{
cin>> _1x1 >> _2x2 >> _3x3 >> _4x4 >> _5x5 >> _6x6 ;
if(_1x1 + _2x2 + _3x3 + _4x4 + _5x5 + _6x6 == 0)
break;
Sum = _6x6 + _5x5 + _4x4 + (_3x3 + 3) / 4;
Sum1x1 = 11 * _5x5 + Identifier1x1[_3x3 % 4];
Sum2x2 = 5 * _4x4 + Identifier2x2[_3x3 % 4];
if(Sum2x2 < _2x2)
{
Sum += (_2x2 - Sum2x2 + 8) / 9;
Sum1x1 += 4 * ( 9 * (_2x2 - Sum2x2 + 8) / 9 - ( _2x2 - Sum2x2 ) );
}
else
Sum1x1 += 4 * (Sum2x2 - _2x2);
if(Sum1x1 < _1x1)
Sum += (_1x1 - Sum1x1 + 35) / 36;
cout<<Sum<<endl;
}
return 0;
} 展开
1个回答
展开全部
正确代码自己看:
#include<stdio.h>
int fmax(int i,int j){
return i>j?i:j;
}
int main(){
int s1,s2,s3,s4,s5,s6;
int sum,tp,tp2;
while(scanf("%d%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5,&s6),s1+s2+s3+s4+s5+s6){
sum=0;
sum+=s6;//6*6的箱子;
//s6=0;
sum+=s5;//5*5的箱子,剩下的用1*1来填充
//s5=0;
s1=fmax(0,s1-11*s5);//剩下的用1*1来填充
sum+=s4;//4*4的箱子,剩下的先用2*2再用1*1来填充
tp=s2;
s2=fmax(0,s2-(5*s4));//用2*2
if(s2==0&&tp!=0)
s1=fmax(0,s1-4*(s4*5-tp)); //s1=fmax(0,s1-(5-tp%5)*4);因为s4的箱子多出来的情况,所以注释里的s1是错误的
sum+=(s3+3)/4;//4个3*3填充一个箱子
tp=s3%4;//tp表示最后一个箱子已经填了几个3*3
if(tp==1){//可以填充5个2*2
if(s2==0){tp2=0;
s1=fmax(0,s1-27);}
if(s2==1){tp2=1;
s1=fmax(0,s1-23);}
if(s2==2){tp2=2;
s1=fmax(0,s1-19);}
if(s2==3){tp2=3;
s1=fmax(0,s1-15);}
if(s2==4){tp2=4;
s1=fmax(0,s1-11);}
if(s2>=5){tp2=5;
s1=fmax(0,s1-7);}
s2=fmax(0,s2-tp2);
}//填好了2*2再填1*1
else if(tp==2){
if(s2==0){tp2=0;
s1=fmax(0,s1-18);}
if(s2==1){tp2=1;
s1=fmax(0,s1-14);}
if(s2==2){tp2=2;
s1=fmax(0,s1-10);}
if(s2>=3){tp2=3;
s1=fmax(0,s1-6);}
s2=fmax(0,s2-tp2);
}
else if(tp==3){
if(s2==0){tp2=0;
s1=fmax(0,s1-9);}
if(s2>=1){tp2=1;
s1=fmax(0,s1-5);}
s2=fmax(0,s2-tp2);
}
sum+=(s2+8)/9;
tp=s2%9;
if(tp)
s1=fmax(0,s1-(36-4*tp));
sum+=(s1+35)/36;
printf("%d\n",sum);
}
return 0;
}
满意请采纳
#include<stdio.h>
int fmax(int i,int j){
return i>j?i:j;
}
int main(){
int s1,s2,s3,s4,s5,s6;
int sum,tp,tp2;
while(scanf("%d%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5,&s6),s1+s2+s3+s4+s5+s6){
sum=0;
sum+=s6;//6*6的箱子;
//s6=0;
sum+=s5;//5*5的箱子,剩下的用1*1来填充
//s5=0;
s1=fmax(0,s1-11*s5);//剩下的用1*1来填充
sum+=s4;//4*4的箱子,剩下的先用2*2再用1*1来填充
tp=s2;
s2=fmax(0,s2-(5*s4));//用2*2
if(s2==0&&tp!=0)
s1=fmax(0,s1-4*(s4*5-tp)); //s1=fmax(0,s1-(5-tp%5)*4);因为s4的箱子多出来的情况,所以注释里的s1是错误的
sum+=(s3+3)/4;//4个3*3填充一个箱子
tp=s3%4;//tp表示最后一个箱子已经填了几个3*3
if(tp==1){//可以填充5个2*2
if(s2==0){tp2=0;
s1=fmax(0,s1-27);}
if(s2==1){tp2=1;
s1=fmax(0,s1-23);}
if(s2==2){tp2=2;
s1=fmax(0,s1-19);}
if(s2==3){tp2=3;
s1=fmax(0,s1-15);}
if(s2==4){tp2=4;
s1=fmax(0,s1-11);}
if(s2>=5){tp2=5;
s1=fmax(0,s1-7);}
s2=fmax(0,s2-tp2);
}//填好了2*2再填1*1
else if(tp==2){
if(s2==0){tp2=0;
s1=fmax(0,s1-18);}
if(s2==1){tp2=1;
s1=fmax(0,s1-14);}
if(s2==2){tp2=2;
s1=fmax(0,s1-10);}
if(s2>=3){tp2=3;
s1=fmax(0,s1-6);}
s2=fmax(0,s2-tp2);
}
else if(tp==3){
if(s2==0){tp2=0;
s1=fmax(0,s1-9);}
if(s2>=1){tp2=1;
s1=fmax(0,s1-5);}
s2=fmax(0,s2-tp2);
}
sum+=(s2+8)/9;
tp=s2%9;
if(tp)
s1=fmax(0,s1-(36-4*tp));
sum+=(s1+35)/36;
printf("%d\n",sum);
}
return 0;
}
满意请采纳
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询