【LGR-172-Div.4】洛谷入门赛 #19

闲得无聊打打比赛,大多数都是枚举和小贪心,很好想,只附上代码。

A-分饼干 I

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair < ll , ll > PII ;
const int maxn = 1e6 + 7 ;
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 t , n , m , xx , yy , x2 , y2 , a[maxn] , b[maxn] , c[maxn] ;
char s[maxn] , S[maxn] , ss[maxn] ;
ll f[maxn][3] ;
int main(){
	a[1] = read() ;
	a[2] = read() ;
	a[3] = read() ;
	sort(a + 1 , a + 4 , greater <>()) ;
	ll Ans = INT_MAX ;
	ll sum = a[1] + a[2] + a[3] ;
	ll l , r ;
	for(int i = 1 ; i <= 3 ; i ++){
		for(int j = 1 ; j + i - 1 <= 3 ; j ++){
			ll res = 0 , ans = 0 ;
			for(int k = j ; k <= j + i - 1 ; k ++){
				res += a[k] ;
			}
			ans = sum - res ;
			if(res > ans){
				if(res - ans < Ans){
					Ans = res - ans ;
					l = res ;
					r = ans ;
				}
			}
		}
	}
	cout << l << " " << r << endl ;
	return 0 ;
}

B-分饼干 II

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair < ll , ll > PII ;
const int maxn = 1e6 + 7 ;
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 t , n , m , k , yy , x2 , y2 , a[maxn] , b[maxn] , c[maxn] ;
char s[maxn] , S[maxn] , ss[maxn] ;
ll f[maxn][3] ;
void solve(){
	n = read() ;
	k = read() ;
	if(n >= (((1ll + k) * k) / 2ll)){
		cout << "Yes\n" ;
	}
	else{
		cout << "No\n" ;
	}
}
int main(){
	t = read() ;
	while(t --){
		solve() ;
	}
	return 0 ;
}

C-跳房子

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair < ll , ll > PII ;
const int maxn = 1e6 + 7 ;
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 t , n , m , k , yy , x2 , y2 , a[maxn] , b[maxn] , c[maxn] ;
char s[maxn] , S[maxn] , ss[maxn] ;
ll f[maxn][3] ;
int main(){
	n = read() ;
	for(int i = 1 ; i <= n ; i ++){
		a[i] = read() ;
	}
	ll cnt = 0 , rt = 1 ;
	while(1){
		if(rt >= n){
			break ;
		}
		cnt ++ ;
		rt = rt + a[rt] ;
	}
	if(rt == n){
		cout << "Yes\n" ;
		cout << cnt << endl ;
	}
	else{
		cout << "No\n" ;
		cout << cnt << endl ;
	}
	return 0 ;
}

D-区间函数最小值

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair < ll , ll > PII ;
const int maxn = 1e6 + 7 ;
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 A , B , C , D , E , F , G , P , l1 , r1 , l2 , r2 ;
ll t , n , m , k , yy , x2 , y2 , a[maxn] , b[maxn] , c[maxn] ;
char s[maxn] , S[maxn] , ss[maxn] ;
ll f[maxn][3] ;
int main(){
	A = read() ;
	B = read() ;
	C = read() ;
	D = read() ;
	E = read() ;
	F = read() ;
	G = read() ;
	P = read() ;
	l1 = read() ;
	r1 = read() ;
	l2 = read() ;
	r2 = read() ;
	ll ans = -INT_MAX ;
	for(ll i = l1 ; i <= r1 ; i ++){
		for(ll j = l2 ; j <= r2 ; j ++){
			ll res = ((((((A * i) % P * i) % P) * i) % P) + (((((B * j) % P )* j) % P) * j) % P ) ;
			res %= P ;
			res = ((res + ((((((C * i) % P) * i) % P) * j ) % P)) % P + ((((((D * i) % P) * j) % P) * j) % P)) ;
			res %= P ;
			res = (res + ((((E * i) % P) * j) % P)) % P + ((F * i) % P );
			res %= P ; 
			res = (res + ((G * j) % P)) % P ;
			ans = max(ans , res) ;	
		}
	}
	cout << ans <<endl ;
	return 0 ;
}

E-小跳蛙

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair < ll , ll > PII ;
const int maxn = 1e6 + 7 ;
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 A , B , C , D , E , F , G , P , l1 , r1 , l2 , r2 ;
ll t , n , m , k , yy , x2 , y2 , a[maxn] , b[maxn] , c[maxn] ;
char s[maxn] , S[maxn] , ss[maxn] ;
ll f[maxn][3] ;
int main(){
	n = read() ;
	for(int i = 1 ; i <= n ; i ++){
		a[i] = read() ;
	}
	map < ll , ll > mp ;
	for(int i = 1 ; i <= n ; i ++){
		mp[a[i]] = i ;
	}
	for(int i = 1 ; i <= n - 1 ; i ++){
		b[mp[i - 1]] = i ;
	}
	b[mp[n - 1]] = 0 ;
	for(int i = 1 ; i <= n ; i ++){
		cout << b[i] << " " ; 
	}
	cout << endl ;
	return 0 ;
}

F-图像变换

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair < ll , ll > PII ;
const int maxn = 1e6 + 7 ;
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 A , B , C , D , E , F , G , P , l1 , r1 , l2 , r2 ;
ll t , n , m , k , yy , x2 , y2 , a[maxn] , b[maxn] , c[maxn] ;
char s[200][1050] , S[200][1050] ;
ll f[maxn][3] ;
int main(){
	n = read() ;
	m = read() ;
	k = read() ;
	for(int i = 1 ; i <= n ; i ++){
		for(int j = 1 ; j <= m ; j ++){
			cin >> s[i][j] ;
		}
	}
	for(int i = 1 ; i <= n ; i ++){
		int cnt = 0 ;
		for(int j = 1 ; j <= m ; j ++){
			for(int w = 1 ; w <= k ; w ++){
				S[i][++ cnt] = s[i][j] ;
			}
		}
	}
	for(int i = 1 ; i <= n ; i ++){
		for(int j = 1 ; j <= k ; j ++){
			for(int w = 1 ; w <= m * k ; w ++){
				cout << S[i][w] ;
			}
			cout << endl ;
		}
	}
	cout << endl ;
	return 0 ;
}

G-二进制与一

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair < ll , ll > PII ;
const int maxn = 1e6 + 7 ;
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 A , B , C , D , E , F , G , P , l1 , r1 , l2 , r2 ;
ll t , n , m , k , yy , x2 , y2 , a[maxn] , b[maxn] , sum[maxn] ;
char s[200][1050] , S[200][1050] ;
ll f[maxn][3] ;
int main(){
	n = read() ;
	m = read() ;
	for(int i = 0 ; i <= 35 ; i ++){
		ll res = (n >> i) & 1 ;
		if(res == 1){
			a[i] = 1 ;
		}
		else{
			a[i] = 0 ;
		}
	}
	ll ans = 0 ;
	for(int i = 1 ; i <= m ; i ++){
		ll rt ;
		rt = read() ;
		rt -- ;
		if(a[rt] == 1){
			continue ;
		}
		ll Rt = -1 ;
		for(int j = 0 ; j <= rt ; j ++){
			if(a[j] == 1){
				Rt = j ;
				break ;
			}
		}
		if(Rt == -1){
			ans += (1 << rt) ;
			a[rt] = 1 ;
		}
		else{
			for(int j = Rt ; j < rt ; j ++){
				if(a[j] == 0){
					ans += (1 << j) ;
				}
			}
			ans += (1 << Rt) ;
			for(int j = Rt ; j < rt ; j ++){
				a[j] = 0 ;
			}
			a[rt] = 1 ;
		}
//		cout << ans << endl ;
	}
	cout << ans << endl ;
	return 0 ;
}

H-Genshin 玩家

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair < ll , ll > PII ;
const int maxn = 1e6 + 7 ;
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 t , n , m , k , yy , x2 , y2 , a[maxn] , b[maxn] , sum[maxn] ;
string s ;
vector < PII > q , p ;
int main(){
	cin >> s ;
	int len = s.length() ;
	for(int i = 0 ; i < len ; i ++){
		if(i + 6 < len){
			string S = "" ;
			for(int j = i ; j <= i + 6 ; j ++){
				S = S + s[j] ;
			}
			if(S == "Genshin"){
				q.push_back({i + 1 , i + 7}) ;
			}
		}
		if(i + 5 < len){
			string S = "" ;
			for(int j = i ; j <= i + 5 ; j ++){
				S = S + s[j] ;
			}
			if(S == "player"){
				p.push_back({i + 1 , i + 6}) ;
			}
		}
	}
	ll ans = 0 ;
	for(int i = 0 ; i < (int)q.size() ; i ++){
		for(int j = 0 ; j < (int)p.size() ; j ++){
			if(p[j].first >= q[i].second){
				ans ++ ;
			}
		}
	}
	cout << ans << endl ;
	return 0 ;
}

喜欢作者的记得点个关注!

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小小许愿瓶

我的成长我做主

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值