結果

問題 No.461 三角形はいくつ?
ユーザー YamyukiYamyuki
提出日時 2016-12-13 15:31:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 517 ms / 5,000 ms
コード長 1,262 bytes
コンパイル時間 473 ms
コンパイル使用メモリ 65,780 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 01:53:44
合計ジャッジ時間 8,378 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 236 ms
4,380 KB
testcase_06 AC 124 ms
4,380 KB
testcase_07 AC 152 ms
4,380 KB
testcase_08 AC 101 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 31 ms
4,376 KB
testcase_11 AC 173 ms
4,380 KB
testcase_12 AC 75 ms
4,380 KB
testcase_13 AC 261 ms
4,380 KB
testcase_14 AC 245 ms
4,380 KB
testcase_15 AC 259 ms
4,376 KB
testcase_16 AC 10 ms
4,380 KB
testcase_17 AC 10 ms
4,380 KB
testcase_18 AC 343 ms
4,376 KB
testcase_19 AC 350 ms
4,380 KB
testcase_20 AC 265 ms
4,380 KB
testcase_21 AC 254 ms
4,380 KB
testcase_22 AC 251 ms
4,380 KB
testcase_23 AC 43 ms
4,384 KB
testcase_24 AC 38 ms
4,380 KB
testcase_25 AC 55 ms
4,376 KB
testcase_26 AC 53 ms
4,380 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 480 ms
4,376 KB
testcase_30 AC 436 ms
4,376 KB
testcase_31 AC 497 ms
4,376 KB
testcase_32 AC 517 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 79 ms
4,380 KB
testcase_37 AC 70 ms
4,380 KB
testcase_38 AC 76 ms
4,376 KB
testcase_39 AC 63 ms
4,380 KB
testcase_40 AC 79 ms
4,380 KB
testcase_41 AC 73 ms
4,380 KB
testcase_42 AC 241 ms
4,380 KB
testcase_43 AC 249 ms
4,380 KB
testcase_44 AC 233 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>

typedef struct {
	long double h[4001];
} hens;


int check(long double a,long double b){
	if(a-b>-0.00000000000000001 && a-b<0.00000000000000001) return 0;
	if(a-b>0) return 1;
	return -1;
}


int cmp(const void *a,const void *b){
	return check(*(long double*)a,*(long double*)b);
}

long search(long double *hen,long double max,int s,int e){
	if(e==s) return e;
	if(check(hen[(s+e)/2+1],max)>0){
		return search(hen,max,s,(s+e)/2);
	}else{
		return search(hen,max,(s+e)/2+1,e);
	}
}

int main(){
	int n,i,j,k;
	int p,h[3];
	long double s;
	hens hen[3];
	long a,b,c,comp;
	scanf("%d",&n);
	for(i=0;i<3;i++){
		h[i]=1;
		hen[i].h[0]=0.0;
	}
	for(i=0;i<n;i++){
		scanf("%d %ld %ld",&p,&a,&b);
		hen[p].h[h[p]]=(long double)b/(long double)(a+b);
		h[p]++;
	}
	//for(i=0;i<3;i++){
	qsort(hen[2].h,h[2],sizeof(long double),cmp);
	//}
	c=0;
	for(i=0;i<h[0];i++){
		for(j=0;j<h[1];j++){
			if(check(1.0,hen[0].h[i]+hen[1].h[j])==-1) continue;
			if(check(hen[0].h[i],hen[1].h[j])>0){
				s=1.0-hen[0].h[i];
			}else{
				s=1.0-hen[1].h[j];
			}
			comp=search(hen[2].h,s,0,h[2]-1);
			c+=comp+1;
			if(check(hen[2].h[search(hen[2].h,1.0-hen[0].h[i]-hen[1].h[j],0,comp)],1.0-hen[0].h[i]-hen[1].h[j])==0) c--;
			}
	}
	printf("%ld\n",c);
	return 0;
}
0