本文共 2894 字,大约阅读时间需要 9 分钟。
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3677 | Accepted: 1901 |
Description
In a big and rich on natural resources country, the government started a campaign to control deforestation. In fact the government is not too interested in how many trees get fallen, but rather how effectively the wood is utilized. So a law was passed which requires every logging company to pay amount of money in proportion to amount of wood that it wastes during operation.
A felling quota on some territory was allotted to a company in this country. Company lorries may only transport logs of exactly L meters long. So when a tree gets sawed into logs, the remainder is wasted.
Trees in this country grow exactly 1 meter per year, so the company may decrease the amount of tax to be paid by simply waiting for some years. Your task is to determine the number of years needed to achieve smallest possible tax. If there is more than one answer, find minimal (earliest) one.
Input
Input file contains number of trees N, length of log L, followed by integers i1 i2 ... iN — heights of each tree.
1 ≤ N ≤ 30000, 1 ≤ L, ik ≤ 30000
Output
Output file must contain single integer — number of years to wait.
Sample Input
Sample Input 13 1 10 15 11Sample Input 23 25 3 6
Sample Output
Sample Output 10Sample Output 21
Hint
Bold texts appearing in the sample sections are informative and do not form part of the actual data.
Source
#include代码二(解题思路二,别人的代码,1AC):#include int arr[31000];int main(void){ int n, log; int i, j, mingy; long long min, sum; scanf("%d%d", &n, &log); for (i = 0; i < n; i++){ scanf("%d", &arr[i]); arr[i] %= log; } for (i = 0; i < log; i++){ for (sum = j = 0; j < n; j++){ sum += (arr[j] + i) % log; } if (!i){ min = sum; mingy = i; } if (min > sum){ min = sum; mingy = i; } } printf("%d\n", mingy); return 0;}
#includeusing namespace std;int max(int a, int b){ return a > b ? a : b;}int main(){ int tree, len; while(cin >> tree >> len){ int hei, ans = 0; while(tree --){ cin >> hei; if(hei % len == 0) continue; ans = max(ans, len - hei % len); } cout << ans << endl; } return 0;}
转载地址:http://hloji.baihongyu.com/