結果

問題 No.461 三角形はいくつ?
ユーザー Yamyuki
提出日時 2016-12-13 14:26:32
言語 C90
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,243 bytes
コンパイル時間 134 ms
コンパイル使用メモリ 23,256 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-30 00:59:41
合計ジャッジ時間 6,288 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 37 WA * 4
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:47:9: warning: implicit declaration of function ‘qsort’ [-Wimplicit-function-declaration]
   47 |         qsort(hen[2].h,h[2],sizeof(double),cmp);
      |         ^~~~~
main.c:36:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |         scanf("%d",&n);
      |         ^~~~~~~~~~~~~~
main.c:42:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   42 |                 scanf("%d %ld %ld",&p,&a,&b);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>

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

int cmp(const void *a,const void *b){
	if(*(double*)a-*(double*)b>0){
		return 1;
	}
	return -1;
}

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

long search(double *hen,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];
	double comp,s;
	hens hen[3];
	long a,b;
	long long c;
	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]]=(double)b/(double)(a+b);
		h[p]++;
	}
	//for(i=0;i<3;i++){
	qsort(hen[2].h,h[2],sizeof(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+=(long long)(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("%lld\n",c);
	return 0;
}
0