Moving Tables--POJ 1083

1、题目类型:模拟。

2、解题思路:水题。

3、注意事项:两种方法:用mov次数记录需要对其结束位置排序;用过道map记录不需要排序。

4、实现方法:

#include<iostream>
#include
<algorithm>
using namespace std;
#define Max 210

struct TMove{
int start,end;
};
TMove mov[Max];
int map[Max];

int cmp(const TMove &n1,const TMove &n2)
{
if(n1.end!=n2.end)
return n1.end<n2.end;
else
return n1.start<n2.start;
}

int main()
{
int i,j,t,n;
cin
>>t;
while(t--)
{
memset(map,
0,sizeof(map));
memset(mov,
0,sizeof(mov));
cin
>>n;
for(i=0;i<n;i++)
{
cin
>>mov[i].start>>mov[i].end;
mov[i].start
++;
mov[i].end
++;
if(mov[i].start>mov[i].end)
{
swap(mov[i].start,mov[i].end);
}
}
// sort(mov,mov+n,cmp);
for(i=0;i<n;i++)
{
// map[i]++;
// for(j=i+1;j<n;j++)
// {
// if(mov[i].end/2>=mov[j].start/2)
for(j=mov[i].start/2;j<=mov[i].end/2;j++)
map[j]
++;
// }
}
cout
<<*max_element(map,map+Max)*10<<endl;
}
return 0;
}

 

posted @ 2010-08-17 20:20  勇泽  阅读(299)  评论(0编辑  收藏  举报