1046. Plane Spotting

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

Craig is fond of planes. Making photographs of planes forms a major part of his daily life. Since he tries to stimulate his social life, and since it’s quite a drive from his home to the airport, Craig tries to be very efficient by investigating what the optimal times are for his plane spotting. Together with some friends he has collected statistics of the number of passing planes in consecutive periods of fifteen minutes (which for obvious reasons we shall call ‘quarters’). In order to plan his trips as efficiently as possible, he is interested in the average number of planes over a certain time period. This way he will get the best return for the time invested. Furthermore, in order to plan his trips with his other activities, he wants to have a list of possible time periods to choose from. These time periods must be ordered such that the most preferable time period is at the top, followed by the next preferable time period, etc. etc. The following rules define which is the order between time periods:

1. A period has to consist of at least a certain number of quarters, since Craig will not drive three hours to be there for just one measly quarter. 
2. A period P1 is better than another period P2 if: 
* the number of planes per quarter in P1 is higher than in P2; 
* the numbers are equal but P1 is a longer period (more quarters); 
* the numbers are equal and they are equally long, but period P1 ends earlier.

Now Craig is not a clever programmer, so he needs someone who will write the good stuff: that means you. So, given input consisting of the number of planes per quarter and the requested number of periods, you will calculate the requested list of optimal periods. If not enough time periods exist which meet requirement 1, you should give only the allowed time periods.

Input

The input starts with a line containing the number of runs N. Next follows two lines for each run. The first line contains three numbers: the number of quarters (1–300), the number of requested best periods (1–100) and the minimum number of quarters Craig wants to spend spotting planes (1–300). The sec-nod line contains one number per quarter, describing for each quarter the observed number of planes. The airport can handle a maximum of 200 planes per quarter.

Output

The output contains the following results for every run:

* A line containing the text “Result for run <N>:” where <N> is the index of the run.

* One line for every requested period: “<F>-<L>” where <F> is first quarter and <L> is the last quarter of the period. The numbering of quarters starts at 1. The output must be ordered such that the most preferable period is at the top.

Sample Input

  1. 3
  2. 10 5 5
  3. 1 5 0 2 1 4 2 5 0 2
  4. 10 3 5
  5. 10 3 1 4 2 6 3 0 8 0
  6. 5 5 5
  7. 1 2 3 4 5

Sample Output

  1. Result for run 1:
  2. 4-8
  3. 2-8
  4. 6-10
  5. 1-8
  6. 2-6
  7. Result for run 2:
  8. 1-6
  9. 1-7
  10. 1-9
  11. Result for run 3:
  12. 1-5

没什么好说的,自己定义一个结构体,然后自定义排序就可以了。。。注意细节:最后输出不够M组怎么办。

  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5. vector<int> num;
  6. struct sub
  7. {
  8. int a;
  9. int b;
  10. double s;
  11. sub(int aa,int bb)
  12. {
  13. a = aa;
  14. b = bb;
  15. int i;
  16. s = 0;
  17. for(i = a;i <= b;i++)
  18. s += num[i];
  19. s = s/(b-a+1);
  20. }
  21. bool operator<(const sub &cc) const
  22. {
  23. if(s != cc.s)
  24. return s > cc.s;
  25. else if(b - a != cc.b - cc.a)
  26. return b - a > cc.b - cc.a;
  27. else
  28. return b < cc.b;
  29. }
  30. };
  31.  
  32. int main()
  33. {
  34. int T;
  35. cin >> T;
  36. int count = 0;
  37. while(T--)
  38. {
  39. count++;
  40. int N,M,K;
  41. cin >> N >> M >> K;
  42. num.resize(N);
  43. vector<sub> temp;
  44. int i;
  45. for(i = 0;i < N;i++)
  46. cin >> num[i];
  47. int j;
  48. for(i = K;i <= N;i++)
  49. {
  50. for(j = 0;j + i - 1< N;j++)
  51. {
  52. sub tt = sub(j,i+j-1);
  53. temp.push_back(tt);
  54. }
  55. }
  56. sort(temp.begin(),temp.end());
  57. cout << "Result for run " << count << ":" << endl;
  58. for(i = 0;i < M && i < temp.size();i++)
  59. {
  60. cout << temp[i].a + 1<< "-" << temp[i].b + 1<< endl;
  61. }
  62. }
  63. return 0;
  64. }

soj1046. Plane Spotting的更多相关文章

  1. sicily 1046. Plane Spotting(排序求topN)

    DescriptionCraig is fond of planes. Making photographs of planes forms a major part of his daily lif ...

  2. sicily 1046. Plane Spotting

    1046. Plane Spotting Time Limit: 1sec    Memory Limit:32MB  Description Craig is fond of planes. Mak ...

  3. 数据的平面拟合 Plane Fitting

    数据的平面拟合 Plane Fitting 看到了一些利用Matlab的平面拟合程序 http://www.ilovematlab.cn/thread-220252-1-1.html

  4. quad 和 plane 区别是什么?

    Quad就是两个三角形组成四边形,Plane会有很多三角形,哦也 貌似Quad拖上去后看不见,很薄的感觉

  5. u3d单词学习plane

    plane n.水平: 平面: 飞机: 木工刨

  6. 【转载】PMC/PEC Boundary Conditions and Plane Wave Simulation

    原文链接 PMC/PEC Boundary Conditions and Plane Wave Simulation (FDTD) OptiFDTD now has options to use Pe ...

  7. codeforces 577E E. Points on Plane(构造+分块)

    题目链接: E. Points on Plane time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  8. Data Plane Development Kit (DPDK): Getting Started

    参考:dpdk getting started 系统: Ubuntu 14.04 内核信息: 执行 uname -a Linux chen-VirtualBox 3.13.0-32-generic # ...

  9. Codeforces Round #115 B. Plane of Tanks: Pro 水题

    B. Plane of Tanks: Pro Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/17 ...

随机推荐

  1. Enterprise Library 4.1 参考源码索引

    http://www.projky.com/entlib/4.1/Microsoft/Practices/EnterpriseLibrary/AppSettings/Configuration/Des ...

  2. 从解决一个java.lang.NoSuchMethodError想到的

    今天在发布系统部署一个web app的时候,发现应用服务器(tomcat 7.0.26)不能正常启动,于是远程登陆到服务器上查看应用服务器的启动日志,在tomcat_home的logs/localho ...

  3. ACM数论之旅1---素数(万事开头难(>_<))

    前言:好多学ACM的人都在问我数论的知识(其实我本人分不清数学和数论有什么区别,反正以后有关数学的知识我都扔进数论分类里面好了) 于是我就准备写一个长篇集,把我知道的数论知识和ACM模板都发上来(而且 ...

  4. Dubbo学习(九) Dubbo面试问题

    Dubbo是Alibaba开源的分布式服务框架,它最大的特点是按照分层的方式来架构,使用这种方式可以使各个层之间解耦合(或者最大限度地松耦合). 从服务模型的角度来看,Dubbo采用的是一种非常简单的 ...

  5. delphi locate函数的使用

    loc1:= qry1.FieldbyName('SPBM').AsString;      //商品编码 loc2:= qry1.FieldbyName('XH').AsString;       ...

  6. Angular中sweetalert弹框的使用详解

    最近太忙了,项目中使用的弹框老板嫌太丑,让我们优化一下,我在网上找了一下,找到了sweetalert弹框,算是比较好看的弹框了.所以我就想办法将sweetalert用到项目中,在项目中引入sweeta ...

  7. vue项目使用eslint

    转载自 https://www.cnblogs.com/hahazexia/p/6393212.html eslint配置方式有两种: 注释配置:使用js注释来直接嵌入ESLint配置信息到一个文件里 ...

  8. https和http/2

    http://geek.csdn.net/news/detail/188003 HTTPS协议原理分析 HTTPS协议需要解决的问题 HTTPS作为安全协议而诞生,那么就不得不面对以下两大安全问题: ...

  9. hbase 过滤器属性及其兼容性

    内容来自于<HBASE权威指南>,留存备查,由于版本的原因,可能已经有变化,在应用前兼容性需要测试.

  10. win10远程连接

    提示凭证不工作问题 https://blog.csdn.net/sinat_25926481/article/details/50775616