Scrambled Polygon(凸多边形,斜率)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Scrambled Polygon(凸多边形,斜率),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3442字,纯文字阅读大概需要5分钟。
内容图文
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 7805 | Accepted: 3712 |
Description
A closed polygon is called convex if the line segment joining any two points of the polygon lies in the polygon. Figure 1 shows a closed polygon which is convex and one which is not convex. (Informally, a closed polygon is convex if its border doesn‘t have any "dents".)
![技术分享](/upload/getfiles/default/2022/11/11/20221111070322822.jpg)
The subject of this problem is a closed convex polygon in the coordinate plane, one of whose vertices is the origin (x = 0, y = 0). Figure 2 shows an example. Such a polygon will have two properties significant for this problem.
The first property is that the vertices of the polygon will be confined to three or fewer of the four quadrants of the coordinate plane. In the example shown in Figure 2, none of the vertices are in the second quadrant (where x < 0, y > 0).
To describe the second property, suppose you "take a trip" around the polygon: start at (0, 0), visit all other vertices exactly once, and arrive at (0, 0). As you visit each vertex (other than (0, 0)), draw the diagonal that connects the current vertex with (0, 0), and calculate the slope of this diagonal. Then, within each quadrant, the slopes of these diagonals will form a decreasing or increasing sequence of numbers, i.e., they will be sorted. Figure 3 illustrates this point.
![技术分享](/upload/getfiles/default/2022/11/11/20221111070323305.jpg)
![技术分享](/upload/getfiles/default/2022/11/11/20221111070323551.jpg)
Input
Output
Sample Input
0 0 70 -50 60 30 -30 -50 80 20 50 -60 90 -20 -30 -40 -10 -60 90 10
Sample Output
(0,0) (-30,-40) (-30,-50) (-10,-60) (50,-60) (70,-50) (90,-20) (90,10) (80,20) (60,30)
题意:就是给你一些点,起点已经告诉你是(0,0),让输出这个多边形,斜率从小到大表示;
题解:排下序就好了,注意把除变成乘。。。
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<queue> using namespace std; const int INF=0x3f3f3f3f; #define mem(x,y) memset(x,y,sizeof(x)) #define SI(x) scanf("%d",&x); struct Node{ int x,y; friend bool operator < (Node a,Node b){ if(a.y*b.x<b.y*a.x)return true; else return false; } }dt[100010]; int main(){ int k=0; while(~scanf("%d%d",&dt[k].x,&dt[k].y))k++; sort(dt+1,dt+k); for(int i=0;i<k;i++)printf("(%d,%d)\n",dt[i].x,dt[i].y); return 0; }
原文:http://www.cnblogs.com/handsomecui/p/5023727.html
内容总结
以上是互联网集市为您收集整理的Scrambled Polygon(凸多边形,斜率)全部内容,希望文章能够帮你解决Scrambled Polygon(凸多边形,斜率)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。