HDU—— 2078 复习时间

来源:互联网 发布:任子行 知乎 编辑:程序博客网 时间:2024/06/04 00:53

题意:中文题目,自行理解。

解题思路:将难度系数用数组接收下来后排序,然后从小到大按题意要求计算效率,除第一门课外,其余课都是与相邻前一项作差然后平方,输出最大的一个。

Code:

#include <iostream>#include <cstdio>#include <algorithm>using namespace std;int main(){    //freopen("input.txt","r",stdin);    int T,n,m;    int array[50];    scanf("%d",&T);    while(T--)    {       scanf("%d%d",&n,&m);       for(int i = 0; i<n; i++)           scanf("%d",&array[i]);       sort(array,array+n);       int sum = 0,total = 0;       for(int i = 0; i<m; i++)       {           if(i == 0) sum = (100-array[i])*(100-array[i]);           else sum = (array[i]-array[i-1])*(array[i]-array[i-1]);           if(sum > total) total = sum;       }       printf("%d\n",total);    }    return 0;}

0 0
原创粉丝点击