培养信心练手题,POJ1083题目描述如下:
这题的思路就是把房号转化为走廊编号(偶数房号除以2得到对应走廊编号,奇数房号加一除以二的打斗对应走廊编号),然后对个编号的走廊被走过的次数进行统计,整条走廊中走过次数最高的一段的次数即为最少搬运趟数。需要注意的是这道题的输入房号可能是先大后小,需要处理一下,不然就会陷入绝望WA中ORZ(别问我为什么知道),具体代码如下:
#include <iostream>
using namespace std;
int main()
{int t, n;cin >> t;while (t--){cin >> n;int i = 0, j = 0, max_time = 0, from[400] = { 0 }, to[400] = { 0 }, corider[201] = { 0 };for (i = 0; i < n; i++){cin >> from[i] >> to[i];int begin_c, end_c;if (from[i] % 2 == 0)begin_c = from[i] / 2;elsebegin_c = (from[i] + 1) / 2;if (to[i] % 2 == 0)end_c = to[i] / 2;elseend_c = (to[i] + 1) / 2;if (begin_c > end_c){int temp = begin_c;begin_c = end_c;end_c = temp;}for (j = begin_c; j <= end_c; j ++){corider[j]++;if (corider[j] > max_time)max_time = corider[j];}}max_time = max_time * 10;cout << max_time << endl;}return 0;
}