首页 > 其他 > 详细

poj1083,nyoj220推桌子 贪心

时间:2015-04-21 11:12:47      阅读:169      评论:0      收藏:0      [点我收藏+]
#include <stdio.h><span style="font-family: Arial, Helvetica, sans-serif;">//注意两点,桌子可能从编号高的房间推到编号低的房间。如果2 3 ,4 5也是要分两次进行。因为3和4在同一走廊。</span>
#include <string.h>
#include <algorithm>
using namespace std;
struct node 
{
	int star,end;
}c[205];
bool cmp(node x,node y)
{
	if(x.star<y.star) return true;
	if(x.star==y.star&&x.end<y.end) return true;
	return false;
}
int main()
{
	int test,n,flag[205],temp;
	scanf("%d",&test);
	while(test--)
	{
		scanf("%d",&n);
		for(int i=0;i<n;i++)
		{
			scanf("%d %d",&c[i].star,&c[i].end);
			if(c[i].star%2)
			c[i].star++;
			if(c[i].end%2)
			c[i].end++;
			if(c[i].star>c[i].end)
			temp=c[i].star,c[i].star=c[i].end,c[i].end=temp;//如果左边大于右边 交换顺序
		}
		sort(c,c+n,cmp);
		memset(flag,0,sizeof(flag));//记录
		int count=0;
		for(int i=0;i<n;i++)//贪心的思想
		{
			if(!flag[i])
			{
				count++,flag[i]=1;
				for(int j=i+1;j<n;j++)
				if(c[j].star>c[i].end&&!flag[j])
				flag[j]=1,c[i].end=c[j].end;
			}
		}
		printf("%d\n",count*10);
	}
	return 0;
}        

poj1083,nyoj220推桌子 贪心

原文:http://blog.csdn.net/su20145104009/article/details/45167153

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