• 问题 D: Wall Clocks


    题目描述

    You are the manager of a chocolate sales team. Your team customarily takes tea breaks every two hours, during which varieties of new chocolate products of your company are served. Everyone looks forward to the tea breaks so much that they frequently give a glance at a wall clock.
    Recently, your team has moved to a new office. You have just arranged desks in the office. One team member asked you to hang a clock on the wall in front of her desk so that she will not be late for tea breaks. Naturally, everyone seconded her.
    You decided to provide an enough number of clocks to be hung in the field of view of everyone.
    Your team members will be satisfied if they have at least one clock (regardless of the orientation of the clock) in their view, or, more precisely, within 45 degrees left and 45 degrees right (both ends inclusive) from the facing directions of their seats. In order to buy as few clocks as possible, you should write a program that calculates the minimum number of clocks needed to meet everyone’s demand.
    The office room is rectangular aligned to north-south and east-west directions. As the walls are tall enough, you can hang clocks even above the door and can assume one’s eyesight is not blocked by other members or furniture. You can also assume that each clock is a point (of size zero), and so you can hang a clock even on a corner of the room.
    For example, assume that there are two members. If they are sitting facing each other at positions shown in figure D.1(A), you need to provide two clocks as they see distinct sections of the wall. If their seats are arranged as shown in figure D.1(B), their fields of view have a common point on the wall. Thus, you can meet their demands by hanging a single clock at the point. In figure D.1(C), their fields of view have a common wall section. You can meet their demands with a single clock by hanging it anywhere in the section. Arrangements (A), (B), and (C) in figure D.1 correspond to Sample Input 1, 2, and 3, respectively. 

    输入

    The input consists of a single test case, formatted as follows.
    n w d
    x1 y1 f1
    .
    .
    .
    xn yn fn

    All numbers in the test case are integers. The first line contains the number of team members n (1 ≤ n ≤ 1, 000) and the size of the office room w and d (2 ≤ w, d ≤ 100, 000). The office room has its width w east-west, and depth d north-south. Each of the following n lines indicates the position and the orientation of the seat of a team member. Each member has a seat at a distinct position (xi, yi) facing the direction fi, for i = 1, ... , n. Here 1 ≤ xi ≤ w − 1, 1 ≤ yi ≤ d − 1,and fi is one of N, E, W, and S, meaning north, east, west, and south, respectively. The position (x, y) means x distant from the west wall and y distant from the south wall.

    输出

    Print the minimum number of clocks needed.

    样例输入 Copy

    2 10 6
    4 4 E
    6 4 W
    

    样例输出 Copy

    2

     

     

    1. #include<bits/stdc++.h>
    2. typedef long long ll;
    3. typedef double db;
    4. using namespace std;
    5. const int N=1e3+5;
    6. const int inf=0x3f3f3f3f;
    7. struct intv
    8. {
    9. int l,r;
    10. bool operator<(const intv&f)const
    11. {
    12. return r<f.r;
    13. }
    14. }inv[N],nin[N];
    15. int main()
    16. {
    17. int n,w,d;
    18. cin.tie(0);
    19. cout.tie(0);
    20. ios::sync_with_stdio(false);
    21. cin>>n>>w>>d;
    22. int len=2*(w+d);
    23. for(int i=0;i<n;i++)
    24. {
    25. int x,y;
    26. string s;
    27. cin>>x>>y>>s;
    28. if(s=="N")
    29. {
    30. inv[i].l=w+d+w-x-(d-y);
    31. inv[i].r=inv[i].l+2*(d-y);
    32. }
    33. if(s=="E")
    34. {
    35. inv[i].l=w+y-(w-x);
    36. inv[i].r=inv[i].l+2*(w-x);
    37. }
    38. if(s=="S")
    39. {
    40. inv[i].l=x-y;
    41. inv[i].r=x+y;
    42. }
    43. if(s=="W")
    44. {
    45. inv[i].l=w+d+w+d-y-x;
    46. inv[i].r=inv[i].l+2*x;
    47. }
    48. }
    49. int ans=inf;
    50. sort(inv,inv+n);
    51. for(int i=0;i<n;i++)
    52. {
    53. for(int j=i,cn=0;cn<n;j=(j+1)%n,++cn)
    54. {
    55. nin[cn]=inv[j];
    56. if(j<i)
    57. {
    58. nin[cn].l+=len;
    59. nin[cn].r+=len;
    60. }
    61. }
    62. sort(nin,nin+n);
    63. int num=1,t=nin[0].r;
    64. for(int j=1;j<n;j++)
    65. {
    66. if(nin[j].l>t)
    67. {
    68. num++;
    69. t=nin[j].r;
    70. }
    71. }
    72. ans=min(ans,num);
    73. }
    74. cout<<ans;
    75. return 0;
    76. }

     

  • 相关阅读:
    Python——列表(数组)
    【测试】robotframework安装
    css_css3新特性
    Spring基础入门
    UE5 ChaosVehicles载具 实现大漂移 (连载四)
    信号量机制的实现
    计算机毕业设计ssm+vue基本微信小程序的垃圾分类系统
    力扣 452. 用最少数量的箭引爆气球
    C语言-数组指针与指针数组
    应用安全系列之四十:登录常见问题以及预防方法
  • 原文地址:https://blog.csdn.net/m0_61949623/article/details/126461971