結果

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

ソースコード

diff #

#include<stdio.h>

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

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

int main(){
	int n,i,j,k;
	int p,h[3];
	double hen[3][4001],comp;
	long a,b,c;
	scanf("%d",&n);
	for(i=0;i<3;i++){
		h[i]=1;
		hen[i][0]=1.0;
	}
	for(i=0;i<n;i++){
		scanf("%d %ld %ld",&p,&a,&b);
		hen[p][h[p]]=(double)a/(double)(a+b);
		h[p]++;
	}
	for(i=0;i<3;i++){
		qsort(hen[i],h[i],sizeof(double),cmp);
	}
	/*c=0;
	for(i=0;i<h[0];i++){
		for(j=h[1]-1;j>=0;j--){
			if(check(1.0-hen[0][i],hen[1][j])<=0){
				comp=(check(hen[0][i],hen[1][i])<=0)?1.0-hen[1][j]:1.0-hen[0][i];
				for(k=h[2]-1;k>=0;k--){
					if(check(comp,hen[2][k])<=0){
						if(check(2.0-hen[0][i]-hen[1][j],hen[2][k])!=0){
							c++;
						}
					}else{
						break;
					}
				}
			}else{
				break;
			}
		}
	}*/
	c=h[0]*h[1]*h[2];
	for(i=0;i<h[0];i++){
		for(j=h[1]-1;j>=0;j--){
			if(check(1.0-hen[0][i],hen[1][j])<=0){
				comp=(check(hen[0][i],hen[1][i])<=0)?1.0-hen[1][j]:1.0-hen[0][i];
				for(k=h[2]-1;k>=0;k--){
					if(check(comp,hen[2][k])<=0){
						if(check(2.0-hen[0][i]-hen[1][j],hen[2][k])==0){
							c--;
						}
					}else{
						c-=k+1;
						break;
					}
				}
			}else{
				c-=j+1;
				break;
			}
		}
	}
	printf("%ld\n",c);
	return 0;
}
0