emmm,先补这一场,上一场太残暴了,一会再补
这一场四道思维题
A
答案等于各个字符的最小出现次数*k
#include <bits/stdc++.h>
using namespace std;
int a[100100];
int main(){
int ans = 0x3f3f3f3f;
string s;
int n, k;
cin >> n >> k;
cin >> s;
for(int i = 0; i < s. size(); i ++){
a[s[i] - 'A'] ++;
}
for(int i = 0; i < k; i ++){
if(a[i] < ans)
ans = a[i];
}
cout << ans * k << endl;
return 0;
}
B
按奇偶区分就好
#include <bits/stdc++.h>
using namespace std;
vector <int> ans1, ans2;
int main(){
int n;
cin >> n;
if(n == 1 || n == 2)
cout << "No" << endl;
else{
cout << "Yes" << endl;
for(int i = 1; i <= n; i ++)
if(i % 2 == 1)
ans1. push_back(i);
else
ans2. push_back(i);
cout << ans1. size() << ' ';
for(int i = 0; i < ans1. size(); i ++)
cout << ans1[i] << ' ';
cout << endl;
cout << ans2. size() << ' ';
for(int i = 0; i < ans2. size(); i ++)
cout << ans2[i] << ' ';
cout << endl;
}
return 0;
}
C
emmm,yy一个方案,如果自己的最大值大于对方的,则选择加上,反之则选择删掉对方的。没想怎么证明,一看过题人数那么多,就直接交了
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
priority_queue <ll> q1, q2;
int main(){
int n;
cin >> n;
ll x;
ll ans1, ans2;
ans1 = ans2 = 0;
for(int i = 0; i < n; i ++){
cin >> x;
q1. push(x);
}
for(int i = 0; i < n; i ++){
cin >> x;
q2. push(x);
}
while(! q1. empty() && ! q2. empty()){
ll t1 = q1. top(), t2 = q2. top();
if(t1 <= t2){
q2. pop();
}
else{
ans1 += t1;
q1. pop();
}
if(q1. empty()){
ans2 += q2. top();
q2. pop();
}
else if(q2. empty()){
q1. pop();
}
else{
t1 = q1. top(), t2 = q2. top();
if(t1 <= t2){
ans2 += t2;
q2. pop();
}
else{
q1. pop();
}
}
}
while(! q1. empty() && q2. empty()){
ll t = q1. top();
ans1 += t;
q1. pop();
q1. pop();
}
while(q1. empty() && ! q2. empty()){
q2. pop();
ll t = q2. top();
ans2 += t;
q2. pop();
}
// cout << ans1 << ' ' << ans2 << endl;
cout << ans1 - ans2 << endl;
return 0;
}
D
nc了,没想出来,或许是潜意识里认为自己做不出D题??更nc,也有可能是累了,各方面的原因吧。。
当时分析出了一种情况:既有正数又有负数,答案为绝对值之和。符号一致的话答案是绝对值之和减去最小的绝对值*2
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[500500];
int main(){
bool flag1, flag2;
flag1 = flag2 = false;
int n;
cin >> n;
ll x = 100000000000;
ll ans = 0;
if(n == 1){
cin >> ans;
cout << ans << endl;
return 0;
}
for(int i = 0; i < n; i ++){
cin >> a[i];
if(a[i] > 0)
flag1 = true;
if(a[i] < 0)
flag2 = true;
if(a[i] == 0)
flag1 = flag2 = true;
x = min(x, abs(a[i]));
ans += abs(a[i]);
}
if(flag1 && flag2)
cout << ans << endl;
else{
cout << ans - x * 2 << endl;
}
return 0;
}