一开始算法想的有点问题。
坑点在于走廊两侧都有房间
也就是说room1和room2对应的位置是一样的
1 to 3 4to6 是没法同时完成的。
做法就是整个扫一遍,看哪个位置的重复次数最大,*10就是答案。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
#include <iostream> #include <algorithm> #include <cmath> #include<cstdio> #include <cstring> using namespace std; int main() { int t,n,a[300],b[300]; int p[300]; int ans; scanf("%d",&t); while (t--) { scanf("%d",&n); memset(p,0,sizeof(p)); memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for (int i=1;i<=n;i++) { scanf("%d %d",&a[i],&b[i]); if (a[i]>b[i]) swap(a[i],b[i]); for (int j=(a[i]+1)/2;j<=(b[i]+1)/2;j++) p[j]++; } ans=0; for (int i=1;i<=200;i++) if (p[i]>ans) ans=p[i]; printf("%d\n",ans*10); } return 0; } |
说点什么
您将是第一位评论人!