更好的阅读体验:http://www.abmcar.top/archives/codeforcesround764div3
完整代码:https://github.com/abmcar/ACM/tree/master/OpenjudgeNow/Codeforces/Codeforces%20Round%20%23764%20(Div.%203)
A. Plus One on the Subset
题目大意:给你一个数组,你可以一次选择其中任意一个或多个数+1,问最小操作多少次使得数组各个元素相等
思路:记录最大值和最小值,答案为二者之差
代码:
void work()
{
cin >> n;
int maxn = 0;
int minn = 2e9;
for (int i = 0; i < n; i++)
{
int temp;
cin >> temp;
maxn = max(maxn,temp);
minn = min(minn,temp);
}
cout << maxn-minn << endl;
}
B. Make AP
题目大意:给你abc三个数,你可以选择一个数 * m (m>0),问是否能构成等差数列
思路:分别把a/b/c当中m的那个数,用另外两个数求公差,判断是否能从ak得到,再判断一下不用乘的情况即可
代码:
void work()
{
ll a, b, c;
cin >> a >> b >> c;
if (c-b == b-a)
{
cout << "YES" << endl;
return;
}
int nowDC = b - a;
int targetC = b + nowDC;
if (((targetC - c) % c == 0) && (targetC - c) / c > 0)
{
// cout << "1" << endl;
cout << "YES" << endl;
return;
}
int nowDB = (c - a) / 2;
if ((c - a) % 2 == 0)
{
int targetB = a + nowDB;
if (((targetB - b) % b == 0) && (targetB - b) / b > 0)
{
// cout << "2" << endl;
cout << "YES" << endl;
return;
}
}
int nowDA = c - b;
int targetA = b - nowDA;
if (((targetA - a) % a == 0) && (targetA - a) / a > 0)
{
// cout << "3" << endl;
cout << "YES" << endl;
return;
}
cout << "NO" << endl;
}
C. Division by Two and Permutation
题目大意:给你一个数组,你可以选择其中任意元素使其除2,可以选择多次,问是否能把数组变成一个排列
思路:和 https://codeforces.com/contest/1617/problem/C 很相似,直接排序贪心判断即可
同类型题解:https://blog.csdn.net/qq_23323539/article/details/122408648?spm=1001.2014.3001.5501
代码:
void work()
{
cin >> n;
map<int, bool> M;
vector<int> unuse, targetNum;
for (int i = 1; i <= n; i++)
{
int temp;
cin >> temp;
if (!M[temp] && temp <= n)
M[temp] = true;
else
unuse.push_back(temp);
}
sort(unuse.begin(), unuse.end());
for (int i = 0; i < unuse.size(); i++)
{
int nowNum = unuse[i] / 2;
// cout << nowNum << " !!!";
bool ok = false;
while (nowNum)
{
if (M[nowNum] == false && nowNum <= n)
{
M[nowNum] = true;
ok = true;
// cout << " find- " << nowNum << endl;
break;
}
nowNum = nowNum / 2;
}
if (!ok)
{
cout << "NO" << endl;
return;
}
}
cout << "YES" << endl;
}
D. Palindromes Coloring
题目大意:给你一个字符串s和一个颜色数k,你需要对字符串中的字母染色,至少每个颜色要有一个字母,且染色后同颜色字母顺序可以任意换,之后把同颜色的字母放在一起,组成k个字符串,问这k个字符串当中最小的长度的最大值是多少?
思路:统计所有字母的数量,已知如果任意两个同字母可以放到任意字符串中,统计可以任意放的个数和单独剩下的个数,
用可以任意放的双字母数/k,可以得到成双字母组成的字符串的长度,之后判断没用上的双字母个数和单字母个数是否大于k,是则所有字符串可以多一位,此时答案=双字母字符串长度+1
代码:
void work()
{
map<int, int> oriN, aftN;
cin >> n >> m;
string oriS;
cin >> oriS;
for (char it : oriS)
oriN[it]++;
for (char i = 'a'; i <= 'z'; i++)
aftN[i] = oriN[i] / 2;
int tot1, tot2;
tot1 = tot2 = 0;
for (char i = 'a'; i <= 'z'; i++)
tot1 += oriN[i] % 2;
for (char i = 'a'; i <= 'z'; i++)
tot2 += aftN[i];
int ans = tot2 / m * 2;
if (tot1 + tot2 % m * 2 >= m)
ans++;
// if (tot1 && (tot2 % m * 2 >= m))
// ans++;
cout << ans << endl;
}