PAT1082 射击比赛 (20 分)

题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805260990660608

思路:  很简单的求最大最小值所对应的id,只要将两者的id分别用两个值存储,在根据求最大最小值得方法求得就好。


  

#include 
#include 

using namespace std;

void solve()
{
    int ma = -2, mi = 200000;
    int a = 0, i = 0;
    int n;
    scanf("%d", &n);
    while(n--)
    {
        int id, x, y;
        scanf("%d%d%d", &id, &x, &y);
        int s = x * x + y * y;
        if(ma < s)
        {
            ma = s;
            a = id;
        }
        if(mi > s)
        {
            mi = s;
            i = id;
        }
    }
    printf("%04d %04d\n", i, a);

}

int main()
{
    solve();
    return 0;
}

                                                                                                                                                                      属20分简单类题目       

                                                                                                                                                             2018年9月17日 10:08:15        

你可能感兴趣的:(PAT,乙级)