1. /***************
  2. poj 3335 点序顺时针
  3. ***************/
  4. #include <iostream>
  5. #include <cmath>
  6. #include <algorithm>
  7. using namespace std;
  8. const double eps = 1e-;
  9. const double maxn = 0x7f7f7f7f;
  10. int dcmp(double x){
  11. if(fabs(x)<eps)
  12. return ;
  13. else
  14. return x<?-:;
  15. }
  16. struct point {
  17. double x,y;
  18. point (double x=,double y =):x(x),y(y){}
  19. };
  20. point p[];
  21. typedef point Vector;
  22.  
  23. struct polygon{
  24. point p[];
  25. int Size;
  26. };
  27.  
  28. struct line{
  29. point fir,sec;
  30. line(point a = point(),point b = point()){
  31. fir = a;
  32. sec = b;
  33. }
  34. };
  35.  
  36. Vector operator -(point a,point b){
  37. return Vector(a.x-b.x,a.y-b.y);
  38. }
  39.  
  40. Vector operator *(Vector a,double p){
  41. return Vector (a.x*p,a.y*p);
  42. }
  43. Vector operator + (Vector a,Vector b){
  44. return Vector (a.x+b.x,a.y+b.y);
  45. }
  46.  
  47. double cross(Vector a,Vector b){
  48. return a.x*b.y-a.y*b.x;
  49. }
  50.  
  51. double dot(Vector a,Vector b){
  52. return a.x*b.x+a.y*b.y;
  53. }
  54.  
  55. point getLineIntersection(point p,Vector v,point q,Vector w){
  56. Vector u = p-q;
  57. double t = cross(w,u)/cross(v,w);
  58. return p+v*t;
  59. }
  60.  
  61. bool onsegment(point p,point a1,point a2){
  62. return dcmp(cross(a1-p,a2-p))==&&dcmp(dot(a1-p,a2-p))<;
  63. }
  64.  
  65. polygon cutploygon(polygon poly,line ln){
  66. polygon newploy;
  67. int m=;
  68. int n = poly.Size;
  69. point a = ln.fir,b = ln.sec;
  70. for(int i=;i<n;i++){
  71. point c = poly.p[i];
  72. point d = poly.p[(i+)%n];
  73. double cc = cross(b-a,c-a);
  74. double dd = cross(b-a,d-a);
  75. if(cc>=)
  76. newploy.p[m++] = c;
  77. if(cc*dd<)
  78. newploy.p[m++] = getLineIntersection(a,b-a,c,d-c);
  79. }
  80. newploy.Size = m;
  81. return newploy;
  82. }
  83.  
  84. int main()
  85. {
  86. int t;
  87. cin>>t;
  88. int n;
  89. while(t--){
  90. cin>>n;
  91. for(int i=;i<n;i++)
  92. cin>>p[i].x>>p[i].y;
  93. polygon poly;
  94. poly.Size = ;
  95. poly.p[].x = -maxn;
  96. poly.p[].y = -maxn;
  97. poly.p[].x = maxn;
  98. poly.p[].y = -maxn;
  99. poly.p[].x = maxn;
  100. poly.p[].y = maxn;
  101. poly.p[].x = -maxn;
  102. poly.p[].y = maxn;
  103. bool flag = true;
  104. for(int i=;i<=n;i++){
  105. line ln;
  106. ln.fir = p[i%n];
  107. ln.sec = p[i-];
  108. poly = cutploygon(poly,ln);
  109. if(poly.Size==){
  110. flag = false;
  111. break;
  112. }
  113. }
  114. if(!flag)
  115. cout<<"NO"<<endl;
  116. else
  117. cout<<"YES"<<endl;
  118. }
  119. return ;
  120. }
  121.  
  122. /****************************************/
  123. poj 点序逆时针
  124. /****************************************/
  125.  
  126. #include <iostream>
  127. #include <cmath>
  128. #include <algorithm>
  129. using namespace std;
  130. const double eps = 1e-;
  131. const double maxn = 0x7f7f7f7f;
  132. int dcmp(double x){
  133. if(fabs(x)<eps)
  134. return ;
  135. else
  136. return x<?-:;
  137. }
  138. struct point {
  139. double x,y;
  140. point (double x=,double y =):x(x),y(y){}
  141. };
  142. point p[];
  143. typedef point Vector;
  144.  
  145. struct polygon{
  146. point p[];
  147. int Size;
  148. };
  149.  
  150. struct line{
  151. point fir,sec;
  152. line(point a = point(),point b = point()){
  153. fir = a;
  154. sec = b;
  155. }
  156. };
  157.  
  158. Vector operator -(point a,point b){
  159. return Vector(a.x-b.x,a.y-b.y);
  160. }
  161.  
  162. Vector operator *(Vector a,double p){
  163. return Vector (a.x*p,a.y*p);
  164. }
  165. Vector operator + (Vector a,Vector b){
  166. return Vector (a.x+b.x,a.y+b.y);
  167. }
  168.  
  169. double cross(Vector a,Vector b){
  170. return a.x*b.y-a.y*b.x;
  171. }
  172.  
  173. double dot(Vector a,Vector b){
  174. return a.x*b.x+a.y*b.y;
  175. }
  176.  
  177. point getLineIntersection(point p,Vector v,point q,Vector w){
  178. Vector u = p-q;
  179. double t = cross(w,u)/cross(v,w);
  180. return p+v*t;
  181. }
  182.  
  183. bool onsegment(point p,point a1,point a2){
  184. return dcmp(cross(a1-p,a2-p))==&&dcmp(dot(a1-p,a2-p))<;
  185. }
  186.  
  187. polygon cutploygon(polygon poly,line ln){
  188. polygon newploy;
  189. int m=;
  190. int n = poly.Size;
  191. point a = ln.fir,b = ln.sec;
  192. for(int i=;i<n;i++){
  193. point c = poly.p[i];
  194. point d = poly.p[(i+)%n];
  195. double cc = cross(b-a,c-a);
  196. double dd = cross(b-a,d-a);
  197. if(cc>=)
  198. newploy.p[m++] = c;
  199. if(cc*dd<)
  200. newploy.p[m++] = getLineIntersection(a,b-a,c,d-c);
  201. }
  202. newploy.Size = m;
  203. return newploy;
  204. }
  205.  
  206. int main()
  207. {
  208. int n;
  209. while(cin>>n&&n){
  210. for(int i=;i<n;i++)
  211. cin>>p[i].x>>p[i].y;
  212. polygon poly;
  213. poly.Size = ;
  214. poly.p[].x = -maxn;
  215. poly.p[].y = -maxn;
  216. poly.p[].x = maxn;
  217. poly.p[].y = -maxn;
  218. poly.p[].x = maxn;
  219. poly.p[].y = maxn;
  220. poly.p[].x = -maxn;
  221. poly.p[].y = maxn;
  222. bool flag = true;
  223. for(int i=;i<n;i++){
  224. line ln;
  225. ln.fir = p[i%n];
  226. ln.sec = p[(i+)%n];
  227. poly = cutploygon(poly,ln);
  228. if(poly.Size==){
  229. flag = false;
  230. break;
  231. }
  232. }
  233. if(!flag)
  234. cout<<""<<endl;
  235. else
  236. cout<<""<<endl;
  237. }
  238. return ;
  239. }
  240.  
  241. /*************************************/
  242. poj 点序顺时针
  243. /*************************************/
  244. #include <iostream>
  245. #include <cmath>
  246. #include <algorithm>
  247. using namespace std;
  248. const double eps = 1e-;
  249. const double maxn = 0x7f7f7f7f;
  250. int dcmp(double x){
  251. if(fabs(x)<eps)
  252. return ;
  253. else
  254. return x<?-:;
  255. }
  256. struct point {
  257. double x,y;
  258. point (double x=,double y =):x(x),y(y){}
  259. };
  260. point p[];
  261. typedef point Vector;
  262.  
  263. struct polygon{
  264. point p[];
  265. int Size;
  266. };
  267.  
  268. struct line{
  269. point fir,sec;
  270. line(point a = point(),point b = point()){
  271. fir = a;
  272. sec = b;
  273. }
  274. };
  275.  
  276. Vector operator -(point a,point b){
  277. return Vector(a.x-b.x,a.y-b.y);
  278. }
  279.  
  280. Vector operator *(Vector a,double p){
  281. return Vector (a.x*p,a.y*p);
  282. }
  283. Vector operator + (Vector a,Vector b){
  284. return Vector (a.x+b.x,a.y+b.y);
  285. }
  286.  
  287. double cross(Vector a,Vector b){
  288. return a.x*b.y-a.y*b.x;
  289. }
  290.  
  291. double dot(Vector a,Vector b){
  292. return a.x*b.x+a.y*b.y;
  293. }
  294.  
  295. point getLineIntersection(point p,Vector v,point q,Vector w){
  296. Vector u = p-q;
  297. double t = cross(w,u)/cross(v,w);
  298. return p+v*t;
  299. }
  300.  
  301. bool onsegment(point p,point a1,point a2){
  302. return dcmp(cross(a1-p,a2-p))==&&dcmp(dot(a1-p,a2-p))<;
  303. }
  304.  
  305. polygon cutploygon(polygon poly,line ln){
  306. polygon newploy;
  307. int m=;
  308. int n = poly.Size;
  309. point a = ln.fir,b = ln.sec;
  310. for(int i=;i<n;i++){
  311. point c = poly.p[i];
  312. point d = poly.p[(i+)%n];
  313. double cc = cross(b-a,c-a);
  314. double dd = cross(b-a,d-a);
  315. if(cc>=)
  316. newploy.p[m++] = c;
  317. if(cc*dd<)
  318. newploy.p[m++] = getLineIntersection(a,b-a,c,d-c);
  319. }
  320. newploy.Size = m;
  321. return newploy;
  322. }
  323.  
  324. int main()
  325. {
  326. int n;
  327. int cnt =;
  328. while(cin>>n&&n){
  329. for(int i=;i<n;i++)
  330. cin>>p[i].x>>p[i].y;
  331. polygon poly;
  332. poly.Size = ;
  333. poly.p[].x = -maxn;
  334. poly.p[].y = -maxn;
  335. poly.p[].x = maxn;
  336. poly.p[].y = -maxn;
  337. poly.p[].x = maxn;
  338. poly.p[].y = maxn;
  339. poly.p[].x = -maxn;
  340. poly.p[].y = maxn;
  341. bool flag = true;
  342. for(int i=;i<=n;i++){
  343. line ln;
  344. ln.fir = p[i%n];
  345. ln.sec = p[i-];
  346. poly = cutploygon(poly,ln);
  347. if(poly.Size==){
  348. flag = false;
  349. break;
  350. }
  351. }
  352. //cout<<poly.Size<<endl;
  353. cout<<"Floor #"<<cnt++<<endl;
  354. if(!flag)
  355. cout<<"Surveillance is impossible."<<endl;
  356. else
  357. cout<<"Surveillance is possible."<<endl;
  358. cout<<endl;
  359. }
  360. return ;
  361. }
  362.  
  363. /**********************************
  364. poj 1279 点序顺时针
  365. **********************************/
  366. #include <iostream>
  367. #include <cmath>
  368. #include <algorithm>
  369. #include <cstdio>
  370. using namespace std;
  371. const double eps = 1e-;
  372. const double maxn = 0x7f7f7f7f;
  373. int dcmp(double x){
  374. if(fabs(x)<eps)
  375. return ;
  376. else
  377. return x<?-:;
  378. }
  379. struct point {
  380. double x,y;
  381. point (double x=,double y =):x(x),y(y){}
  382. };
  383. point p[];
  384. typedef point Vector;
  385.  
  386. struct polygon{
  387. point p[];
  388. int Size;
  389. };
  390.  
  391. struct line{
  392. point fir,sec;
  393. line(point a = point(),point b = point()){
  394. fir = a;
  395. sec = b;
  396. }
  397. };
  398.  
  399. Vector operator -(point a,point b){
  400. return Vector(a.x-b.x,a.y-b.y);
  401. }
  402.  
  403. Vector operator *(Vector a,double p){
  404. return Vector (a.x*p,a.y*p);
  405. }
  406. Vector operator + (Vector a,Vector b){
  407. return Vector (a.x+b.x,a.y+b.y);
  408. }
  409.  
  410. double cross(Vector a,Vector b){
  411. return a.x*b.y-a.y*b.x;
  412. }
  413.  
  414. double dot(Vector a,Vector b){
  415. return a.x*b.x+a.y*b.y;
  416. }
  417.  
  418. point getLineIntersection(point p,Vector v,point q,Vector w){
  419. Vector u = p-q;
  420. double t = cross(w,u)/cross(v,w);
  421. return p+v*t;
  422. }
  423.  
  424. bool onsegment(point p,point a1,point a2){
  425. return dcmp(cross(a1-p,a2-p))==&&dcmp(dot(a1-p,a2-p))<;
  426. }
  427.  
  428. polygon cutploygon(polygon poly,line ln){
  429. polygon newploy;
  430. int m=;
  431. int n = poly.Size;
  432. point a = ln.fir,b = ln.sec;
  433. for(int i=;i<n;i++){
  434. point c = poly.p[i];
  435. point d = poly.p[(i+)%n];
  436. double cc = cross(b-a,c-a);
  437. double dd = cross(b-a,d-a);
  438. if(cc>=)
  439. newploy.p[m++] = c;
  440. if(cc*dd<)
  441. newploy.p[m++] = getLineIntersection(a,b-a,c,d-c);
  442. }
  443. newploy.Size = m;
  444. return newploy;
  445. }
  446.  
  447. double polyArea(point *p,int n){
  448. double area =;
  449. for(int i=;i<n-;i++){
  450. area += cross(p[i]-p[],p[i+]-p[]);
  451. }
  452. return area/;
  453. }
  454.  
  455. int main()
  456. {
  457. int t;
  458. cin>>t;
  459. int n;
  460. while(t--){
  461. cin>>n;
  462. for(int i=;i<n;i++)
  463. cin>>p[i].x>>p[i].y;
  464. polygon poly;
  465. poly.Size = ;
  466. poly.p[].x = -maxn;
  467. poly.p[].y = -maxn;
  468. poly.p[].x = maxn;
  469. poly.p[].y = -maxn;
  470. poly.p[].x = maxn;
  471. poly.p[].y = maxn;
  472. poly.p[].x = -maxn;
  473. poly.p[].y = maxn;
  474. bool flag = true;
  475. for(int i=;i<=n;i++){
  476. line ln;
  477. ln.fir = p[i%n];
  478. ln.sec = p[i-];
  479. poly = cutploygon(poly,ln);
  480. if(poly.Size==){
  481. flag = false;
  482. break;
  483. }
  484. }
  485. double res;
  486. if(!flag)
  487. res =;
  488. else{
  489. res = polyArea(poly.p,poly.Size);
  490. }
  491. printf("%.2lf\n",res);
  492. }
  493. return ;
  494. }

poj 3335 /poj 3130/ poj 1474 半平面交 判断核是否存在 / poj1279 半平面交 求核的面积的更多相关文章

  1. 三道半平面交测模板题 Poj1474 Poj 3335 Poj 3130

    求半平面交的算法是zzy大神的排序增量法. ///Poj 1474 #include <cmath> #include <algorithm> #include <cst ...

  2. poj 3335 Rotating Scoreboard(半平面交)

    Rotating Scoreboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6420   Accepted: 25 ...

  3. POJ 3335 Rotating Scoreboard 半平面交求核

    LINK 题意:给出一个多边形,求是否存在核. 思路:比较裸的题,要注意的是求系数和交点时的x和y坐标不要搞混...判断核的顶点数是否大于1就行了 /** @Date : 2017-07-20 19: ...

  4. POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交

    题意:逆时针给出N个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...

  5. POJ 1279 Art Gallery 半平面交/多边形求核

    http://poj.org/problem?id=1279 顺时针给你一个多边形...求能看到所有点的面积...用半平面对所有边取交即可,模版题 这里的半平面交是O(n^2)的算法...比较逗比.. ...

  6. poj 3335 Rotating Scoreboard - 半平面交

    /* poj 3335 Rotating Scoreboard - 半平面交 点是顺时针给出的 */ #include <stdio.h> #include<math.h> c ...

  7. POJ 3304 Segments 基础线段交判断

    LINK 题意:询问是否存在直线,使得所有线段在其上的投影拥有公共点 思路:如果投影拥有公共区域,那么从投影的公共区域作垂线,显然能够与所有线段相交,那么题目转换为询问是否存在直线与所有线段相交.判断 ...

  8. POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)

    POJ 3177 Redundant Paths POJ 3352 Road Construction 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...

  9. poj 3335(半平面交)

    链接:http://poj.org/problem?id=3335     //大牛们常说的测模板题 ------------------------------------------------- ...

随机推荐

  1. jQuery Lint: enables you to automatically inject jQuery Lint into the page as it is loaded (great for ad-hoc code validation)

    FireQuery is a Firebug extension for jQuery development jQuery Lint: enables you to automatically in ...

  2. hdu 4497 GCD and LCM(2013 ACM-ICPC吉林通化全国邀请赛——题目重现)

    质分解 + 简单计数.当时去比赛的时候太年轻了...这道题都没敢想.现在回过头来做了一下,发现挺简单的,当时没做这道题真是挺遗憾的.这道题就是把lcm  / gcd 质分解,统计每个质因子的个数,然后 ...

  3. oracle中clob字段的使用

    oracle中定义了一个字段是clob的,由于用的是ssh的框架,结果在面向对象存取的时候出现clob类型字段和String类型字段的转换问题.开始查阅了clob字段和String字段的相互转换的方法 ...

  4. HTML本地存储,localstorg的应用实例

    <!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...

  5. Android学习路线(二十)运用Fragment构建动态UI

    要在Android系统上创建一个动态或者多面板的用户界面,你须要将UI组件以及activity行为封装成模块.让它可以在你的activity中灵活地切换显示与隐藏. 你可以使用Fragment类来创建 ...

  6. android UI进阶之用ViewPager实现欢迎引导页面[转]

    ViewPager需要android-support-v4.jar这个包的支持,来自google提供的一个附加包.大家搜下即可. ViewPager主要用来组织一组数据,并且通过左右滑动的方式来展示. ...

  7. Problem A: Artificial Intelligence?

    Description Physics teachers in high school often think that problems given as text are more demandi ...

  8. A Byte of Python 笔记(9) 面向对象编程

    第11章  面向对象编程 面向过程:根据操作数据的函数或语句块来设计程序. 面向对象(OOP, object-oriented programming):把数据和功能结合起来,用对象包裹组织程序. 类 ...

  9. Bootstrap Alert 使用

    参考 http://www.bootcss.com/javascript.html#alerts 不过这里没有动态alert的例子 于是再参考http://stackoverflow.com/ques ...

  10. Oracle中sign函数和decode函数的使用

    Oracle中sign函数和decode函数的使用 1.比较大小函数SIGN sign(x)或者Sign(x)叫做 符号函数,其功能是取某个数的符号(正或负): 当x>0,sign(x)=1; ...