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

100题,贴个代码,见笑。。。

Posted by AlwaysLearning at 2013-12-31 21:40:51 on Problem 2241
#include<iostream>
#include<algorithm>
using namespace std;

struct Block
{
	int x;
	int y;
	int z;
};

int cmp(Block a, Block b)
{
	if(a.x < b.x)
		return 1;
	else if(a.x > b.x)
		return 0;
	else if(a.y < b.y)
		return 1;
	else
		return 0;
}
int go(Block *block, int n)
{
	sort(block, block + n, cmp);
	int dp[n];
	for(int i = 0; i < n; ++i)
		dp[i] = block[i].z;

	for(int i = 1; i < n; ++i)
	{
		for(int j = 0; j < i; ++j)
			if(block[j].x < block[i].x && block[j].y < block[i].y)
				dp[i] = max(dp[i], dp[j] + block[i].z);
	}
	
	return *max_element(dp, dp + n);
}
int main()
{
	int n;
	for(int i = 1; 1; ++i)
	{
		cin>>n;
		if(0 == n)
			return 0;
		Block block[6 * n];
		for(int j = 0; j < n; ++j)
		{
			cin>>block[6 * j].x>>block[6 * j].y>>block[6 * j].z;
			
			block[6 * j + 1].x = block[6 * j].y;
			block[6 * j + 1].y = block[6 * j].x;
			block[6 * j + 1].z = block[6 * j].z;

			block[6 * j + 2].x = block[6 * j].y;
			block[6 * j + 2].y = block[6 * j].z;
			block[6 * j + 2].z = block[6 * j].x;

			block[6 * j + 3].x = block[6 * j].z;
			block[6 * j + 3].y = block[6 * j].y;
			block[6 * j + 3].z = block[6 * j].x;

			block[6 * j + 4].x = block[6 * j].x;
			block[6 * j + 4].y = block[6 * j].z;
			block[6 * j + 4].z = block[6 * j].y;

			block[6 * j + 5].x = block[6 * j].z;
			block[6 * j + 5].y = block[6 * j].x;
			block[6 * j + 5].z = block[6 * j].y;
		}
		cout<<"Case "<<i<<": maximum height = "<<go(block, 6 * n)<<endl;
	}
	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