首页 > 其他 > 详细

hdu1050

时间:2017-01-17 00:46:34      阅读:287      评论:0      收藏:0      [点我收藏+]

#include <cstdio>
#include <algorithm>

using namespace std;

#define SIZE 205

struct Data_Type
{
int from, to;
bool flag;
}moving[SIZE];

bool Cmp(const Data_Type a, const Data_Type b)
{
return a.from < b.from;
}

int main(void)
{
int i, testNum, n;

scanf("%d", &testNum);
while (testNum-- != 0)
{
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d%d", &moving[i].from, &moving[i].to);
if (moving[i].from > moving[i].to)
{
int temp = moving[i].from;
moving[i].from = moving[i].to;
moving[i].to = temp;
}
if (moving[i].from % 2 == 0)
{
moving[i].from--;
}
if (moving[i].to % 2 == 1)
{
moving[i].to++;
}
moving[i].flag = false;
}
sort(moving, moving+n, Cmp);
bool completion = false;
int count = -1, priorTo;
while (!completion)
{
completion = true;
count++;
priorTo = 0;
for (i = 0; i < n; i++)
{
if (!moving[i].flag && moving[i].from > priorTo)
{
moving[i].flag = true;
priorTo = moving[i].to;
completion = false;
}
}
}
printf("%d\n", count*10);
}
return 0;
}

hdu1050

原文:http://www.cnblogs.com/wangkun1993/p/6291390.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!