传送门

题意

分析

求一个凸包即可

1.所有点在凸包上且点数>3,令凸包上第1,3点为'A',其余点为'B'

2.部分点在凸包上,令凸包上点为'A',其余点为'B'

3.无可行情况

附代码

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. const LL eps=1e-10;
  5. const LL pi=acos(-1.0);
  6. int dcmp(LL x)
  7. {
  8. if(x==0LL) return 0;
  9. else return x<0? -1:1;
  10. }
  11. struct Point
  12. {
  13. LL x,y;
  14. int id;
  15. void read()
  16. {
  17. scanf("%lld%lld",&x,&y);
  18. }
  19. void output()
  20. {
  21. printf("%lld %lld\n",x,y);
  22. }
  23. Point(LL x_=0,LL y_=0)
  24. {
  25. x=x_,y=y_;
  26. }
  27. Point operator -(const Point& rhs)
  28. {
  29. return Point(x-rhs.x,y-rhs.y);
  30. }
  31. Point operator +(const Point& rhs)
  32. {
  33. return Point(x+rhs.x,y+rhs.y);
  34. }
  35. Point operator *(const LL& t)
  36. {
  37. return Point(x*t,y*t);
  38. }
  39. Point operator /(const LL& t)
  40. {
  41. return Point(x/t,y/t);
  42. }
  43. bool operator ==(const Point& rhs)
  44. {
  45. return dcmp(x-rhs.x)==0&&dcmp(y-rhs.y)==0;
  46. }
  47. bool operator<(const Point& rhs)const
  48. {
  49. return x<rhs.x||x==rhs.x&&y<rhs.y;
  50. }
  51. };
  52. typedef Point Vector;
  53. LL Cross(Vector A,Vector B)
  54. {
  55. return A.x*B.y-A.y*B.x;
  56. }
  57. LL Dot(Vector A,Vector B)
  58. {
  59. return A.x*B.x+A.y*B.y;
  60. }
  61. LL Area2(Point A,Point B,Point C)
  62. {
  63. return Cross(B-A,C-A);
  64. }
  65. bool SegmentProperIntersection(Point A1,Point B1,Point A2,Point B2)
  66. {
  67. LL c1=Cross(B1-A1,A2-A1),c2=Cross(B1-A1,B2-A1),
  68. c3=Cross(B2-A2,A1-A2),c4=Cross(B2-A2,B1-A2);
  69. return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4)<0;
  70. }
  71. bool OnSegment1(Point P,Point A,Point B)
  72. {
  73. return dcmp(Cross(P-A,P-B))==0 && dcmp(Dot(P-A,P-B))<=0;
  74. }
  75. bool SegmentIntersection(Point A1,Point B1,Point A2,Point B2)
  76. {
  77. return SegmentProperIntersection(A1,B1,A2,B2) ||
  78. OnSegment1(A2,A1,B1)||OnSegment1(B2,A1,B1) ||
  79. OnSegment1(A1,A2,B2)||OnSegment1(B1,A2,B2);
  80. }
  81. int ConvexHull(Point *p,int n,Point *ch)
  82. {
  83. sort(p,p+n);
  84. int m=0;
  85. for(int i=0; i<n; ++i)
  86. {
  87. while(m>1&&dcmp(Area2(ch[m-2],ch[m-1],p[i]))<=0) --m; //直到 ch[m-2],ch[m-1],p[i] 不是顺时针且不在同一直线
  88. ch[m++]=p[i];
  89. }
  90. int k=m;
  91. for (int i=n-2; i>=0; --i)
  92. {
  93. while(m>k&&dcmp(Area2(ch[m-2],ch[m-1],p[i]))<=0) --m;
  94. ch[m++]=p[i];
  95. }
  96. return n>1?m-1:m;
  97. }
  98. //==============================================
  99. int n,nc;
  100. Point p[105],ch[105];
  101. int c[105];
  102. bool judge()
  103. {
  104. int cnt=ConvexHull(p,n,ch);//计算在凸包上的点
  105. if(cnt<n)
  106. {
  107. for(int i=0;i<cnt;++i) c[ch[i].id]=1;
  108. return 1;
  109. }
  110. else if(cnt>3)
  111. {
  112. c[ch[0].id]=c[ch[2].id]=1;
  113. return 1;
  114. }
  115. else return 0;
  116. }
  117. int main()
  118. {
  119. int T;
  120. scanf("%d",&T);
  121. while(T--)
  122. {
  123. scanf("%d",&n);
  124. memset(c,0,n*sizeof(int));
  125. for(int i=0;i<n;i++)
  126. p[i].read(),p[i].id=i;
  127. if(judge())
  128. {
  129. puts("YES");
  130. for(int i=0;i<n;++i) if(c[i]) putchar('A');else putchar('B');
  131. puts("");
  132. }
  133. else
  134. puts("NO");
  135. }
  136. return 0;
  137. }

hihocoder 1582 : Territorial Dispute(凸包)的更多相关文章

  1. hihoCoder #1582 : Territorial Dispute 凸包

    #1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...

  2. hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...

  3. hihocoder 1582 : Territorial Dispute (计算几何)(2017 北京网络赛E)

    题目链接 题意:给出n个点.用两种颜色来给每个点染色.问能否存在一种染色方式,使不同颜色的点不能被划分到一条直线的两侧. 题解:求个凸包(其实只考虑四个点就行.但因为有板子,所以感觉这样写更休闲一些. ...

  4. 【分类讨论】【计算几何】【凸包】hihocoder 1582 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E. Territorial Dispute

    题意:平面上n个点,问你是否存在一种黑白染色方案,使得对于该方案,无法使用一条直线使得黑色点划分在直线一侧,白色点划分在另一侧.如果存在,输出一种方案. 如果n<=2,显然不存在. 如果所有点共 ...

  5. ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛

    编号 名称 通过率 通过人数 提交人数 A√水题(队友写的 Visiting Peking University 91% 1122 1228 B— Reverse Suffix Array 57% 6 ...

  6. words

    conscious[英][ˈkɒnʃəs][美][ˈkɑnʃəs]consensus[英][kənˈsensəs][美][kənˈsɛnsəs] scious sensuswaterflood; de ...

  7. [poj1113][Wall] (水平序+graham算法 求凸包)

    Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...

  8. hihocoder -1121-二分图的判定

    hihocoder -1121-二分图的判定 1121 : 二分图一•二分图判定 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 大家好,我是小Hi和小Ho的小伙伴Net ...

  9. Hihocoder 太阁最新面经算法竞赛18

    Hihocoder 太阁最新面经算法竞赛18 source: https://hihocoder.com/contest/hihointerview27/problems 题目1 : Big Plus ...

随机推荐

  1. wiki平台工具

    1.  confluence  评点: 好用,与world类似.模板多.

  2. Spring Boot 使用Java代码创建Bean并注冊到Spring中

    从 Spring3.0 開始,添加了一种新的途经来配置Bean Definition,这就是通过 Java Code 配置 Bean Definition. 与Xml和Annotation两种配置方式 ...

  3. poj 3169 Layout(差分约束)

    Layout Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6549   Accepted: 3168 Descriptio ...

  4. 如何在List集合中去重

    众所周知List集合中的元素是有序的,但是List中的元素同样是可以重复的,那么我们应该怎么在List集合中去重呢? 方法一: 对于方法一而言,这也许是一个小窍门.利用的是Set集合中不允许出现重复的 ...

  5. Intel MIC

    http://en.wikipedia.org/wiki/Intel_MIC Intel MIC From Wikipedia, the free encyclopedia     Intel Man ...

  6. 赵雅智_SimpleCursorAdapter

    项目步骤 声明listView控件并获取显示的视图 获取显示的数据 设置显示的adapter 注冊点击事件 详细案例 实现效果: watermark/2/text/aHR0cDovL2Jsb2cuY3 ...

  7. Finally语句块的运行

    一.finally语句块是否一定运行? Java中异常捕获机制try...catch...finally块中的finally语句是不是一定会被运行?非常多人都说不是.当然他们的回答是正确的,经过试验. ...

  8. UIPanGestureRecognizer上下左右滑动方向推断算法

    CGFloat const gestureMinimumTranslation = 20.0; typedef enum :NSInteger { kCameraMoveDirectionNone, ...

  9. bash exec

    1 当exec执行命令时,会为该命令创建shell进程,并且终止老的shell进程的执行,并且保留老的shell进程的进程号 [root@localhost ~]# cat test_exec.sh ...

  10. inherited在消息中的作用(编译器根据inherited所在的函数,直接转换成对祖先类同名动态函数的调用,或者转换成对DefaultHandler的调用)

    好奇一下.看来Object Pascal确实与Windows深入结合了. unit Unit1; interface uses Windows, Messages, SysUtils, Variant ...