https://www.nowcoder.com/acm/contest/110/B
链接:https://www.nowcoder.com/acm/contest/110/B
题目描述
为了让所有选手都感到开心,Nowcoder练习赛总会包含一些非常基本的问题。
比如说: 按顺时针或逆时针方向给你一个简单的多边形的顶点坐标,请回答此多边形是顺时针还是逆时针。
输入描述:
输入包含N + 1行。第一行包含一个整数N,表示简单多边形的顶点数。在下面的N行中,
第i行包含两个整数xi,yi,表示简单多边形中的第i个顶点的坐标。
输出描述:
如果简单多边形按顺时针顺序给出,则在一行中输出“clockwise”(不带引号)。
否则,打印"counterclockwise''(不带引号)。
示例1
输入
3
0 0
1 0
0 1
输出
counterclockwise
示例2
输入
3
0 0
0 1
1 0
输出
clockwise
备注:
3≤N≤30-1000≤xi,yi≤1000数据保证,这个简单多边形的面积不为零。
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200050;
const double eps = 1e-8;
typedef struct Point{
double x, y;
}Point;
double cross(Point a,Point b,Point c){
double t=((a.x-c.x)*(b.y-c.y)) - ( (b.x-c.x) * (a.y-c.y) );
return t;
}
double PolygonArea(Point p[], int n)
{
if(n < 3) return 0.0;
double s = p[0].y * (p[n - 1].x - p[1].x);
p[n] = p[0];
for(int i = 1; i < n; ++ i)
s += p[i].y * (p[i - 1].x - p[i + 1].x);
return s * 0.5;
}
Point p1[maxn];
int n1;
int main()
{
while(scanf("%d",&n1) != EOF ){
for(int i = 0; i < n1; i++)
scanf("%lf%lf", &p1[i].x, &p1[i].y);
if ( PolygonArea(p1,n1) > 0 )
puts("counterclockwise");
else
puts("clockwise");
}
return 0;
}