結果

問題 No.947 ABC包囲網
ユーザー vectorcc
提出日時 2020-01-21 13:38:19
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,550 bytes
コンパイル時間 735 ms
コンパイル使用メモリ 81,448 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 09:13:59
合計ジャッジ時間 7,623 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9 WA * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<cmath>

#define REP(i,j,N) for(int i=j,__i=N;i<__i;++i)

struct Point{
	double x;
	double y;
	Point(double x_=0,double y_=0){
		x=x_;
		y=y_;
	}
	Point(const Point &dst){
		x=dst.x;
		y=dst.y;
	}
	const std::string str()const{
		std::ostringstream osm;
		char buf[128];
		sprintf(buf,"%.16f",x);
		osm<<"("<<buf;
		sprintf(buf,"%.16f",y);
		osm<<","<<buf<<")";
		return osm.str();
	}
};

bool operator<(const Point &src,const Point &dst){
	return src.x<dst.x;
}

int N;

bool input(){
	std::cin>>N;
	return true;
}

double getk(Point &left,Point &right){
	double k=left.y;
	return left.y+(0-left.x)*(right.y-left.y)/(right.x-left.x);
}

int solve(){
	using namespace std;
	vector<Point> points(N),tmp(3);
	Point point,left;
	double k1,k2;
	int count=0;
	REP(i,0,2)
		cin>>points[i].x>>points[i].y;
	REP(i,2,N){
		cin>>points[i].x>>points[i].y;
		REP(j,0,i-1){
			tmp[0]=points[j];
			tmp[1]=points[j+1];
			tmp[2]=points[i];
			sort(tmp.begin(),tmp.end());
			if(tmp[0].x<=0&&tmp[2].x>=0){
				k1=getk(tmp[0],tmp[1]);
				k2=getk(tmp[0],tmp[2]);
				if((k1>0)^(k2>0))
					if(!((k1==0&&tmp[1].x>=0)&&(k2==0&&tmp[2].x>=0))){
//cout<<tmp[0].str()<<tmp[1].str()<<tmp[2].str()<<endl;
//cout<<getk(tmp[0],tmp[1])<<" "<<getk(tmp[0],tmp[2])<<endl;
						k1=getk(tmp[1],tmp[2]);
						if(-k1/(tmp[2].y-tmp[1].y)/(tmp[2].x-tmp[1].y)>0)
							count++;
					}
			}
		}
	}
	return count;
}

int main(){
	input();
	int res=solve();
	std::cout<<res<<std::endl;
}
0