标签:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
using namespace std;
int w,h,L,i,j,ans;
struct Point{
int x,y;
}p[60];
double Cross(Point a,Point b){
return a.x*b.y-a.y*b.x;
}
int main(){
while(scanf("%d%d",&w,&h),w,h){
Point tmp,tp,tmmp,tmp1,tp1,tmmp1;
ans=1;
scanf("%d",&L);
for(i=0;i<=L;i++){
scanf("%d%d",&p[i].x,&p[i].y);
}
if(L==1){
ans=1;
}
else if(L==2){
ans=1;
}
else{
for(i=L;i>=3;i--){
for(j=i-1;j>=1;j--){
tmp.x=p[i].x-p[i-1].x;
tmp.y=p[i].y-p[i-1].y;
tp.x=p[j-1].x-p[i-1].x;
tp.y=p[j-1].y-p[i-1].y;
tmmp.x=p[j].x-p[i-1].x;
tmmp.y=p[j].y-p[i-1].y;
tmp1.x=p[j].x-p[j-1].x;
tmp1.y=p[j].y-p[j-1].y;
tp1.x=p[i-1].x-p[j-1].x;
tp1.y=p[i-1].y-p[j-1].y;
tmmp1.x=p[i].x-p[j-1].x;
tmmp1.y=p[i].y-p[j-1].y;
double c1=Cross(tmp,tp),c2=Cross(tmp,tmmp);
double c3=Cross(tmp1,tp1),c4=Cross(tmp1,tmmp1);
if( c1*c2 < 0 && c3*c4<0)
ans++;
}
}
}
printf("%d\n",ans+L);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/JiaoZha/p/5698874.html