传送门UVa Live Archive 2322 - Wooden Sticks
题意:给出木棍的长和宽,如果后一根制造的木棍的长和宽都>=前一根,就可以不用时间setup,不然就要1单位的时间,求最小的时间。
排序,依次输出即可。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 5000 + 100;
struct STICK
{
int l, w;
friend bool operator < (const STICK &a, const STICK &b)
{
if (a.l != b.l)
return a.l < b.l;
else
return a.w < b.w;
}
}stick[MAXN];
int vis[MAXN];
int main()
{
//freopen("input.txt", "r", stdin);
int T, i, j, n, cnt, allCnt;
int latest;
scanf("%d", &T);
while (T--)
{
memset(vis, 0, sizeof(vis));
cnt = allCnt = 0;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d%d", &stick[i].l, &stick[i].w);
sort(stick, stick + n);
while (true)
{
cnt++;
for (i = 0; i < n; i++)
if (!vis[i])
{
latest = stick[i].w;
vis[i] = 1;
allCnt++;
break;
}
for (i = 1; i < n; i++)
{
if (stick[i].w >= latest && !vis[i])
{
vis[i] = 1;
latest = stick[i].w;
allCnt++;
}
}
if (allCnt == n)
break;
}
printf("%d\n", cnt);
}
return 0;
}