POJ 2014(Flow Layout)

POJ 2014(Flow Layout)
#include < iostream >
using   namespace  std;
int  main()
{
    
int lastw,lasth,nextw,nexth,inh,inw;
    
int curh,curw;
    
int wid;
    
while(cin>>wid)
    
{
        
if(wid==0)
            
break;
        lastw
=0;
        lasth
=0;
        nextw
=0;
        nexth
=0;
        curh
=0;
        curw
=0;
        
while(cin>>inw>>inh)
        
{
            
if(inw==-1 && inh==-1)
                
break;
            
if(curw+inw<=wid)
            
{
                curw
+=inw;
                
if(nextw<curw)
                    nextw
=curw;
                
if(curw>lastw)
                    lastw
=curw;
                curh
=lasth+inh;
                
if(curh>nexth)
                    nexth
=curh;
            }

            
else
            
{
                lasth
=nexth;

                lastw
=nextw;
                curh
=lasth+inh;
                nexth
=curh;
                curw
=inw;
                
if(curw>nextw)
                    nextw
=curw;
            }

        }

        cout
<<nextw<<" x "<<nexth<<endl;
    }

    
return 0;
}

你可能感兴趣的:(POJ 2014(Flow Layout))