Sicily.1046. Plane Spotting(排序)
来源:互联网 发布:淘宝店铺客服怎么应聘 编辑:程序博客网 时间:2024/05/17 03:36
/*1046. Plane Spotting 大意:给出一串时间段内飞过的飞机数量。按照规定顺序排序得出 结果 */#include <iostream>#include <algorithm> #include <stdlib.h>using namespace std;//用系统函数sort,定义比较函数compare,按照指定顺序排序 struct planPeriod{ int start; int end; double aver;};bool compare(planPeriod a, planPeriod b){ if(a.aver > b.aver) return 1; if(a.aver == b.aver && a.end - a.start > b.end - b.start) return 1; if(a.aver == b.aver && a.end - a.start == b.end - b.start && a.end < b.end) return 1; return 0;}int main(){ int N; cin >> N; int pN, topN, minN; planPeriod p[100000]; for(int i=1; i<=N; i++) { int plane[300]; cin >> pN >> topN >> minN; for(int k=0; k<pN; k++) cin >> plane[k]; int c=0; for(int sampleN=minN; sampleN <= pN; sampleN++) { for(int t =0; t+sampleN <= pN; t++, c++) { double sum=0; for(int k=t; k-t < sampleN; k++) { sum += plane[k]; } p[c].start = t+1; p[c].end = t+sampleN; p[c].aver = sum/sampleN; } } sort(p,p+c,compare); cout << "Result for run "<< i << ":" << endl; for(int k=0; k<topN && k<c; k++) cout << p[k].start << "-" << p[k].end << endl; } system("pause"); return 0;}