Submission #1370624


Source Code Expand

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

#define datatype double

typedef enum{
	false,
	true
}Boolean;

//比較関数
int compare(datatype a, datatype b){
	if(a < b){
		return -1;
	}
	else if(a > b){
		return 1;
	}
	else{
		return 0;
	}
}

void sort_sub(datatype *origin, int left, int right, datatype *tmp){
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		sort_sub(origin, left, half, tmp);
		sort_sub(origin, half, right, tmp);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if((compare(tmp[j], tmp[k]) >= 0 && j < half) || k == right){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				k++;
			}
		}
	}
}

void sort(datatype *origin, int N){
	datatype *tmp = (datatype *)malloc(sizeof(datatype) * N);
	sort_sub(origin, 0, N, tmp);
}

Boolean can_achieve(int N, int K, int *w, int *p, double h){
	int i;
	double *s = (double *)malloc(sizeof(double) * N);
	for(i = 0; i < N; i++){
		s[i] = (p[i] - h) * w[i];
	}
	sort(s, N);
	double sum = 0;
	for(i = 0; i < K; i++){
		sum += s[i];
	}
	if(sum >= 0){
		return true;
	}
	else{
		return false;
	}
}

int main(){
	int N, K, i;
	scanf("%d%d", &N, &K);
	int *w = (int *)malloc(sizeof(int) * N);
	int *p = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%d%d", &w[i], &p[i]);
	}
	double l, r, h;
	for(l = 0, r = 100; r - l > 1e-10; ){
		//printf("test:(l, r) = (%f, %f)\n", l, r);
		h = (r + l) / 2;
		if(can_achieve(N, K, w, p, h) == true){
			l = h;
		}
		else{
			r = h;
		}
	}
	printf("%2.9f\n", l);
	return 0;
}

Submission Info

Submission Time
Task D - 食塩水
User abc050
Language C (GCC 5.4.1)
Score 100
Code Size 1681 Byte
Status AC
Exec Time 4 ms
Memory 768 KB

Compile Error

./Main.c: In function ‘main’:
./Main.c:71:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &K);
  ^
./Main.c:75:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &w[i], &p[i]);
   ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 22
Set Name Test Cases
Sample s0.txt, s1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, s0.txt, s1.txt
Case Name Status Exec Time Memory
000.txt AC 3 ms 768 KB
001.txt AC 1 ms 256 KB
002.txt AC 3 ms 768 KB
003.txt AC 1 ms 256 KB
004.txt AC 3 ms 768 KB
005.txt AC 3 ms 768 KB
006.txt AC 3 ms 768 KB
007.txt AC 3 ms 640 KB
008.txt AC 3 ms 768 KB
009.txt AC 1 ms 256 KB
010.txt AC 3 ms 768 KB
011.txt AC 2 ms 512 KB
012.txt AC 4 ms 768 KB
013.txt AC 2 ms 512 KB
014.txt AC 3 ms 768 KB
015.txt AC 3 ms 640 KB
016.txt AC 3 ms 768 KB
017.txt AC 2 ms 640 KB
018.txt AC 3 ms 768 KB
019.txt AC 3 ms 640 KB
s0.txt AC 1 ms 128 KB
s1.txt AC 1 ms 128 KB