結果

問題 No.947 ABC包囲網
ユーザー vectorccvectorcc
提出日時 2020-01-21 13:40:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,550 bytes
コンパイル時間 1,029 ms
コンパイル使用メモリ 80,908 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-18 19:37:03
合計ジャッジ時間 8,483 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,388 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 140 ms
4,380 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
権限があれば一括ダウンロードができます

ソースコード

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