Sicily.1046. Plane Spotting(排序)
2012-12-27 16:26
357 查看
/*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; }
相关文章推荐
- sicily 1046. Plane Spotting(排序求topN)
- sicily 1046 Plane Spotting
- sicily 1046. Plane Spotting
- sicily 1046. Plane Spotting
- Sicily 1046, Plane Spotting
- [sicily online]1046. Plane Spotting
- sicily 1046 Plane Spotting
- sicily 1046 Plane Spotting
- sicily 1046. Plane Spotting
- sicily--1046. Plane Spotting
- sicily 1046. Plane Spotting 排序 结构
- 1046. Plane Spotting
- sicily 选择排序比较次数 期末测试
- Sicily 1142 排序 (SOJ 1142) 【搜索剪枝】
- sicily-1930.排序
- 九度1046(排序)
- sicily 1198. Substring (递归全排列+排序)
- Sicily 1142. 排序
- sicily--1930. 排序
- Sicily. 全排序输出