/*
* Copyright (c) Huawei Technologies Co., Ltd. 2019-2019. All rights reserved.
* Description: 上机编程认证
* Note: 缺省代码仅供参考,可自行决定使用、修改或删除
*/
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
#define ARR_LEN (7 * 24)
int real_length(int &l, int &r)
{
if (l > ARR_LEN - 1) {
return 0;
}
if(r >= ARR_LEN && l <= r % ARR_LEN) {
return 168;
}
return r - l + 1;
}
// 待实现函数,在此函数中填入答题代码
class Solution {
public:
vector<int> GetBestTimeWindow(int n, const vector<int> &arr) const
{
vector<long double> arr2(ARR_LEN * 2, 0);
int size2 = arr2.size();
for (int i = 0; i < size2; ++i) {
arr2[i] = arr[i % ARR_LEN];
}
int l = 0, r = 0;
long double sum = arr2[l];
vector<int> result(2, -1);
int max_len = 0;
int tmp = 0;
while(r < size2 - 1) {
if (sum > n) {
if (l == r) {
l++;
r++;
sum = arr2[l];
} else {
sum -= arr2[l];
l++;
}
} else {
if ((tmp = real_length(l, r)) > max_len) {
result[0] = l;
result[1] = r % ARR_LEN;
max_len = tmp;
}
r++;
sum += arr2[r];
}
}
return result;
}
};
// 以下为考题输入输出框架,此部分代码不建议改动
inline int ReadInt()
{
int number;
std::cin >> number;
return number;
}
template<typename T>
inline std::vector<T> ReadVector(int size)
{
std::vector<T> objects(size);
for (int i = 0; i < size; ++i) {
std::cin >> objects[i];
}
return objects;
}
template<typename T>
inline void WriteVector(const std::vector<T>& objects, char delimeter = ' ')
{
auto it = objects.begin();
if (it == objects.end()) {
return;
}
std::cout << *it;
for (++it; it != objects.end(); ++it) {
std::cout << delimeter << *it;
}
}
int main()
{
//int n = ReadInt();
int n = 1093;
//vector<int> arr = ReadVector<int>(ARR_LEN);
//vector<int> arr {1181752412, 543415221, 531530463, 234578117, 1042880611, 665595500, 40235803, 341476205, 598181603, 654392401, 1144538484, 792938707, 377482833, 526157682, 1189739783, 1273889670, 982432920, 167585328, 1017054374, 977968560, 629801530, 240362933, 838591093, 1187257411, 428734257, 811390594, 256224032, 871526575, 1109752321, 868987433, 746551207, 273537101, 977687504, 938965948, 978573453, 1271456209, 691036223, 175829997, 330905006, 1405265302, 204400075, 936587958, 146547411, 328705521, 619876647, 686184391, 248589455, 744795832, 1099047966, 476250253, 154532931, 586830117, 181672590, 1196888644, 1081730556, 66354216, 1174997414, 1330100010, 98202898, 580075595, 501234663, 539136754, 1248199481, 1426610732, 1255046159, 141130310, 380287612, 84991174, 976707862, 1304706077, 1340390911, 1144481420, 431478337, 455196048, 1138583725, 1030150637, 537132404, 1120922559, 1286704546, 849659359, 166366785, 992451891, 1168426438, 1250864282, 129141751, 258618284, 985019739, 311373230, 1310356326, 728245636, 75867287, 1124812227, 7574921, 9500565, 488126316, 714435397, 793308335, 679708633, 1266562204, 617614488, 389139562, 1330452995, 150303435, 473471356, 322757347, 184203138, 556622471, 1327945471, 569731953, 56693312, 1012697229, 813889471, 1052032931, 980976278, 1294772756, 371037572, 1345941563, 1382772253, 642697146, 784870685, 956877429, 817657735, 91617563, 598976762, 414048262, 1266729947, 68707558, 1108294117, 1206308634, 1382239511, 118150888, 1336455885, 70425099, 506718225, 659788550, 259608592, 1428424306, 1366101736, 112869362, 261171093, 523788894, 364343131, 1177536214, 50948868, 349905789, 666279488, 265420269, 1132149796, 1373960800, 190166465, 919220793, 1295209418, 1393203209, 547631461, 666841627, 1117413576, 1417715730, 887715804, 738341911, 1278829516, 352854592, 1019668586, 1323010899, 268196851, 386117020, 1193488254, 844001586, 1283591035
//};
vector<int> arr {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2,1
};
int sum = 0;
for (auto e : arr) {
sum += e;
}
cout << sum <<endl;
Solution solu;
vector<int> res = solu.GetBestTimeWindow(n, arr);
WriteVector(res);
return 0;
}
点击并拖拽以移动