hdu1050 Moving Tables---贪心

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1050

题目大意:
就说有一些桌子需要从某些房间搬到另一些房间,但中间只有一条走廊,且走廊中任何一段只能同时进行一次搬运。

思路:

由于有走廊有两边,可以尝试转换成同一边,比如我要从房间6搬到房间10,等价于我从房间5搬到房间9,这样转化之后问题变成了求多个区间的最大重叠次数,直接暴力就可以了,不过有一个坑点,题意只是说从房间x搬到房间y,没说x<y,所以x,y的大小不确定,暴力时需要进行判断。

 1 #include<iostream>
 2 #include<string>
 3 #include<vector>
 4 #include<cstdio>
 5 #include<cstring>
 6 #define FOR(i, a, b) for(int i = a; i < b; i++)
 7 using namespace std;
 8 int n, T;
 9 int a[450];
10 int main()
11 {    
12     cin >> T;
13     while(T--)
14     {
15         memset(a, 0, sizeof(a));
16         cin >> n;
17         int x, y, ans = 0;
18         while(n--)
19         {
20             cin >> x >> y;
21             if((x&1) == 0)x--;
22             if((y&1) == 0)y--;
23             //cout<<x<<" "<<y<<endl;
24             if(x > y)swap(x, y);
25             for(int i = x; i <= y; i+=2)a[i]++;
26         }
27         for(int i = 1; i <= 400; i+=2)ans = max(ans, a[i]);
28         cout<<ans*10<<endl;
29     }
30     return 0;
31 }

 

posted @ 2018-03-30 11:16  _努力努力再努力x  阅读(115)  评论(0编辑  收藏  举报