首页 > 其他分享 >AtCoder Beginner Contest 258

AtCoder Beginner Contest 258

时间:2022-08-16 20:56:57浏览次数:75  
标签: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
From: https://www.cnblogs.com/PHarr/p/16592925.html

相关文章

  • Atcoder ABC169
    A  直接输出\(a×b\)即可inta,b;std::cin>>a>>b;std::cout<<a*b<<"\n";B  将所有的\(N\)个数乘起来看是不是大于\(10^{18}\),很明......
  • AtCoder Beginner Contest 264部分题解(a~d)
    A题题目大意:打印“atcoder"中从第l个到第r个字母参考代码:#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong#defineIOSios_base::sync_with_std......
  • Atcoder Grand Contest 025 E - Walking on a Tree(欧拉回路)
    Atcoder题面传送门打个表发现答案等于每条边被覆盖的次数与\(2\)取min之和,考虑如何构造这个上界。首先考虑树是以\(1\)为中心的菊花图,且任意\(A_i,B_i\ne1\)的......
  • 【杂题乱写】AtCoder dp 26题
    AtCoderdp26题原比赛链接洛谷题单链接A-Frog1题目已然给出了转移方程,设\(dp_i\)为到第\(i\)块石头的最小代价。转移方程:\[dp_i=\min(dp_{i-1}+|h_i-h_{i-1}......
  • freee Programming Contest 2022(AtCoder Beginner Contest 264)A-E
    freeeProgrammingContest2022(AtCoderBeginnerContest264)https://atcoder.jp/contests/abc264FG待补A-"atcoder".substr()输出atcoder第L位和第R位上的字符#in......
  • AtCoder Beginner Contest 264
    比赛链接AtCoderBeginnerContest264E.Blackout2给出很多点(\(n+m\leq2\times10^5\)),有发电站和城市,以及很多边(\(e\leq5\times10^5\)),有\(q\)次删边操作,求每次......
  • AtCoder Beginner Contest 264
    E-Blackout2离线+并查集。注意到只有删边操作,而删边操作其实不是很好维护。由于没有强制在线,所以可以离线一下然后逆序考虑,这样删边就变成了加边,这就用并查集就足以维......