AtCoder Beginner Contest 258

2022/8/16 23:30:55

本文主要是介绍AtCoder Beginner Contest 258,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

A - When?

21:00后的第k分钟的时间

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

const int N = 2e5+5;
int n , a[N] , cnt , k;

int32_t main(){
	int n , h = 21 , m = 0;
	cin >> n;
	m += n;
	h += m / 60 ; m %= 60;
	printf("%02d:%02d\n" , h , m );
}

B - Number Box

数据范围很小,枚举起点,枚举方向

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

const int N = 12;
const int dx[] = {1 ,-1 ,0 ,0 ,1 ,-1 ,1 ,-1 };
const int dy[] = {0 ,0 ,1 ,-1 , 1 ,1 ,-1 ,-1 };
int n , a[N][N] , ans ;
string s;

int32_t main()
{
    cin >> n;
    for( int i = 0 ; i < n ; i ++ )
    {
        cin >> s;
        for( int j = 0 ; j < n ; j ++ )
            a[i][j] = s[j] - '0';
    }

    for( int i = 0 ; i < n ; i ++ )
    {
        for( int j = 0 ; j < n ; j ++ )
        {
            for( int k = 0 , x = i , y = j , cnt = 0ll ; k < 8 ; k ++ , x = i , y = j , cnt = 0ll ){
                for( int l = 1 ; l <= n ; l ++ )
                    cnt = cnt * 10ll + a[x][y] , x  =  ( x + dx[k] + n ) % n , y = ( y + dy[k] +n) % n;
                ans = max( ans , cnt );
            }
        }
    }
    cout << ans << endl;
}

C - Rotation

给一个长度为 n 的字符串 s 有 q 次操作,操作有两种。1是逐个删除结尾的 x 个字符然后逐渐添加到开头,2 时输出当前的第 x 个字符

这里不用移动开头,而是把创当成是一个换来考虑,每次维护一下开头的位置就好了

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

const int N = 2e5+5;
int n , sta , q;
string s;

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(){
	n = read() , q = read() , sta = 0;
	cin >> s;
	for( int op , x ; q ; q -- )
	{
		op = read() , x = read();
		if( op == 1 ) sta = ( ( sta - x ) % n + n ) % n ;
		else {
			cout << s[( ( sta + x - 1 ) % n + n ) % n ] << "\n";
		}
	}
}

D - Trophy

\(res=\min(\sum_{i=1}^{k}(a_i+b_i)+(x-k)\times b_i)\)

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

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

int32_t main() {
    int n = read() , m = read() , res = LONG_MAX , sum = 0;
    for( int a , b ; n && m ; n -- ){
        a = read() , b = read();
        sum += a + b , m --;
        res = min( res , sum + m * b );
    }
    cout << res << "\n";
    return 0;
}


这篇关于AtCoder Beginner Contest 258的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程