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)(1≤n≤10): the number of gears in the engine.
  • nn lines, each with three space-separated integers aa, bb and cc (1 \le a, b, c \le 10^4)(1≤a,b,c≤104): 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

题意:有一条抛物线其方程为T=-aR^{2}+bR+c, 然后每次给你n条抛物线的a,b,c值,求给的n条抛物线中y轴的最大值是那条抛物线的。

解法:依次求出每条抛物线的最大值max=\frac{b^{^{2}}}{4a}+c (配方),再根据其进行排序即可。

#include <iostream>
#include <algorithm>
using namespace std;
typedef struct{
    double value;
    int num;
}P;
bool cmp(P q, P w) {
    return q.value > w.value;//定义排序方式
}
int main() {
    int t, n, a, b, c;
  	cin>>t;
    while(t--) {
        P p[20];
        cin>>n;
        for(int i = 0; i < n; i++) {
            cin>>a>>b>>c;
            p[i].num = i + 1;
            p[i].value = 1.0*b*b/(4*a) + c;
        }
        sort(p, p + n, cmp);
        cout<<p[0].num<<endl;
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值