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

我在pku上的第一道dp题(附程序)

Posted by 547880119 at 2009-02-24 12:59:16 on Problem 1018
#include <stdio.h>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
	int t;
	int n;
	int m[100];
	int b[100][100];
	int p[100][100];
	int total;
	int B[10000];//record the possible answer for the minimal bandwidth of the communication system
	double Dec[10000];//record B/P
	int len_B;
	int i,j,k;

	scanf("%d",&t);

	while(t>0)
	{
		//n: there have n pieces of devices
		scanf("%d",&n);

		//resert the data value for different cases
		len_B = 0;
	

		//this paragraph is to make the input data correct
		for( int i = 0; i < n ; i++ )
		{
			scanf("%d",&m[i]);
			for( int j = 0; j < m[i]; j++ )
			{
				scanf("%d %d",&b[i][j],&p[i][j]);
				B[len_B] = b[i][j];
				len_B ++;
			}
		}

		for(  i = 0; i < len_B; i++ )
		{
			total = 0;//for each case of B[i],we should reset the value of total peice to 0.
	
			for(  j = 0; j < n; j++ )
			{
				int temp = INT_MAX;	
				
				for(  k = 0; k < m[j]; k++ )
				{
					if( b[j][k] >= B[i] &  p[j][k] < temp )
					{							
							temp = p[j][k];
					}
				}//for_k

				if( temp != INT_MAX)
					total += temp;
				else 
					total = INT_MIN;
			}//for_j

			if( total > 0 )
				Dec[i] =((double) B[i])/((double) total);
			else
				Dec[i] = -1;
		}//for_i

		double max = -1;
		for( i = 0; i < len_B; i++ )
			if( Dec[i] > max )
			{
				max = Dec[i];	
			}

		cout << setiosflags(ios::fixed) << setprecision(3) << max << endl;
		

			t--;
	}

	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