小沙的步伐(枚举+暴力)

Posted MangataTS

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了小沙的步伐(枚举+暴力)相关的知识,希望对你有一定的参考价值。

题面链接

https://ac.nowcoder.com/acm/contest/23477/K

题面

思路

对于每次击球,我们只需要判断击球的点是否是5.因为题目中给出如果不移动那么就不算经过,其余击球点的经过次数都是每次击球ans+2,因为击球完需要回到5这个位置

代码

#include<bits/stdc++.h>
using namespace std;
//----------------�Զ��岿��----------------
#define ll long long
#define mod 1000000007
#define endl "\\n"
#define PII pair<int,int>

int dx[4]=0,-1,0,1,dy[4]=-1,0,1,0;

ll ksm(ll a,ll b) 
	ll ans = 1;
	for(;b;b>>=1LL) 
		if(b & 1) ans = ans * a % mod;
		a = a * a % mod;
	
	return ans;


ll lowbit(ll x)return -x & x;

const int N = 2e6+10;
//----------------�Զ��岿��----------------
int n,m,q,a[N];

int main()

	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	string s;
	cin>>s;
	int l = s.size();
	for(int i = 0;i < l; ++i) 
		int k = s[i] - '0';
		if(k == 5) continue;
		a[k]++,a[5]++;
	
	for(int i = 1;i <= 9; ++i) 
		cout<<a[i]<<" ";
	
	return 0;


以上是关于小沙的步伐(枚举+暴力)的主要内容,如果未能解决你的问题,请参考以下文章

小沙的算数(前缀和+二分 or 并查集)

牛客2022年愚人节比赛,10题做法完整版

2022牛客寒假算法基础集训营2 签到题7题

牛客2022年愚人节比赛,10题做法完整版

暴力枚举进程模块

蓝桥系列212道「暴力枚举」真题,夯实你的刷题基本功(暴力枚举模板)