AtCoder Beginner Contest 052

A - Two Rectangles

比大小

#include<bits/stdc++.h>

using namespace std;

int32_t main(){
	int a , b , c , d ;
	cin >> a >> b >> c >> d;
	cout << max( a * b , c * d );
	return 0;
}

B - Increment Decrement

模拟

#include<bits/stdc++.h>

using namespace std;

int32_t main(){
	int n , x = 0 , res = 0;
	string s;
	cin >> n >> s;
	for( auto i : s ){
		if( i == 'I' ) x ++ , res = max( x , res );
		else x --;
	}
	cout << res;
	return 0;
}

C - Factors of Factorial

首先把阶乘中所有的数都质因数分解,然后把因子都合并得到\(\sum p_i^{k_i}\),然后用一点点组合数的性质可知所有的正因子数目就是\(\Pi (k_i+1)\)

#include<bits/stdc++.h>

using namespace std;

#define int long long

const int mod = 1e9+7;

int32_t main(){
	int n;
	cin >> n;
	vector<int> p(n+1 , 0);
	for( int i = 1 , x ; i <= n ; i ++ ){
		x = i;
		for( int j = 2 ; j * j <= x ; j ++ ){
			if( x % j ) continue;
			while( x % j == 0 ) x /= j , p[j] ++ ;
		}
		if( x != 1 ) p[x] ++;
	}
	int res = 1;
	for( int i = 1 ; i <= n ; i ++ ){
		if( p[i] == 0 ) continue;
	}
	for( auto i : p )
		res = ( res * i + res ) % mod;
	cout << res;
	return 0;
}

D - Walk and Teleport

看似是 dp,实际上因为跳跃操作不限制距离,所以最优的情况一定是从上一个城镇直接跳过来,所以就是考虑一下跳过来和走过来哪一个更优

#include<bits/stdc++.h>

using namespace std;

#define int long long

int read(){
	int x = 0 , ch = getchar();
	while( ch < '0' || ch > '9' ) ch = getchar();
	while( ch >= '0' && ch <= '9' ) x = ( x << 3 ) + ( x << 1 ) + ch - '0' , ch = getchar();
	return x;
}

int32_t main(){
	int n = read() , a = read() , b = read() , res = 0;
	vector<int> x(n);
	for( auto &i : x ) i = read();
	for( int i = 1 ; i < n ; i ++ )
		res += min( b , (x[i] - x[i-1])* a );
	cout << res;
	return 0;
}
posted @ 2023-03-09 16:58  PHarr  阅读(17)  评论(0编辑  收藏  举报