51nod做题笔记
2652 阶乘0的数量 V2
因子中2的密度远远大于5的密度,故只需关注因子为5的出现即可,即间隔5,阶乘增加一个零。然后二分答案即可。
1094 和为k的连续区间
这题有的做法,求出前缀和后必有,枚举一个,只需要去找即可。map或者二分随便搞。
2462 铺设道路
这题有线性的做法:.
1506 最小字典序
丑死了
### #include<iostream>
#include<stdio.h>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<cstring>
#include<stack>
#include <cmath>
#define mem(ss) memset(ss,0,sizeof(ss))
#define rep(d, s, t) for(int d=s;d<=t;d++)
#define rev(d, s, t) for(int d=s;d>=t;d--)
#define inf 0x3f3f3f3f
typedef long long ll;
typedef long double ld;
typedef double db;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
const ll mod = 1e9 + 7;
const int N = 5e5 + 10;
#define io_opt ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
inline ll read() {
ll x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int n;
string s;
int pre[N], suf[N];
int main() {
io_opt;
cin >> s;
n = s.size();
pre[0] = 0;
for (int i = 1; i < n; i++) {
pre[i] = pre[i - 1];
if (s[i] > s[pre[i - 1]]) {
pre[i] = i;
}
}
suf[n - 1] = n - 1;
for (int i = n - 2; i >= 0; i--) {
suf[i] = suf[i + 1];
if (s[i] < s[suf[i + 1]]) {
suf[i] = i;
}
}
if(n<26) {
string ans = "{";
for (int i = 1; i < n; i++) {
swap(s[pre[i - 1]], s[suf[i]]);
ans = min(ans, s);
swap(s[pre[i - 1]], s[suf[i]]);
}
cout << ans;
}else{
for (int i = 0; i < n; i++)
if (s[i] > s[suf[i]]) {
swap(s[i], s[suf[i]]);
break;
}
cout << s;
}
return 0;
}
浙公网安备 33010602011771号