码迷,mamicode.com
首页 > 其他好文 > 详细

HDU1050

时间:2014-07-21 23:29:03      阅读:319      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   数据   

bubuko.com,布布扣

思路分析(盗图一张):

分析过程有如下图所示:

bubuko.com,布布扣

我们可以用一个数组flag记录(1,2),(3,4)·····的公共走廊被记录的次数,每经过一次便把对应的flag[i]加1;注意边缘化处理,我们只采用一个长为205的数组处理,所以需要把数据统一到偶数中去,然后采用flag[j/2]进行存储。

由于对于每一个flag[i]一次只能访问一次,所以我们只需要找出最大的flag[i]就可以输出结果。

代码展示:

 1 #include<iostream>
 2 #include<string.h>
 3 using namespace std;
 4 #define maxn 205
 5 int move[maxn][2];
 6 int flag[205];
 7 int main()
 8 {
 9     int t;
10     cin>>t;
11     while(t--)
12     {
13         int n;
14         memset(flag,0,sizeof(flag));
15         cin>>n;
16         for(int i=0;i<n;i++)
17             {
18                 cin>>move[i][0]>>move[i][1];
19                 if(move[i][0]>move[i][1]){int t=move[i][0];move[i][0]=move[i][1];move[i][1]=t;}
20                 if(move[i][0]%2==1) move[i][0]++;
21                 if(move[i][1]%2==1) move[i][1]++;
22                 for(int j=move[i][0];j<=move[i][1];j+=2)
23                     flag[j/2]++;
24             }
25             int max=flag[0];
26             for(int i=1;i<=200;i++)
27             if(flag[i]>max)max=flag[i];
28             cout<<max*10<<endl;
29     }
30     return 0;
31 }

HDU1050,布布扣,bubuko.com

HDU1050

标签:style   blog   http   color   os   数据   

原文地址:http://www.cnblogs.com/khbcsu/p/3859316.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!