需要考场源数据请联系偷偷📡:LifeGoesOn_Rio
打赏偷偷🧧:[置顶]⬆️修考使用必看🔥
Hint🧿:读写操作|最大连续子数组和 | 模拟 | 机器学习
最后一问理论上在考场上是很难做出来的 ---- 偷偷🎲
#include<bits/stdc++.h>
using namespace std;
void solve1(){
ifstream fin("infections.txt");
// ofstream fout("ans1.txt");
string s;
vector<int> nums;
while(getline(fin, s, ':')) nums.push_back(stoi(s));
// for(auto x : nums) cout << x << " ";
sort(nums.begin(), nums.end());
auto last = unique(nums.begin(), nums.end());
nums.erase(last, nums.end());
cout << nums[nums.size() - 10] << endl;
}
// 01~47
void my_read(const string& path, vector<int>& nums){
ifstream fin(path);
string s;
while(getline(fin, s, ':')) nums.push_back(stoi(s));
sort(nums.begin(), nums.end());
auto last = unique(nums.begin(), nums.end());
nums.erase(last, nums.end());
}
void solve2(){
int sum = 0;
vector<int> nums;
for(int i = 1; i <= 47; i++){
string s = "data";
if(i <= 9) s = s + "0" + to_string(i);
else s = s + to_string(i);
s += ".txt";
my_read(s, nums);
int n = nums[nums.size() - 10];
cout << n << " ";
sum += n;
nums.clear();
}
cout << endl;
cout << sum << endl;
}
void solve3(){
ifstream fin("infections.txt");
string s;
vector<int> nums;
while(getline(fin, s, ':')) nums.push_back(stoi(s));
vector<int> diff;
diff.push_back(nums[0]);
for(int i = 1; i < nums.size(); i++) diff.push_back(nums[i] - nums[i - 1]);
// for(auto x : diff) cout << x << " ";
string line = "";
for(auto x : diff){
if(x >= 0) line += "+";
line += to_string(x);
}
cout << line << endl;
cout << line.size() << endl;
}
void solve4(){
ifstream fin("infections.txt");
string s;
vector<int> nums;
while(getline(fin, s, ':')) nums.push_back(stoi(s));
vector<int> diff;
diff.push_back(nums[0]);
for(int i = 1; i < nums.size(); i++) diff.push_back(nums[i] - nums[i - 1]);
// for(auto x : diff) cout << x << " ";
int start = 0, end = 0;
int length = 1;
int curSum = diff[0];
int maxSum = diff[0];
vector<pair<int, int>> period;
for(int i = 1; i < diff.size(); i++){
if(curSum + diff[i] <= diff[i]){
curSum = diff[i];
start = i;
}
else{
curSum += diff[i];
if(curSum > maxSum){
maxSum = curSum;
end = i;
length = end - start + 1;
period.clear();
period.push_back({start, end});
}
else if(curSum == maxSum){
int curLength = i - start + 1;
if(curLength == length){
period.push_back({start, i});
}
else if(curLength < length){
period.clear();
period.push_back({start, i});
}
}
}
}
for(auto x : period) cout << x.first + 1 << " " << x.second + 1<< endl;
cout << maxSum << endl;
}
void work1(){
ifstream fin("infections.txt");
string s;
vector<int> nums;
while(getline(fin, s, ':')){
nums.push_back(stoi(s));
}
// for(auto x : nums) cout << x << " ";
int n = (int)nums.size();
int ave_min = INT_MAX;
int ave_max = INT_MIN;
int ave_sum = 0;
for(int i = 3; i < n-3; i++){
int ave = 0;
for(int k = -3; k <= 3; k++){
ave += nums[i + k];
}
ave_min = min(ave_min, ave);
ave_max = max(ave_max, ave);
ave_sum += ave;
}
printf("%.4lf %.4lf %.4lf", ave_min * 1.0 / 7, ave_max * 1.0 / 7, ave_sum * 1.0 / 7);
}
void load(const string& path, vector<int>& nums){
ifstream fin(path);
string s;
while(getline(fin, s, ':')) nums.push_back(stoi(s));
}
long long query(vector<int>& x, vector<int>& y){
if(x.size() < y.size()) swap(x, y); // 保证x数组大小大于y
int m = (int)x.size(), n = (int)y.size();
long long res = 1e18;
for(int i = 0; i <= m - n; i++){
long long now = 0;
for(int k = 0; k <= n - 1; k++){
long long d = x[k + i] - y[k];
now += d * d;
}
res = min(res, now);
}
return -res;
}
void work2(){
vector<vector<int>> all_nums;
for(int i = 1; i <= 47; i++){
string s = "data";
if(i <= 9) s = s + "0" + to_string(i);
else s = s + to_string(i);
s += ".txt";
vector<int> nums;
load(s, nums);
all_nums.push_back(nums);
nums.clear();
}
// for(auto x : all_nums[0]) cout << x << " ";
// cout << all_nums.size() << endl;
long long mx = LONG_MIN;
vector<pair<int, int>> ans;
for(int i = 0; i < 47; i++){
for(int j = i + 1; j < 47; j++){
long long ret = query(all_nums[i], all_nums[j]);
if(ret > mx){
mx = ret;
ans.clear();
ans.push_back({i, j});
}
else if(ret == mx) ans.push_back({i, j});
}
}
for(auto p : ans) cout << p.first + 1 << " " << p.second + 1 << endl;
}
void work3(){
vector<int> nums;
load("infections2.txt", nums);
// for(auto x : nums) cout << x << " ";
long long sum_i = 0, sum_i2 = 0, sum_ix = 0, sum_x = 0;
int n = (int)nums.size();
for(int i = 0; i <= n-1; i++){
sum_i += i;
sum_i2 += i * i;
sum_ix += i * nums[i];
sum_x += nums[i];
}
double a = 1.0 * (n * sum_ix - sum_i * sum_x) / (n * sum_i2 - sum_i * sum_i);
double k = 1.0 * (sum_i2 * sum_x - sum_ix * sum_i) / (n * sum_i2 - sum_i * sum_i);
printf("%.4lf %.4lf", a, k);
cout << endl;
}
int main(){
// solve1();
// solve2();
// solve3();
// solve4();
// work1();
// work2();
// work3();
return 0;
}