銀聯 第二場 (本弟弟只會做水題

A碼隊GO(找最大正方形)
代碼:

#include<bits/stdc++.h>
using namespace std;

int main(){
	int T,n,m;
	cin >> T;
	while(T--){
		cin >> n >> m;
		char tmp;
		int mat[n+2][m+2] = { 0 };
		int res[n+2][m+2] = { 0 };
		int maxn = 0;

		for(int i  = 0;i < n;i++){
			for(int j = 0;j < m;j++){
				cin >> tmp;
				mat[i][j] = (tmp == '.');
				if(!i || !j){
					res[i][j] = mat[i][j];
					maxn = max(maxn,res[i][j]);
				}
			}
		}

		for(int i = 1;i < n;i++){
			for(int j = 1;j < m;j++){
				res[i][j] = (mat[i][j] == 0) ? 0 : min(min(res[i-1][j-1],res[i-1][j]),res[i][j-1]) + 1;
				maxn = max(maxn,res[i][j]);
			}
		}

		cout << maxn * maxn << endl;
	}
}

B.碼隊弟弟求和問題
代碼:

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;
ll n,m,inv6;

ll qmod(ll base,ll n){
	ll res = 1;
	while(n){
		if(n & 1){
			res = res * base % mod;
		}
		base = base * base % mod;
		n >>= 1;
	}
	return res;
}

ll f1(ll x){
	return ((x + 1) * x / 2) % mod;
}
ll f2(ll x){
	return x * (x + 1) % mod * (2*x + 1) % mod * inv6 % mod;
}

ll g(ll l,ll r){
	return(f2(r) - f2(l - 1) + mod) % mod;
}

ll Re(ll m){
	ll res = m * f1(m) % mod;
	for(ll l = 1,r = 0;l <= m;l = r + 1){
		r = m/(m/l);
		res -= 1ll * g(l,r) * (m/l) % mod;
		res = (res + mod) % mod;
	}
	return res;
}
int main(){
	inv6 = qmod(6,mod - 2);
	while(cin >> n >> m){
		printf("%lld\n",Re(n)*Re(m) % mod);
	}
}

C.異世界幻想 (樹

暫留

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章