牛客网【瓜分5000元奖金】Wannafly挑战赛13 ABCD

比赛链接

A-zzy的小号

题意有点歪,就是说给你一个字符串,其中 i l的大小写可以视为相同的,o的大小写和0(数字零)可以视为相同的。其他的字母的大小写视为相同

问这个字符串能被看成多少种组合。

显然如果是 il类的话结果*4,o0类结果*3,剩下的*2就行了

 #include<iostream>  
#include<string>  
#include<cstring>  
#include<vector>  
#include<map>  
#include<algorithm>  
#include<queue>  
#include<set>  
#include<cstdio>  
#include<functional>  
#include<iomanip>  
#include<cmath>  
#include<stack>  
using namespace std;
const int maxn = 3*(int)(1e5) + 1000;
const int inf = 0x3f3f3f3f;
const int mods = int(1e9) + 7;
const double eps = 1e-3;
typedef long long LL;
typedef unsigned long long ull;
char str[maxn];
int main(){
	scanf("%s", &str);
	int len = strlen(str);
	LL cnt = 1;
	for (int i = 0; i < len; i++) {
		if (str[i] == 'i' || str[i] == 'I' || str[i] == 'l' || str[i] == 'L') {
			cnt = cnt * 4;
		}
		else if (str[i] == 'o' || str[i] == 'O' || str[i] == '0') {
			cnt = cnt * 3;
		}
		else if ((str[i] >= 'a'&&str[i] <= 'z') || (str[i] >= 'A'&&str[i] <= 'Z')) {
			cnt = cnt * 2;
		}
		cnt %= mods;
	}
	printf("%lld\n", cnt);
	return 0;
}


B-jxc军训

显然是一个排列组合的概率问题。

结果为

化简得(n^2-m)/(n^2)

因为结果对998244353取模,所以要用到逆元(这才是这题的难点吧,,,)

这里笔者给出的是由费马小定理来求的逆元,读者可以参照代码理解或者百度。

 #include<iostream>  
#include<string>  
#include<cstring>  
#include<vector>  
#include<map>  
#include<algorithm>  
#include<queue>  
#include<set>  
#include<cstdio>  
#include<functional>  
#include<iomanip>  
#include<cmath>  
#include<stack>  
using namespace std;
const int maxn = 3*(int)(1e5) + 1000;
const int inf = 0x3f3f3f3f;
const int mods = 998244353;
const double eps = 1e-3;
typedef long long LL;
typedef unsigned long long ull;
LL pow_mod(LL a, LL b, LL p) {//a的b次方求余p 
	LL ret = 1;
	while (b) {
		if (b & 1) ret = (ret * a) % p;
		a = (a * a) % p;
		b >>= 1;
	}
	return ret;
}
LL Fermat(LL a, LL p) {//费马求a关于p的逆元 
	return pow_mod(a, p - 2, p);
}
int main(){
	LL n, m;
	scanf("%lld%lld", &n, &m);
	LL ni = Fermat(n*n, mods);
	LL ans = (n*n-m)%mods;
	ans = ans*ni%mods;
	printf("%lld\n", ans);
	return 0;
}

C-zzf的好矩阵

这里其实是一个脑洞推公式题。

首先由题意可知最后得出来的矩阵(假设为n*n),

那么矩阵内的元素一定是从1~n^2且不重复

例如如果是3*3的矩阵,那么其中一种可能就是

1 2 3

4 5 6

7 8 9

知道这个后我们可以找规律(笔者不会推)

考虑3*3的矩阵

1 2 3

 4 5 6

7 8 9

可以发现只要保持绑定关系,对应的列(或者行)排列就能形成新的组合。

行(列)的排列为3!,由于为n*n的矩阵可以翻转。

即结果为n!*n!*2

 #include<iostream>  
#include<string>  
#include<cstring>  
#include<vector>  
#include<map>  
#include<algorithm>  
#include<queue>  
#include<set>  
#include<cstdio>  
#include<functional>  
#include<iomanip>  
#include<cmath>  
#include<stack>  
using namespace std;
const int maxn = 3*(int)(1e5) + 1000;
const int inf = 0x3f3f3f3f;
const int mods = 998244353;
const double eps = 1e-3;
typedef long long LL;
typedef unsigned long long ull;
int main(){
	LL n;
	scanf("%lld", &n);
	LL ans = 1;
	for (LL i = 1; i <= n; i++) {
		ans = (ans*i) % mods;
	}
	printf("%lld\n", ((ans*ans) % mods * 2 % mods));
	return 0;
}

D-applese的生日

对于一块蛋糕,它无论别切几刀,其后继的大小都相等。

那么可以保留最小的蛋糕体积,然后把蛋糕和他被切的数目存在一个优先队列里,排序方式为蛋糕被切了k刀后的大小(大到小)。

这样就可以不断的通过增加切最大的蛋糕使得全部蛋糕的体积趋近知道达成目标为止。

 #include<iostream>  
#include<string>  
#include<cstring>  
#include<vector>  
#include<map>  
#include<algorithm>  
#include<queue>  
#include<set>  
#include<cstdio>  
#include<functional>  
#include<iomanip>  
#include<cmath>  
#include<stack>  
using namespace std;
const int maxn = 3*(int)(1e5) + 1000;
const int inf = 0x3f3f3f3f;
const int mods = 998244353;
const double eps = 1e-3;
typedef long long LL;
typedef unsigned long long ull;
struct nodes {
	double ca;
	int cnt;
	bool operator <(const nodes &a)const {
		return ca / cnt < a.ca / a.cnt;
	}
}ka[1111];
int main(){
	priority_queue<nodes> que;
	double t, maxs = inf;
	int n;
	scanf("%lf%d", &t, &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf", &ka[i].ca);
		ka[i].cnt = 1;
		que.push(ka[i]);
		maxs = min(maxs, ka[i].ca);
	}
	int cnt = 0;
	while (1) {
		nodes tmp = que.top();
		que.pop();
		if (maxs / (tmp.ca / tmp.cnt) >= t) {
			break;
		}
		cnt++;
		tmp.cnt++;
		que.push(tmp);
		maxs = min(maxs, tmp.ca / tmp.cnt);
	}
	printf("%d\n", cnt);
	return 0;
}
剩下的摸了

猜你喜欢

转载自blog.csdn.net/xiuya19/article/details/79853341