Copy Code code as follows:
Take HDU2108 For example, go to AC bar.
Point in reverse order input
Import Java.util.Scanner;
1s
public class HDU2108 {
public static void Main (string[] args) {
Scanner sc = new Scanner (system.in);
while (true) {
int x,y;
int n = sc.nextint ();
if (0==n) {
Break
}
Point[] p = new Point[n];
for (int i=0; i<n; i++) {
P[i] = new Point ();
}
for (int i=0; i<n; i++) {
x = Sc.nextint ();
y = Sc.nextint ();
P[i] = new Point (x,y);
}
Polygons
Boolean tag = true;
int j,k,t;
for (int i=0; i<n; i++) {
K,t directly to the N on the line
j = i;
K = i+1;
t = i+2;
Take the triangle as an example to see
if (k==n) {
k = 0;
}
if (t==n+1) {
t = 1;
}
if (t==n) {
t = 0;
}
Note that the back minus the front
Point P1 = new Point (p[k].x-p[j].x,
P[K].Y-P[J].Y);
Point P2 = new Point (p[t].x-p[k].x,
P[T].Y-P[K].Y);
Cross product
int ans = p1.x*p2.y-p1.y*p2.x;
if (ans<0) {
Tag = false;
Break
}
}
if (tag) {
System.out.println ("convex");
}else {
SYSTEM.OUT.PRINTLN ("concave");
}
}
}
}
Class Point {
int x;
int y;
Public Point () {
this.x = 0;
This.y = 0;
}
public point (int x, int y) {
this.x = x;
This.y = y;
}
}