本文主要是介绍Codeforces Round 952 (Div. 4) A - G题解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
A. Creating Words
直接输出即可。
代码:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {ll x = 0, f = 1 ;char c = getchar() ;while (c > '9' || c < '0') {if (c == '-')f = -1 ;c = getchar() ;}while (c >= '0' && c <= '9') {x = x * 10 + c - '0' ;c = getchar() ;}return x * f ;
}ll b[maxn] , a[maxn] , n , m , t ;
char s[maxn] , S[maxn] ;
void solve(){scanf("%s" , s + 1) ;scanf("%s" , S + 1) ;cout << S[1] << s[2] << s[3] << " " ;cout << s[1] << S[2] << S[3] << endl ;
}
int main(){t = read() ;while(t --){solve() ;}return 0 ;
}
B. Maximum Multiple Sum
题意:给你一个n,问的值,满足的累加和最大的x是多少。
题解:直接枚举即可。
代码:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {ll x = 0, f = 1 ;char c = getchar() ;while (c > '9' || c < '0') {if (c == '-')f = -1 ;c = getchar() ;}while (c >= '0' && c <= '9') {x = x * 10 + c - '0' ;c = getchar() ;}return x * f ;
}ll b[maxn] , a[maxn] , n , m , t ;
char s[maxn] , S[maxn] ;
void solve(){n = read() ;ll Ans = 0 , rt = 2 ;for(int i = 2 ; i <= n ; i ++){ll ans = 0 ;for(int j = i ; j <= n ; j += i){ans += j ;}if(ans >= Ans){Ans = ans ;rt = i ;}}cout << rt << endl ;
}
int main(){t = read() ;while(t --){solve() ;}return 0 ;
}
C. Good Prefixes
题意:给你n个数字,问他的前缀能否满足最大的数字等于其他所有数字之和,统计可以满足的数量。
题解:枚举即可,每次用最大的数字和其他数字之和比较,统计答案即可。复杂度O(n)。
代码:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {ll x = 0, f = 1 ;char c = getchar() ;while (c > '9' || c < '0') {if (c == '-')f = -1 ;c = getchar() ;}while (c >= '0' && c <= '9') {x = x * 10 + c - '0' ;c = getchar() ;}return x * f ;
}ll b[maxn] , a[maxn] , n , m , t ;
char s[maxn] , S[maxn] ;
void solve(){n = read() ;for(int i = 1 ; i <= n ; i ++){a[i] = read() ;}ll sum = 0 , Max = a[1] , ans = 0 ;for(int i = 2 ; i <= n ; i ++){if(a[i] > Max){sum += Max ;Max = a[i] ;}else{sum += a[i] ;}if(sum == Max){ans ++ ;}}if(a[1] == 0){ans ++ ;}cout << ans << endl ;
}
int main(){t = read() ;while(t --){solve() ;}return 0 ;
}
D. Manhattan Circle
题意:给你一个n*m的字符阵,问曼哈顿园的圆心在哪里。
题解:每次碰到#就更新边缘距离,最后直接输出即可。
代码:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {ll x = 0, f = 1 ;char c = getchar() ;while (c > '9' || c < '0') {if (c == '-')f = -1 ;c = getchar() ;}while (c >= '0' && c <= '9') {x = x * 10 + c - '0' ;c = getchar() ;}return x * f ;
}ll b[maxn] , a[maxn] , n , m , t ;
char s[maxn] , S[maxn] ;
void solve(){n = read() ;m = read() ;ll l = m , r = 1 , L = n , R = 1 ;for(ll i = 1 ; i <= n ; i ++){for(ll j = 1 ; j <= m ; j ++){char c ;cin >> c ;if(c == '#'){l = min(l , j) ;r = max(r , j) ;L = min(L , i) ;R = max(R , i) ;}}}// cout << l << " " << r << endl ;cout << (L + R) / 2 << " " << (l + r) / 2 << endl ;
}
int main(){t = read() ;while(t --){solve() ;}return 0 ;
}
E. Secret Box
题意:给你一个盒子,长宽高分别为x,y,z,给你一个体积K ,能否找到n,m,k,体积等于K,问在盒子中有多少种放法。
题解:因为数据范围是1~2000,枚举n和m,再算出k,看能否整除,最后求出的最大值即可。
代码:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {ll x = 0, f = 1 ;char c = getchar() ;while (c > '9' || c < '0') {if (c == '-')f = -1 ;c = getchar() ;}while (c >= '0' && c <= '9') {x = x * 10 + c - '0' ;c = getchar() ;}return x * f ;
}ll b[maxn] , a[maxn] , n , m , k , ans , t ;
char s[maxn] , S[maxn] ;
void solve(){n = read() ;m = read() ;k = read() ;ans = read() ;ll Ans = 0 ;for(ll i = 1 ; i <= n ; i ++){for(ll j = 1 ; j <= m ; j ++){ll sum = i * j ;if(ans % sum == 0){ll z = ans / sum ;Ans = max(Ans , (n - i + 1) * (m - j + 1) * (k - z + 1)) ;}}}cout << Ans << endl ;
}
int main(){t = read() ;while(t --){solve() ;}return 0 ;
}
F. Final Boss
题意:给你一个n为大BOSS的血量值,再给你n组数字,每个数字有一个攻击值和冷却时间,每次攻击可以使用多个没有冷却的数字,问最少多少轮可以击败BOSS。
题解:一眼二分,直接枚举二分的边界,代表轮数,可以推断出,如果第n轮可以完成,那么n+1轮也一定完成,符合单调性,直接用二分,check询问能否打败BOSS即可,复杂度。
代码:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {ll x = 0, f = 1 ;char c = getchar() ;while (c > '9' || c < '0') {if (c == '-')f = -1 ;c = getchar() ;}while (c >= '0' && c <= '9') {x = x * 10 + c - '0' ;c = getchar() ;}return x * f ;
}ll b[maxn] , a[maxn] , n , m , t ;
char s[maxn] , S[maxn] ;
bool check(ll mid){ll ans = 0 ;for(int i = 1 ; i <= m ; i ++){ans += a[i] ;}mid -- ;for(int i = 1 ; i <= m ; i ++){ans += (mid / b[i]) * a[i] ;}if(ans >= n){return 1 ;}return 0 ;
}
void solve(){n = read() ;m = read() ;for(int i = 1 ; i <= m ; i ++){a[i] = read() ;}for(int i = 1 ; i <= m ; i ++){b[i] = read() ;}ll l = 1 , r = 4e10 , ans = -1 ;while(l <= r){ll mid = (l + r) / 2 ;if(check(mid)){ans = mid ;r = mid - 1 ;}else{l = mid + 1 ;}}cout << ans << endl ;
}
int main(){t = read() ;while(t --){solve() ;}return 0 ;
}
G. D-Function
先附代码,明天起来写题解。
代码:
#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {ll x = 0, f = 1 ;char c = getchar() ;while (c > '9' || c < '0') {if (c == '-')f = -1 ;c = getchar() ;}while (c >= '0' && c <= '9') {x = x * 10 + c - '0' ;c = getchar() ;}return x * f ;
}
ll l , r , k , t ;
void solve() {l = read() ;k = read() ;t = read() ;auto ksm = [&] (ll a, ll x) {ll s = 1;while (x) {if (x & 1) s = s * a % mod;a = a * a % mod;x >>= 1;}return s;};auto f = [&](int x) -> ll {if (k > 10) return 0; return ksm(9 / k + 1, x);};cout << ((f(r) - f(l)) % mod + mod) % mod << endl ;
}int main() {t = read() ;while (t --){solve();}return 0;
}
喜欢作者的记得留下你们的关注,你们的鼓励就是“我”最大的动力!
这篇关于Codeforces Round 952 (Div. 4) A - G题解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!