Codeforces Round #790 (Div. 4)

A. Lucky?

题意:给一个字符串,看前三位之和是否和后三位相等。
代码

// Problem: A. Lucky?
// Contest: Codeforces - Codeforces Round #790 (Div. 4)
// URL: https://codeforces.com/contest/1676/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms

#include
using namespace std;
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
const int mod=1000000007;
ll qmi(int a, int b, int p){
    ll res = 1 % p; while (b){
    if (b & 1) res = res * a % p; a = a * (ll)a % p; b >>= 1;} return res;}
ll gcd(ll a,ll b) {
    return b?gcd(b,a%b):a;}
int main(){
   
	int t;
	cin>>t;
	while(t--)
	{
   
		string s;
		cin>>s;
		int a = 0 , b = 0;
		for(int i = 0 ; i < 3 ; i ++ )	a += s[i] - '0';
		for(int i = 3 ; i < 6 ; i ++ )	b += s[i] - '0';
		if(a == b)	cout<<"YES\n";
		else cout<<"NO\n";
	}
	return 0;
}

B. Equal Candies

题意:有n个糖果,每个糖果重量不同,要使大家分得糖果重量相同,每人分一个,你可以减少每个糖果任意重量,问最少减少多少。
思路:直接所有糖果都减少至最小值。

// Problem: B. Equal Candies
// Contest: Codeforces - Codeforces Round #790 (Div. 4)
// URL: https://codeforces.com/contest/1676/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms

#include
using namespace std;
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
const int mod=1000000007;
ll qmi(int a, int b, int p){
    ll res = 1 % p; while (b){
    if (b & 1) res = res * a % p; a = a * (ll)a % p; b >>= 1;} return res;}
ll gcd(ll a,ll b) {
    return b?gcd(b,a%b):a;}
int a[55];
int main(){
   
	int t;
	cin>>t;
	while(t--)
	{
   
		int n;
		cin>>n;
		for(int i = 0 ; i < n ; i ++ )	cin>>a[i];
		sort(a,a+n);
		ll ans = 0;
		for(int i = 1 ; i < n ; i ++ )	ans += (a[i]-a[0]);
		cout<<ans<<"\n";
	}
	return 0;
}

C. Most Similar Words

题意:每组给n个字符串,任意选两个,使其中一个转化为另一个,求最小转化步数,每个字母可以转化为相邻的字母,花费1.
在这里插入图片描述
思路:排序后选最小和次小,最大和次大,两者中取最小值。

// Problem: C. Most Similar Words
// Contest: Codeforces - Codeforces Round #790 (Div. 4)
// URL: https://codeforces.com/contest/1676/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms

#include
using namespace std;
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
const int mod=1000000007 , N = 55;
ll qmi

你可能感兴趣的:(比赛题解,算法,c++,数据结构)