Educational Codeforces Round 74 (Rated for Div. 2)
A. Prime Subtraction
-
思路:任何大于等于二的数都可以由二和三构成
-
AC代码
#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 t;
ll x, y, tmp;
int main(){
#ifndef ONLINE_JUDGE
freopen("my_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t -- ){
cin >> x >> y;
tmp = x - y;
if (tmp == 1)
cout << "NO
";
else
cout << "YES
";
}
return 0;
}
B. Kill 'Em All
-
思路:贪心 排序后 从最大的开始搞
-
AC代码
#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 = 1e5 + 10;
int q, n, r, ans;
int x[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 -- ){
ans = 0;
cin >> n >> r;
for (int i = 1; i <= n; i ++ )
cin >> x[i];
sort(x + 1, x + n + 1);
for (int i = n; i >= 1; i -- ){
if (x[i] - ans * r > 0){
ans ++ ;
while (i - 1 >= 1 && x[i - 1] == x[i])
i -- ;
}
}
cout << ans << "
";
}
return 0;
}
C. Standard Free2play
-
思路:每次找某一段连续且长度为偶数时答案+1 注意最后一段特判
-
AC代码
#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, h, n, ans, cnt;
int p[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 -- ){
ans = 0, cnt = 1;
cin >> h >> n;
for (int i = 1; i <= n; i ++ )
cin >> p[i];
for (int i = 2; i <= n; i ++ ){
if (p[i - 1] - 1 == p[i])
cnt ++ ;
else{
if (cnt % 2 == 0)
ans ++ ;
cnt = 0;
}
}
if (cnt % 2 == 0 && p[n] > 1)
ans ++ ;
cout << ans << "
";
}
return 0;
}
D. AB-string
-
思路:参考官方题解 做的时候很难想到 用总的减去不符合题意的即可
-
AC代码
#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;
ll n, tot, ans;
ll a[N];
string s;
int main(){
#ifndef ONLINE_JUDGE
freopen("my_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> s;
for (int i = 0; i < n; i ++ ){
if (s[i] != s[i - 1])
a[ ++ tot ] = 1;
else
a[tot] ++ ;
}
ans = n * (n - 1) / 2 - 2 * n + a[1] + a[tot] + tot - 1;
cout << ans << "
";
return 0;
}