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

AtCoder Beginner Contest 336

时间:2024-01-14 22:22:07浏览次数:29  
标签:AtCoder Beginner int 336 long while solve dp define

AtCoder Beginner Contest 336

A - Long Loong

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



void solve()
{	
	int x;
	cin >> x;
	cout <<"L";
	while(x--) cout<<"o";
	cout<<"ng";
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T = 1;
	//cin >> T;
	while(T--) solve();
    return 0;
}

B - CTZ

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

void solve()
{	
	int x;
	cin >> x;
	int ans = 0;
	while(x){
		if(x&1) break;
		else{
			ans++;
			x >>= 1;
		}
	}
	cout << ans <<endl;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T = 1;
	//cin >> T;
	while(T--) solve();
    return 0;
}

C - Even Digits

应该算是求贡献吧

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

const int N = 1e12;
int X[5]={0,2,4,6,8};

void solve()
{	
	vector<int> dp;
	dp.push_back(1);
	dp.push_back(5);
	while(dp.back()<=1e12) dp.push_back(dp.back()*5);
	int n;
	cin >> n;
	n--;
	int x = 0;
	vector<int> path;
	for(int i=dp.size()-1;i>0;i--)
	{
		int z=0;
		while(x+dp[i-1]<=n&&z<4)
		{
			x += dp[i-1];
			z++;
		}
		path.push_back(z);
	}
	reverse(path.begin(),path.end());
	int z=1;
	int ans = 0;
	for(auto u:path){
		ans += X[u]*z;
		z *= 10;
	}
	cout << ans <<endl;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T = 1;
	//cin >> T;
	while(T--) solve();
    return 0;
}

D - Pyramid

经典快结束了顿悟

每一位数能表示的最大值与他相邻两位数有关。

例如 1 3 1,因为左右都是1所以中间那一位能表示的最大值只能是2。

显然a[1]和a[n]的最大值只能是1。

以最大值为1的点为起点跑广搜。

结束后数组中的最大值就是答案。

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

const int N = 2e5 + 10;
int a[N];
bool visl[N],visr[N];

void solve()
{	
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		cin >> a[i];
	}
	a[1]=a[n]=1;
	queue<pair<int,int>> path;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==1){
			path.push({i,i});
			visl[i] =visr[i] = true;
		}
	}
	while(path.size()){
		int fa=path.front().first;
		int u =path.front().second;
		path.pop();
		if(u+1<=n&&fa!=u+1&&!visl[u+1]){
			a[u+1] = min(a[u+1],a[u]+1);
			//cout << u+1 <<" "<<a[u+1]<<endl;
			path.push({u,u+1});
			visl[u+1]=true;
		}
		if(u-1>0&&fa!=u-1&&!visr[u-1]){
			a[u-1] = min(a[u-1],a[u]+1);
			//cout << u-1 <<" "<<a[u-1]<<endl;
			path.push({u,u-1});
			visr[u-1]=true;
		}
	}
	cout << *max_element(a+1,a+1+n)<<endl;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T = 1;
	//cin >> T;
	while(T--) solve();
    return 0;
}

标签:AtCoder,Beginner,int,336,long,while,solve,dp,define
From: https://www.cnblogs.com/zfxyyy/p/17964302

相关文章

  • AtCoder World Tour 2022 B The Greatest Two
    原题面:https://atcoder.jp/contests/wtf22-day2/tasks/wtf22_day2_b题面翻译:一个长度为\(n\)的排列\(p\),每次可以把一个长\(k\)区间的最大与次大值交换,问操作任意次数后可以得到的排列数量对\(998244353\)取模。这题被我搬到了一场多校联考中。在搬到的题面中,我加入了......
  • AtCoder Beginner Contest 335 G Discrete Logarithm Problems
    洛谷传送门AtCoder传送门考虑若我们对于每个\(a_i\)求出来了使得\(g^{b_i}\equiva_i\pmodP\)的\(b_i\)(其中\(g\)为\(P\)的原根),那么\(a_i^k\equiva_j\pmodP\)等价于\(kb_i\equivb_j\pmod{P-1}\),有解的充要条件是\(\gcd(b_i,P-1)\midb_j\)。显然......
  • AtCoder Beginner Contest 335 (Sponsored by Mynavi)
    AtCoderBeginnerContest335(SponsoredbyMynavi)A-2023代码:#include<bits/stdc++.h>usingnamespacestd;usingll=longlong;usingpii=pair<ll,ll>;#definefifirst#definesesecondvoidsolve(){strings;cin>>s;......
  • AtCoder Beginner Contest 335 总结
    ABC335总结A.202<s>3</s>翻译给你一个由小写英文字母和数字组成的字符串\(S\)。\(S\)保证以2023结尾。将\(S\)的最后一个字符改为4,并打印修改后的字符串。分析两种做法:直接把最后一个字符改为4,然后输出。输出前\(n\)个字符后输出4。code#include<bits/stdc......
  • AtCoder Beginner Contest 295
    B-Bombsd难度:⭐题目大意给定一个n*m的网格,其中'.'表示空白,'#'表示障碍物,数字x表示此处有一个炸弹,会将附近曼哈顿距离小于等于x的格子都变成空白;问所有炸弹爆炸后的网格;解题思路数据范围很小,暴力即可;神秘代码#include<bits/stdc++.h>#definei......
  • AtCoder Regular Contest 167 C MST on Line++
    洛谷传送门AtCoder传送门我是傻逼。很平凡的一个计数。但是不会啊。怎么会是呢。考虑Kruskal求解MSTonLine问题。我们可以想到统计边权\(=a_i\)的出现次数。然后又可以容斥转化成统计边权\(\lea_i\)的出现次数,设其为\(f_i\)。考虑求\(f_i\)。就相当于把\(p\)......
  • AtCoder Beginner Contest 334
    B-ChristmasTrees难度:⭐⭐题目大意小莫从坐标轴的某个位置n种了一棵树,并且每隔m米就再种一棵树,注意是双向的,两边都种;给定一个区间,问这个区间中有多少棵树;解题思路我们可以让区间的边界都减去n,这样区间中的树都位于坐标km上;然后我们把边界都平移到正......
  • AtCoder Beginner Contest 复盘合集
    AtCoderBeginnerContest复盘合集修改链接2023.12.6ABC312VP(OI赛制)这次的ABC相对比较难:红橙黄黄蓝绿绿,Ex(蓝)AlinkB稍微麻烦一点。linkC很水,直接Sort一遍即可。linkD稍微思考,可以得出一个DP,准确来说不太像DPlink【警钟长鸣】我非常的弱智,\(n<=3000\)赛时写......
  • AtCoder Regular Contest 168 F Up-Down Queries
    洛谷传送门AtCoder传送门貌似是第三道问号题?感觉前面这个转化不是人能想到的。。。考虑维护\(y\)的差分序列。更进一步地,我们类比slopetrick,维护一个可重集,里面有\(y_{i+1}-y_i\)个\(i\)(为了方便我们让每次操作时\(y_{m+1}\)加\(1\))。那么一次操作就相当于,插......
  • atcoder
    DPABC275EABC274DABC274EABC271EABC270DABC266D状态机模型ABC265Emap存状态+步骤型遍历(注意DP顺序)+复杂度证明ABC262D关于数字的DP,将一类数字分成一个状态加粗样式ABC261D没啥好说的看题目写DPABC253E关于数字的DPABC251E状态机DPABC197E在一维轴上行走的DP......