【hdu 2108】Shape of HDU
of HDU Shape
2023-09-14 09:03:48 时间
【题目链接】:http://acm.hdu.edu.cn/showproblem.php?pid=2108
【题意】
【题解】
逆时针;
可以想象一下;
如果是凸多边形的话;
逆时针的相邻的两条边;
前一条和后一条(逆时针意义上的“后一条”)边所代表的向量;
如果做叉积的话;
其结果肯定是指向屏幕外面的;
如果突然变成凹的了;
再做叉乘的话;
指向是屏幕里面的了;
也就是说如果是凸多边形的话;
叉乘的结果应该都为正数;
【Number Of WA】
0
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 11000;
struct point
{
double x,y;
};
double chaji(point a,point b)
{
double x1 = a.x,y1 = a.y;
double x2 = b.x,y2 = b.y;
return x1*y2-x2*y1;
}
int n;
point a[N];
int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false);
while (cin >> n)
{
if (n==0) break;
rep1(i,1,n)
cin >> a[i].x >> a[i].y;
a[n+1]=a[1],a[n+2]=a[2];
bool fi = false;
rep1(i,1,n)
{
point v1 = point{a[i+1].x-a[i].x,a[i+1].y-a[i].y};
point v2 = point{a[i+2].x-a[i+1].x,a[i+2].y-a[i+1].y};
if (chaji(v1,v2)<0) fi = true;
}
if (fi)
cout <<"concave"<<endl;
else
cout <<"convex"<<endl;
}
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
相关文章
- 记录一次在生成数据库服务器上出现The timeout period elapsed prior to completion of the operation or the server is not responding.和Exception has been thrown by the target of an invocation的解决办法
- HDU 3920 Clear All of Them I(DP + 状态压缩 + 贪心)
- [Typescript] Map an Object to a Union of Tuples
- docker报错:Unable to get pid of LinuxThreads manager thread及openjdk-alpine镜像无法打印线程堆栈和内存堆栈问题
- 如何处理UI5一般性错误Cannot read property md of undefined
- 成功解决ValueError: y should be a 1d array, got an array of shape (110000, 3) instead.
- The authenticity of host ‘172.16.132.189 (172.16.132.189)‘ can‘t be established.
- JVM 语言的兴衰 【The Rise and Fall of JVM Languages】
- BaseException: Could not construct partition: Weight vector not the same size as the number of edges