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

Rounded to one decimal place竟然不是让四舍五入。。!!!!!!!!附代码

Posted by Nat at 2008-08-29 14:17:17 on Problem 2510
首先,这个题实在恶心。。。。

time不用double过不去(想要我们考虑精度干嘛不直接搞高精度却来搞expression中subexpression的implict conversion的边界的边界的边界的边界的边界的边界的边界的..)

另外,rounded to one decimal place之round居然不是指的四舍五入。。(holy shit..)

WA了3次找了半天BUG最后绝望的把代码中临近输出前的四舍五入部分注释掉居然AC了。。。。

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

vector<double> queries;

class cSubstance
{
public:
	cSubstance( int type, double time, double n )
		: _type( type ), _time( time ), _n( n )
	{}

	~cSubstance()
	{}

	double getEffect( double t )
	{
		if( t < _time ) 
			return 0;

		double ret = 0;
		if( _type == 1 )
			ret = 8.0*_n-(t-_time)/12.0;
		else 
			ret = 2.0*_n-(t-_time)*(t-_time)/79.0;

		if( ret < 0 )
			ret = 0;

		return ret;
	}

	double _time;
	double _n;
	int _type;
};

cSubstance *subs[100];
int nsubs;

int main()
{
	char buff[255];
	
	while( cin.getline( buff, 255 ) )
	{
	
		if( buff[0] == 'Q' )
		{
			double time;
			sscanf( buff+5, "%lf", &time );
			queries.push_back( time );

			continue;
		}

		char stype[25];
		double time;
		double n;
		sscanf( buff, "%s %lf %lf", stype, &time, &n );
		subs[ nsubs++ ] = new cSubstance( (string( "Coffee" ) == stype ? 0 : 1 ), 
			time, n );
	}

	sort( queries.begin(), queries.end() );

	for( int i=0; i<queries.size(); i++ )
	{
		double total = 0;
		for( int j=0; j<nsubs; j++ )
			total += subs[j]->getEffect( queries[i] );
		if( total < 1 )
			total = 1;
/*
		total *= 10;
		if( int(total + 0.5) != int( total ) )
			total += 1;
		total /= 10;
		*/

		printf( "%d %.1f\n", int(queries[i]), total );
	}

	for( int i=0; i<nsubs; i++ )
		delete subs[i];

	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