0
点赞
收藏
分享

微信扫一扫

poj3427Ecology tax


/*poj3427Ecology tax
说有一家公司要开采木头,有N棵树,长度不同,公司的卡车的长度是L,
所以必须把木头砍成单位为L的几段,多余部分丢弃。已经森林里树木每年均生长单位1,

问,过多少年砍伐树木,使得丢弃的树木量最少。暴力每年增长1,存取最小值和年份。

输入树木和车长,下面是每棵树的目前长度

*/



#include<iostream>
using namespace std;

int main()
{
int n, l;
int a[30001];
int min = 999999999; int tem;
cin >> n >> l;
int t;
for (t = 1; t <= n; ++t)
{
cin >> a[t];
}
int year=0;
for (t = 0; t < l; ++t)
{
tem = 0;
for (int i = 1; i <= n; ++i)
{
tem += a[i] % l;
a[i]++;
}
if (min > tem)
{
min = tem;
year = t;
}
}
cout << year << endl;
return 0;
}




/*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.


Constraints



1 ≤ N ≤ 30000, 1 ≤ L, ik ≤ 30000



Output



Output file must contain single integer — number of years to wait.



Sample Input



Sample Input 1


3 1


10 15 11


Sample Input 2


3 2


5 3 6



Sample Output



Sample Output 1


0


Sample Output 2


1*/

*





*






举报

相关推荐

The 2021 CCPC Guilin Tax(爆搜)

0 条评论