| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
哪位帮我看看,一直WA。大家给的数据都测过了。#include <vector>
#include <cstdio>
#include <iostream>
using namespace std;
struct product
{
int bandwidth;
int price;
};
double min_result = 0;
int cur_i = -1;
int cur_j = -1;
double tmp_result = 0.0;
int tmp_price = 0;
vector< vector<product> > vec;
void get_data( int i )
{
if( i == vec.size() )
{
tmp_result = (double)vec[cur_i][cur_j].bandwidth/tmp_price;
if( tmp_result > min_result )
min_result = tmp_result;
return;
}
if( i == cur_i )
{
get_data(i+1);
return;
}
for( int j = 0; j < vec[i].size(); ++j )
{
if( vec[cur_i][cur_j].bandwidth > vec[i][j].bandwidth )
continue;
tmp_price += vec[i][j].price;
get_data( i+1 );
tmp_price -= vec[i][j].price;
}
}
int main()
{
int a = 0;
int n = 0;
scanf( "%d", &a );
scanf( "%d", &n );
for( int i = 0; i < n; ++i )
{
scanf("%d",&a);
vec.push_back( vector<product>() );
for( int j = 0; j < a; ++j )
{
int b;
vec[i].push_back( product() );
scanf("%d", &b );
vec[i][j].bandwidth = b;
scanf("%d", &b );
vec[i][j].price = b;
}
}
for( int i = 0; i < vec.size(); ++i )
{
for( int j = 0; j < vec[i].size(); ++j )
{
cur_i = i;
cur_j = j;
tmp_price = vec[i][j].price;
get_data( 0 );
}
}
printf("%.03f", min_result);
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator