Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

纪念65贴一水,轻拍

Posted by realkingiscoming at 2009-11-01 10:17:43 on Problem 2014
#include <iostream>
using namespace std;

int main()
{
	int limitwidth;
	
	int x;
	int y;

	int totalwidth;//for all
	int totalheight;//for all

	cin>>limitwidth;

	while(limitwidth != 0)
	{
		totalwidth = 0;
		totalheight = 0;

		int sumwidthforeachline = 0;//for each line
		int maxheightforeachline = 0;//for each line
		
		cin>>x>>y;

		while(!((x == -1) && (y == -1)))
		{
			if(sumwidthforeachline + x <= limitwidth)//put it on the current line
			{
				sumwidthforeachline += x;
				
			}
			else//need to turn to next line
			{
				sumwidthforeachline = 0;

				totalheight += maxheightforeachline;

				maxheightforeachline = 0;

				sumwidthforeachline += x;

			}

			if(sumwidthforeachline > totalwidth)
					totalwidth = sumwidthforeachline;

			if(y > maxheightforeachline)
					maxheightforeachline = y;

			cin>>x>>y;
		}//end of while(!((x == -1) && (y == -1)))

		totalheight += maxheightforeachline;

		cout<<totalwidth<<" x "<<totalheight<<endl;

		cin>>limitwidth;
	}

	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator