ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

AtCoder Beginner Contest 258

2022-08-16 21:01:59  阅读:159  来源: 互联网

标签:AtCoder ch const Beginner int long ++ 258 getchar


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,ch,const,Beginner,int,long,++,258,getchar
来源: https://www.cnblogs.com/PHarr/p/16592925.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有