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