hdu 1050 最大重叠数(贪心)
2015-02-21 22:34
381 查看
原题地址:
点击打开链接
题目大意:在走廊间移动椅子,每次只能移动一个,无论在任何两个房间之间移动都要花费10min,求移动所有椅子所用掉的最短时间。
解析:这题基本是求一个最大重叠数的问题,当然用贪心也可以解决。
/*
Name: hdu 1050
Copyright:
Author:
Date: 15/2/21 22:28
Description:实质为求走廊的最大重叠数
*/
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
// freopen("E:\input.txt", "r", stdin);
int room[205];
int t;
scanf("%d", &t);
int max;
int a, b;
int n;
int i, j;
while (t--)
{
max = 0;
memset(room, 0, sizeof(room)); //每次都要重新清零
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d%d", &a, &b);
a = (a - 1) / 2; //由于1.3 和 2.4 其实经过的是一条走廊
b = (b - 1) / 2;
if (a > b)
{
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
for (j = a; j <= b; j++)
{
room[j]++;
if (room[j] > max) //求最大的走廊的最大重叠数
{
max = room[j];
}
}
}
printf("%d\n", max * 10);
}
return 0;
}
这里的几篇博客关于此题有很好的解释:
http://blog.csdn.net/code_pang/article/details/8251240
http://blog.csdn.net/niushuai666/article/details/7010417
点击打开链接
题目大意:在走廊间移动椅子,每次只能移动一个,无论在任何两个房间之间移动都要花费10min,求移动所有椅子所用掉的最短时间。
解析:这题基本是求一个最大重叠数的问题,当然用贪心也可以解决。
/*
Name: hdu 1050
Copyright:
Author:
Date: 15/2/21 22:28
Description:实质为求走廊的最大重叠数
*/
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
// freopen("E:\input.txt", "r", stdin);
int room[205];
int t;
scanf("%d", &t);
int max;
int a, b;
int n;
int i, j;
while (t--)
{
max = 0;
memset(room, 0, sizeof(room)); //每次都要重新清零
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d%d", &a, &b);
a = (a - 1) / 2; //由于1.3 和 2.4 其实经过的是一条走廊
b = (b - 1) / 2;
if (a > b)
{
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
for (j = a; j <= b; j++)
{
room[j]++;
if (room[j] > max) //求最大的走廊的最大重叠数
{
max = room[j];
}
}
}
printf("%d\n", max * 10);
}
return 0;
}
这里的几篇博客关于此题有很好的解释:
http://blog.csdn.net/code_pang/article/details/8251240
http://blog.csdn.net/niushuai666/article/details/7010417
相关文章推荐
- hdoj1050 moving tables 贪心 最大重叠区间数
- HDU 1050 Moving Tables (贪心 区间最大叠加数)
- HDU_1050 && POJ_1083 Move Tables(贪心)
- hdu 1081 To The Max ****poj 1050(最大子矩阵和)DP
- hdu 1050 Moving Tables(贪心算法---区间覆盖,重叠数)
- [ACM] hdu 1864 最大报销额(01背包或贪心)
- [ACM] hdu 1864 最大报销额(01背包或贪心)
- HDU_1050 重叠数
- hdu 1050 Moving Tables (贪心)
- hdu 1050 Moving Tables(最大区间覆盖问题)
- HDU 1050 Moving Tables (贪心,注意细节)
- hdu 1050+hdu 1789+hdu 3177(贪心)
- hdu 1050 Moving Tables 贪心
- HDU 1081 & POJ 1050 To The Max (最大子矩阵和)
- HDU 1867 KMP 求最大尾部重叠
- hdu 1050 重叠 rom
- hdu 1003/poj 1050 连续子序列最大和经典基础dp
- hdu 1050+hdu 1789+hdu 3177(贪心)
- hdu 1050 Moving Tables_贪心
- HDU 1050 Moving Tables 贪心