Benelux Algorithm Programming Contest 2014 Final G: Growling Gears

G: Growling Gears:

The Best Acceleration Production Company specializes in multi-gear engines. The performance of an engine in a certain gear, measured in the amount of torque produced, is not constant: the amount of torque depends on the RPM of the engine. This relationship can be described using a torque-RPM curve.

For the latest line of engines, the torque-RPM curve of all gears in the engine is a parabola of the form T = -aR^2 +bR+cT=aR2+bR+c,where RR is the RPM of the engine,and TT is the resulting torque.

Given the parabolas describing all gears in an engine, determine the gear in which the highest torque is produced. The first gear is gear 11, the second gear is gear 22, etc. There will be only one gear that produces the highest torque: all test cases are such that the maximum torque is at least 11 higher than the maximum torque in all the other gears.

Input Format

On the first line one positive number: the number of test cases, at most 100100. After that per test case:

  • one line with a single integer nn (1 \le n \le 10)(1n10): the number of gears in the engine.
  • nn lines, each with three space-separated integers aabb and cc (1 \le a, b, c \le 10^4)(1a,b,c104): the parameters of the parabola T = -aR^2 +bR+cT=aR2+bR+c describing the torque-RPM curve of each engine.

Output Format

Per test case:

  • one line with a single integer: the gear in which the maximum torque is generated.

样例输入

3
1
1 4 2
2
3 126 1400
2 152 208
2
3 127 1400
2 154 208

样例输出

1
2
2

题目来源

Benelux Algorithm Programming Contest 2014 Final

代码:

#include <iostream>
using namespace std;
int main(int argc, char const *argv[]){	
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		int max = 0;
		int ans = 0;
		int flag = 0;
		while(n --){
			int a, b, c;
			cin >> a >> b >> c;
			flag ++;
			if(max < double(b * b ) / (4*a) + c){
				max =  double(b * b ) / (4*a) + c;
				ans = flag;
			}

		}
		cout << ans << endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_36561697/article/details/81021752