标签:杂题
这个题坑极多,附代码和测试数据,如果测试数据都过了,基本上就能AC了,希望对大家有所帮助
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cmp(const void*a, const void*b)
{
return *(int*)a - *(int*)b;
}
int main()
{
int m, n, a[1000], i, water, num, cases = 0;
double high, waters;
while (scanf("%d%d", &m, &n))
{
if (m == 0 && n == 0)
break;
memset(a, 0, sizeof(a));
cases++;
for (i = 0; i<m*n; i++)
{
scanf("%d", &a[i]);
}
num = m*n;
scanf("%d", &water);
qsort(a, num, sizeof(int), cmp);
high = a[0], waters = 0;
if (num == 1)
{
printf("Region %d\n", cases);
printf("Water level is %.2f meters.\n", a[0] + (double)water / 100);
printf("%.2f percent of the region is under water.\n\n", (double)100);
continue;
}
if (water == 0)
{
printf("Region %d\n", cases);
printf("Water level is %.2f meters.\n", a[0] + (double)water / 100);
printf("%.2f percent of the region is under water.\n\n", (double)0);
continue;
}
for (i = 1; i<num; i++)
{
if ((a[i] - a[i - 1])*i * 100 + waters >= water)
{
printf("Region %d\n", cases);
printf("Water level is %.2f meters.\n", high + (double)(water - waters) / i / 100);
printf("%.2f percent of the region is under water.\n\n", (double)i / num * 100);
break;
}
waters += (a[i] - a[i - 1])*i * 100;
high = a[i];
}
if (i >= num)
{
printf("Region %d\n", cases);
printf("Water level is %.2f meters.\n", a[num - 1] + (double)(water - waters) / num / 100);
printf("%.2f percent of the region is under water.\n\n", (double)100);
}
}
return 0;
}
3 3
25 37 45
51 12 34
94 83 -1
10000
1 1
25
10000
1 2
1 2
100
1 2
1 2
200
5 1
4 5 5 5 -3
0
1 1
25
240
5 1
4 5 5 5 6
100
5 1
4 5 5 5 6
0
5 1
3 -4 -4 -4 5
100
0 0
Region 1
Water level is 41.40 meters.
55.56 percent of the region is under water.
Region 2
Water level is 125.00 meters.
100.00 percent of the region is under water.
Region 3
Water level is 2.00 meters.
50.00 percent of the region is under water.
Region 4
Water level is 2.50 meters.
100.00 percent of the region is under water.
Region 5
Water level is -3.00 meters.
0.00 percent of the region is under water.
Region 6
Water level is 27.40 meters.
100.00 percent of the region is under water.
Region 7
Water level is 5.00 meters.
20.00 percent of the region is under water.
Region 8
Water level is 4.00 meters.
0.00 percent of the region is under water.
Region 9
Water level is -3.67 meters.
60.00 percent of the region is under water.
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:杂题
原文地址:http://blog.csdn.net/bryant03/article/details/47094045