'commit'
This commit is contained in:
47
TangDou/Mkx/20241125/LianXuQuJianHe.cpp
Normal file
47
TangDou/Mkx/20241125/LianXuQuJianHe.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 10010;
|
||||
typedef long long LL;
|
||||
map<LL, int> s;
|
||||
LL sum;
|
||||
int n, k;
|
||||
/**
|
||||
测试用例
|
||||
6 10
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
|
||||
答案:
|
||||
1 4
|
||||
*/
|
||||
int main() {
|
||||
cin >> n >> k;
|
||||
|
||||
int L = INT_MAX, R; // 左右端点
|
||||
bool found = false; // 是不是找到了
|
||||
int x;
|
||||
|
||||
s[0] = 0;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> x; // 新输入的数据
|
||||
sum += x; // 总和
|
||||
|
||||
auto it = s.find(sum - k); // 查找前缀和为sum-k的元素
|
||||
if (it != s.end()) { // 如果找到了
|
||||
L = it->second, R = i; // 记录答案
|
||||
found = true;
|
||||
} else
|
||||
s[sum] = i; // sum-k 不存在,才会记录sum,换句话说,就是sum是唯一的
|
||||
}
|
||||
|
||||
if (found)
|
||||
cout << L + 1 << " " << R << endl;
|
||||
else
|
||||
cout << "No Solution" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
43
TangDou/Mkx/20241125/YueHan.cpp
Normal file
43
TangDou/Mkx/20241125/YueHan.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
map<string, int> b;
|
||||
/*
|
||||
测试用例:
|
||||
|
||||
5
|
||||
BESSIE ELSIE MATILDA
|
||||
FRAN BESSIE INGRID
|
||||
BESSIE ELSIE MATILDA
|
||||
MATILDA INGRID FRAN
|
||||
ELSIE BESSIE MATILDA
|
||||
|
||||
答案:
|
||||
3
|
||||
*/
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) { // 共n组
|
||||
map<string, int> a; // 声明一个map用来将每组三个字符串进行整理顺序
|
||||
for (int j = 1; j <= 3; j++) { // 每组3个
|
||||
string s;
|
||||
cin >> s;
|
||||
a[s] = 1; // 由于a是一个有序map,所以进入map的自动就是排序的
|
||||
}
|
||||
|
||||
// 把在map中的字符串键值使用迭代器进行逐个输出,拼接成一个新的字符串,这个新的字符串一定是顺序固定的
|
||||
string se = "";
|
||||
for (auto it = a.begin(); it != a.end(); it++)
|
||||
se = se + " " + it->first;
|
||||
// cout << "sorted string =" << se << endl;
|
||||
// 将整理完顺序的字符串做为key放入到map的b中
|
||||
b[se]++;
|
||||
}
|
||||
// 使用迭代器输出b里面的内容看一下
|
||||
int mx = 0;
|
||||
for (auto it = b.begin(); it != b.end(); it++)
|
||||
mx = max(mx, it->second);
|
||||
|
||||
cout << mx << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user