Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1)
A. CME
Thinking: n = 0 n is an even number to an odd number answers the answer is judged at Laid 1 when n is 2 answers 2
AC Code
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mult_mod(ll x, ll y, ll mod){
return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}
ll pow_mod(ll a, ll b, ll p){
ll res = 1;
while (b){
if (b & 1)
res = mult_mod(res, a, p);
a = mult_mod(a, a, p);
b >>= 1;
}
return res % p;
}
ll gcd(ll a, ll b){
return b ? gcd(b, a % b) : a;
}
int q, n;
int main(){
#ifndef ONLINE_JUDGE
freopen("my_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> q;
while (q -- ){
cin >> n;
if (n == 2)
cout << 2 << "\n";
else if (n & 1)
cout << 1 << "\n";
else
cout << 0 << "\n";
}
return 0;
}
B. Strings Equalization
Idea: As long as there are two children the same character string can make string equivalent to string s t
AC Code
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mult_mod(ll x, ll y, ll mod){
return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}
ll pow_mod(ll a, ll b, ll p){
ll res = 1;
while (b){
if (b & 1)
res = mult_mod(res, a, p);
a = mult_mod(a, a, p);
b >>= 1;
}
return res % p;
}
ll gcd(ll a, ll b){
return b ? gcd(b, a % b) : a;
}
int q;
string s, t;
int main(){
#ifndef ONLINE_JUDGE
freopen("my_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> q;
while (q -- ){
cin >> s >> t;
bool flag = false;
for (int i = 0; i < s.length(); i ++ ){
for (int j = 0; j < t.length(); j ++ ){
if (s[i] == t[j]){
flag = true;
break;
}
}
if (flag)
break;
}
if (flag)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
C. Save the Nature
Idea: After descending order greedy p + half to make trouble on the line (
Recently I came across this question is really too muchAC Code
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mult_mod(ll x, ll y, ll mod){
return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}
ll pow_mod(ll a, ll b, ll p){
ll res = 1;
while (b){
if (b & 1)
res = mult_mod(res, a, p);
a = mult_mod(a, a, p);
b >>= 1;
}
return res % p;
}
ll gcd(ll a, ll b){
return b ? gcd(b, a % b) : a;
}
const int N = 2e5 + 10;
int q, n;
bool flag;
ll tmp, x, a, y, b, k, l, r, mid;
ll p[N];
inline bool cmp(const ll &a, const ll &b){
return a > b;
}
inline bool check(ll mid){
ll ans = 0;
int pos = 1;
for (int i = 1; i <= mid; i ++ )
if (i % a == 0 && i % b == 0)
ans += 0.01 * p[pos ++ ] * (x + y);
for (int i = 1; i <= mid; i ++ )
if (i % a == 0 && i % b != 0)
ans += 0.01 * p[pos ++ ] * x;
for (int i = 1; i <= mid; i ++ )
if (i % a != 0 && i % b == 0)
ans += 0.01 * p[pos ++ ] * y;
return ans >= k;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("my_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> q;
while (q -- ){
flag = false;
cin >> n;
l = 1, r = n;
for (int i = 1; i <= n; i ++ )
cin >> p[i];
sort(p + 1, p + n + 1, cmp);
cin >> x >> a >> y >> b >> k;
if (x < y){
swap(x, y);
swap(a, b);
}
while (l <= r){
mid = (l + r) >> 1;
if (check(mid)){
r = mid - 1;
flag = true;
}
else
l = mid + 1;
}
if (flag)
cout << l << "\n";
else
cout << "-1\n";
}
return 0;
}
D. Sequence Sorting
Ideas: Record the left point and the right point and then look for different values of disjoint longest continuous value
AC Code
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mult_mod(ll x, ll y, ll mod){
return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}
ll pow_mod(ll a, ll b, ll p){
ll res = 1;
while (b){
if (b & 1)
res = mult_mod(res, a, p);
a = mult_mod(a, a, p);
b >>= 1;
}
return res % p;
}
ll gcd(ll a, ll b){
return b ? gcd(b, a % b) : a;
}
const int N = 3e5 + 10;
int q, n, a, R, res, ans;
int l[N], r[N];
set<int> st;
int main(){
#ifndef ONLINE_JUDGE
freopen("my_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> q;
while (q -- ){
R = -1, res = 0, ans = 0;
st.clear();
cin >> n;
for (int i = 1; i <= n; i ++ ){
l[i] = n;
r[i] = 1;
}
for (int i = 1; i <= n; i ++ ){
cin >> a;
l[a] = min(l[a], i);
r[a] = max(r[a], i);
st.insert(a);
}
for (auto a: st){
if (l[a] > R)
res ++ ;
else
res = 1;
R = r[a];
ans = max(ans, res);
}
cout << st.size() - ans << "\n";
}
return 0;
}