我写了这道题,然后第二个点挂了。
用的是叉乘。
我通过试的方式知道了:
第二个点应该输出1,但是我的输出2
大佬救救橘蒻吧!!!!!代码很好懂的!!!!
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
string aa,bb,cc,dd;
struct node{
int x,y;
};
node a,b,c,d;
bool fir;
node pls(node xx, node yy){
node ans;
ans.x=xx.x-yy.x;
ans.y=xx.y-yy.y;
return ans;
}
int chac(node xx, node yy){
return (xx.x*yy.y)-(xx.y*yy.x);
}
int dianc(node xx, node yy){
return (xx.x*yy.x)+(xx.y*yy.y);
}
int main(){
cin>>aa>>bb>>cc>>dd;
for(int i=1;i<aa.length()-1;++i){
if(aa[i]==','){fir=1;continue;}
if(!fir){
a.x*=10;
a.x+=(aa[i]-'0');
}
else{
a.y*=10;
a.y+=(aa[i]-'0');
}
}fir=0;
for(int i=1;i<bb.length()-1;++i){
if(bb[i]==','){fir=1;continue;}
if(!fir){
b.x*=10;
b.x+=(bb[i]-'0');
}
else{
b.y*=10;
b.y+=(bb[i]-'0');
}
}
for(int i=1;i<cc.length()-1;++i){
if(cc[i]==','){fir=1;continue;}
if(!fir){
c.x*=10;
c.x+=(cc[i]-'0');
}
else{
c.y*=10;
c.y+=(cc[i]-'0');
}
}fir=0;
for(int i=1;i<dd.length()-1;++i){
if(dd[i]==','){fir=1;continue;}
if(!fir){
d.x*=10;
d.x+=(dd[i]-'0');
}
else{
d.y*=10;
d.y+=(dd[i]-'0');
}
}
if(d.x==a.x && d.y == a.y){cout<<4<<endl;return 0;}
if(d.x==b.x && d.y == b.y){cout<<4<<endl;return 0;}
if(d.x==c.x && d.y == c.y){cout<<4<<endl;return 0;}
int zhe=0;//叉积为正
if(chac(pls(a,d),pls(b,d)) > 0){
zhe+=1;
}else if(chac(pls(a,d),pls(b,d))==0){
if(dianc(pls(a,d),pls(b,d))<0){
cout<<3<<'\n';
return 0;
}
}
if(chac(pls(b,d),pls(c,d)) > 0){
zhe+=1;
}else if(chac(pls(b,d),pls(c,d))==0){
if(dianc(pls(b,d),pls(c,d))<0){
cout<<3<<'\n';
return 0;
}
}
if(chac(pls(c,d),pls(a,d)) > 0){
zhe+=1;
//cout<<'k'<<endl;
}else if(chac(pls(c,d),pls(a,d))==0){
if(dianc(pls(c,d),pls(a,d))<0){
cout<<3<<'\n';
return 0;
}
}
if(zhe==3 || zhe==0){
cout<<1<<'\n';
}
else{
cout<<2<<'\n';
}
//cout<<zhe<<endl;
return 0;
}
大佬别走啊