Nothing to fear
种一棵树最好的时间是十年前,其次是现在!
那些你早出晚归付出的刻苦努力,你不想训练,当你觉的太累了但还是要咬牙坚持的时候,那就是在追逐梦想,不要在意终点有什么,要享受路途的过程,或许你不能成就梦想,但一定会有更伟大的事情随之而来。 mamba out~
2020.8.6
人一我十,人十我百,追逐青春的梦想,怀着自信的心,永不言弃!
613Div3 -C
#include <bits/stdc++.h>
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lowbit(x) (x & -x)
using namespace std;
typedef long long ll;
const int MAX = 0x7ffffff;
int test;
void slove()
{
int n;cin >> n;
vector<int> a(n, 0) , cnt(110 , 0);
for(int i = 0;i < n ;i ++){
cin >> a[i];
cnt[a[i]]++;
}
int ans = 0;
for(int s = 2; s <= 2 * n; s++)
{
int cur = 0;
for(int i = 1;i < (s + 1) / 2 ;i ++)
{
if(s - i > n)continue;
cur += min(cnt[i] , cnt[s - i]);
}
if(s % 2 == 0)cur += cnt[s / 2] / 2;
ans = max(ans , cur);
}
cout << ans << endl;
}
int main()
{
#ifdef LOCAL
auto start_time = clock();
cerr << setprecision(3) << fixed; // 在iomanip中
#endif
SIS;
cin >> test;
while(test--)
{
slove();
}
#ifdef LOCAL
auto end_time = clock();
cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms
";
#endif
}
613Div3-D
维护两个优先队列记录以 0 为结尾得最小索引 pos0 , 和 记录以 1 为结尾得最小索引 pos1.每次进行查询即可。
#include <bits/stdc++.h>
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lowbit(x) (x & -x)
using namespace std;
typedef long long ll;
const int MAX = 0x7ffffff;
int test;
void slove()
{
int n;
string s;
cin >> n >> s;
vector<int> ans(n);
int cnt = 0;
priority_queue<int,vector<int>,greater<int> > pos1 , pos0;
for(int i = 0;i < n ;i ++)
{
int k = s[i] - '0';
if(k == 0)
{
if(pos1.size() == 0){
pos0.push(i);
ans[i] = ++cnt;
} else {
int top = pos1.top();
pos1.pop();
ans[i] = ans[top];
pos0.push(i);
}
} else {
if(pos0.size() == 0){
pos1.push(i);
ans[i] = ++cnt;
} else {
int top = pos0.top();
pos0.pop();
ans[i] = ans[top];
pos1.push(i);
}
}
}
cout << cnt << endl;
for(int i = 0;i < n;i ++){
cout << ans[i] << " ";
}
cout << endl;
}
int main()
{
#ifdef LOCAL
auto start_time = clock();
cerr << setprecision(3) << fixed; // 在iomanip中
#endif
SIS;
cin >> test;
while(test--)
{
slove();
}
#ifdef LOCAL
auto end_time = clock();
cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms
";
#endif
}