牛客網【瓜分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;
}
剩下的摸了
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章