結果

問題 No.21 平均の差
ユーザー TLwiegehtt
提出日時 2015-07-08 05:16:47
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,097 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 25,472 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-08 01:38:49
合計ジャッジ時間 607 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:71:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   71 |         scanf("%d", &n);
      |         ^~~~~~~~~~~~~~~
main.c:72:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   72 |         scanf("%d", &k);
      |         ^~~~~~~~~~~~~~~
main.c:74:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   74 |                 scanf("%d", &num[i]);
      |                 ^~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int num[15];
int stack[20];
int scnt=0;
int gAve=0;

int compare_int( const void*a, const void*b){
	int ta = *(int*)a;
	int tb = *(int*)b;
	if(ta < tb){
		return -1;
	}else if(ta > tb){
		return 1;
	}
	
	return 0;
}


	
void saiki(int digit, int k){
	int i;
	if(k == 0 && digit == 0){
		int s;
		int tAve;
		int ssum = 0;
		double minAve = 9999999.0;
		double maxAve = 0.0;
		
		for(s=0;s<scnt;s++){
			double ag = 0.0;
			for(i=0;i<stack[s];i++){
				ag = ag + (1.0*num[ssum+i]);
			}
			
			ag = ag/(1.0*stack[s]);
			
			if(minAve > ag ){
				minAve = ag;
			}
			if(maxAve < ag ){
				maxAve = ag;
			}
			
			ssum += stack[s];
		}
		
		tAve = (int)ceil(maxAve-minAve);
		if(gAve < tAve){
			gAve = tAve;
		}
		return;
	}
	
	for(i=1;i<=digit;i++){
		stack[scnt] = i;
		scnt++;
		saiki(digit-i, k-1);
		scnt--;
	}
	
	return;
}

int main(void){
	int i,n,k;
	
	scanf("%d", &n);
	scanf("%d", &k);
	for(i=0;i<n;i++){
		scanf("%d", &num[i]);
	}
	
	qsort(num, n, sizeof(int), compare_int);
	saiki(n,k);
	
	
	printf("%d\n", gAve);
	return 0;
}
0