标签:
Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
3 4 10 20 30 40 50 60 70 80 2 1 3 2 200 3 10 100 20 80 30 50
Sample Output
10 20 30
题目大意:有400个房屋,需要在这些房屋之间搬运箱子,但是同一段走廊在每10分钟只能进行一次搬运,问你最少要多少分钟才能完成搬运任务。
思路分析:我看题目分类这道题是划分在dp里面的,刚开始一直想构造状态转移方程,就是没有弄出来,后来看了别人的题解,才造用贪心做,直接
记录每个区间的访问次数,访问最大次数*10就是需要的最短时间。
代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
const int maxn=400+10;
const int inf=0xffffff;
int t[maxn];
int main()
{
int T,n,a,b;
cin>>T;
while(T--)
{
scanf("%d",&n);
mem(t);
int ma=-inf;
for(int i=0;i<n;i++)
{
scanf("%d%d",&a,&b);
if(a>b) swap(a,b);
if(a%2==0) a--;
if(b%2==1) b++;
for(int j=a;j<=b;j++)
t[j]++;
}
for(int i=1;i<=400;i++)
{
ma=max(ma,t[i]);
}
cout<<10*ma<<endl;
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/xuejianye/p/5483245.html