1046 Plane Spotting
来源:互联网 发布:喜剧之王 知乎 编辑:程序博客网 时间:2024/05/05 14:45
1046 Plane Spotting
sicily
algorithm
title
题目链接:
给出一个长度为N的非负整数序列(所有数不超过200),还有两个整数M和K,求前M个最优的长度不小于K的连续子序列。连续子序列的优先级如何比较平均值大的序列优于平均值小的长度大的序列优于长度小的结束位置靠前的序列优于结束位置靠后的
code
#include <iostream>#include <vector>#include <string>#include <math.h>#include <algorithm>using namespace std;struct nodes{ /* data */ float averNum; int len; int lastIdx;};// note double or float has no ==const float inf = 1e-9;const int N = 305;float myAbs(const float a, const float b) { float diff = a - b; if(diff < 0) { diff = 0 - diff; } return diff;}int myMin(const int a, const int b) { return a < b ? a : b;}bool cmp(const nodes& a, const nodes& b) { if(a.averNum - b.averNum > inf) { return true; } else if(myAbs(a.averNum, b.averNum) < inf) { if(a.len > b.len) { return true; } else if(a.len == b.len) { if(a.lastIdx < b.lastIdx) { return true; } } } return false;}int main() { int T; cin >> T; for(int t = 0; t < T; t++) { int n, m, k; cin >> n >> m >> k; int nums[N]; for(int i = 0; i < n; i++) { cin >> nums[i]; } // std::vector<nodes> planes; for(int i = 0; i < n; i++) { int sum = 0; for(int j = i; j < n; j++) { sum += nums[j]; int len = j - i + 1; // min size if(len >= k) { float averNum = sum / (len + 0.); nodes pn; pn.len = len; pn.averNum = averNum; pn.lastIdx = j + 1; planes.push_back(pn); } } } int size = planes.size(); sort(planes.begin(), planes.end(), cmp); size = myMin(size, m); for(int i = 0; i < size; i++) { if(i == 0) { std::cout << "Result for run " << t + 1 << ":" << std::endl; } std::cout << planes[i].lastIdx - planes[i].len + 1 << "-" << planes[i].lastIdx << std::endl; } } return 0;}
0 0
- sicily 1046 Plane Spotting
- sicily 1046 Plane Spotting
- Sicily 1046, Plane Spotting
- 1046 Plane Spotting
- sicily 1046 Plane Spotting
- Plane Spotting
- sicily--1046. Plane Spotting
- 1046. Plane Spotting
- Sicily 1046. Plane Spotting
- 1046. Plane Spotting排序
- sicily 1046. Plane Spotting
- 1046. Plane Spotting
- 1046. Plane Spotting
- 1046. Plane Spotting
- sicily 1046.Plane Spotting
- [sicily]1046. Plane Spotting
- 1046. Plane Spotting
- Sicily 1046. Plane Spotting
- Eclipse格式化代码时不换行与自动换行
- Hadoop分布式缓存
- django 注册、登录及第三方接口程序(4):扩展邮箱注册,登录,微博登录
- 微信公众号开发系列-开发模式创建自定义菜单
- CentOS6.x中vmware workstation 虚拟机启动报错:Could not open /dev/vmmon
- 1046 Plane Spotting
- ColdFusion8目录遍历漏洞
- java加密解密简单实现(学习一下)
- Django站点管理标准库,用grappelli美化Django Admin后台管理界面
- leetcode Word Break
- iOS开发 - Block块的使用(一)基础概念
- 【MongoDB】windows平台搭建Mongo数据库复制集(类似集群)(二)
- schema学习笔记
- KVC和KVO