2020-2021年度第二届全国大学生算法设计与编程挑战赛题解(冬季赛)

A—塔

#include <stdio.h>
/***********************************
观察题目样例给出的高为5层的塔,可以得出以下几个规律
对于一个高为n层的塔而言,首先设最上面一层(顶层)为第一层。
1. 对于第i层而言,其字符的排列规律为:大写字母表中从第1个字符(A)~第i个字符,后又倒序从第i-1个字符~第1个字符(A)。
2. 第1~n-1层每层前都有空格,具体而言,对于第i行,字符前面的空格个数为n-i个。
找出以上规律后,我们就可以根据这些规律构造出答案:层高26的塔。

TIPS:
大写字母'A'为大写字母表第一个字符
对于大写字母表中第i个字符,可以使用'A'+i-1得到。
例如:第5个字符为'E',亦即为:'A'+5-1
***********************************/
int main() {
    
    
    char c1;
    int n = 26; //设定塔的层数为26
    int i, j;
    for (i = 1; i <= n; i++) {
    
       //对塔每一层按照规律进行构造。
        //首先进行输出空格的操作:对于第i行,字符前面的空格个数为n-i个。
        for (j = 1; j <=n-i; j++)
            printf(" ");
        for (j = 1; j <= i; j++) {
    
     //按照规律1,输出第1~第i个大写字母。
            c1 = j + 'A' - 1; //第j个大写字母为'A'+j-1
            printf("%c", c1); //输出第j个大写字母
        }
        for (j = i-1; j >= 1; j--) {
    
    //按照规律1,输出第i-1~第1个大写字母,注意是倒序
            c1 = j+'A'-1;
            printf("%c", c1);
        }
        printf("\n");//第i行输出结束,进行换行。
    }
    return 0;
}

B—日记

#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
#include<string>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
ll lst[Max];


int main()
{
    
    
	string str = "ibti lbtlovebte lbtlibtinbtnkbtkebtezbas jebte dosadnbtna ovakbtkebtemibtijaxaszxdbtddbtddbtddbtddbtddbtd";
	string ans = "";
	for (int i = 0;i <= str.size() - 1;i++)
	{
    
    
		ans += str[i];
		if (str[i] == 'l'||str[i]=='i'||str[i]=='n'||str[i]=='k'||str[i]=='k'||str[i]=='e')i+=3;
	}
	cout << ans;
}

E—神仙爱采药

贪心,体积还剩时有多少取多少,当体积不够后再将体积2的扔掉取体积1的,注意答案会爆int。

#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
#include<string>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
ll lst[Max];


int main()
{
    
    
	ll v;cin >> v;
	ll ans = 0, sumv = 0, numz = 0, num2 = 0;
	string str;cin >> str;
	for (ll i = 0;i < str.size();i++)
	{
    
    
		ll p = str[i] - '0';
		if (p + sumv <= v)
		{
    
    
			if (p == 2)num2++;
			numz++;
			sumv += p;
		}
		else
		{
    
    
			if (num2 >= 1 && p == 1)
			{
    
    
				sumv--;
				num2--;
			}
		}
		ans += numz;
	}
	cout << ans;
}

奇怪的小鸭子增加了

#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
#include<string>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
ll lst[Max];


int main()
{
    
    
	ll x, y, a, b;cin >> x >> y >> a >> b;
	ll ans = 0;
	ll h = x / (a + a), s = y / (b + b);
	if (x % (a + a) >= a)h++;
	if (y % (b + b) >= b)s++;
	cout << h * s;
	return 0;
}

I—奇怪的传输机也增加了

YE5和N0注意!

#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<memory.h>
#include<cmath>
#include<iomanip>
#define pii pair<int,int>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
int lst[Max];

int main()
{
    
    
	int n, x, y;cin >> n >> x >> y;
	double sum = n, yu = n;
	int s = 0;
	for (int i = 1;i <= y;i++)
	{
    
    
		s++;
		sum = sum * 2 / 3;
		if (s >= x)
		{
    
    
			sum += yu / 2;
			s = -199999;
		}
		if (sum < n / 32)
		{
    
    
			cout << "N0!" << endl;
			cout << i << " " << fixed << setprecision(6) << sum;
			return 0;
		}
	}
	cout << "YE5!" << endl;
	cout << fixed << setprecision(6) << sum;
	return 0;
}

K—关于哥俩好的数字这件事

数据不大直接暴力把1—1e8的数字求个位数和,比较取最小。

#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<memory.h>
#include<cmath>
#include<vector>
#define pii pair<int,int>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
ll mi = 1e9;
int n[50005];
vector<int> vec[500006];
map<int, int> ma;

int divid(int n)
{
    
    
	int res = 0;
	while (n != 0)
	{
    
    
		res += n % 10;
		n /= 10;
	}
	return res;
}

int main()
{
    
    
	int n;cin >> n;
	for (int i = 1;i <= 10000000;i++)
	{
    
    
		int p = divid(i);
		if (p >= 500005)continue;
		vec[p].push_back(i);
		if (vec[p].size() == n)
		{
    
    
			ll ans = 0;
			for (int j = 0;j < vec[p].size();j++)
			{
    
    
				ans += vec[p][j];
			}
			mi = min(mi, ans);
		}
	}
	cout << mi;
	return 0;
}

字符串:待补…

猜你喜欢

转载自blog.csdn.net/asbbv/article/details/114790509