#include "common.h"
	
void Usage(void) {
	printf("分析超过指定票数的人数的概率\nanalyse 人数 票数1 [票数2..票数%d]\n", MAX_VOTES_LIMIT_SIZE);
}

void GetOneVotes(unsigned long number, unsigned long* votes) {
	for (int j=0; j<number; ++j) {
		scanf("%u,", votes+j);
	}
}

unsigned long VotesOverLimit(unsigned long number, const unsigned long* votes, unsigned long votesLimit) {
	unsigned long retVal = 0;
	for (unsigned long i=0; i<number; ++i) {
		if (votes[i] >= votesLimit) {
			retVal++;
		}
	}
	return retVal;
}

int main(int argc, const char* argv[]) {

	if (3 <= argc && argc <= MAX_VOTES_LIMIT_SIZE+2) {
		unsigned long candidateNumberLimit = atoi(argv[1]);
		unsigned long votesLimits[MAX_VOTES_LIMIT_SIZE];
		unsigned long votesLimitSize = argc-2;
		
		for (int i=0; i<votesLimitSize; ++i) {
			votesLimits[i] = atoi(argv[i+2]);
		}
		
		unsigned long candidateNumber = 0;
		unsigned long quota = 0;
		unsigned long judgerNumber = 0;
		unsigned long simulationTimes = 0;
		scanf("%u,%u,%u,%u", &candidateNumber, &quota, &judgerNumber, &simulationTimes);
		
		
		if (1 <= candidateNumber && candidateNumber <= MAX_CANDIDATE_NUMBER &&
		    1 <= quota && quota <= MAX_QUOTA &&
			1 <= judgerNumber && judgerNumber <= MAX_JUDGER_NUMBER &&
			10 <= simulationTimes && simulationTimes <= MAX_SIMULATION_TIMES) {
			
			unsigned long passTimes[MAX_VOTES_LIMIT_SIZE];
			ZeroArray(passTimes, votesLimitSize);
			
			for (unsigned long i=0; i<simulationTimes; ++i) {
				unsigned long votes[MAX_CANDIDATE_NUMBER];
				GetOneVotes(candidateNumber, votes);
				
				for (unsigned long j=0; j<votesLimitSize; ++j) {
					if (VotesOverLimit(candidateNumber, votes, votesLimits[j]) >= candidateNumberLimit) {
						passTimes[j]++;
					}
				}
			}
			
			for (unsigned long i=0; i<votesLimitSize; ++i) {
				printf("%.03f,",passTimes[i]*1.0/simulationTimes);
			}
			printf("\n");
			
		} else {
			printf("数据不对，参考vote的参数\n");
		}
		
	} else {
		Usage();
	}
	
	return 0;
}