当时比赛没打,现在补个题
链接:https://ac.nowcoder.com/acm/contest/551#question
A题:签到题
B题:签到题 凑齐长度,标记一下判断就可以
#include <bits/stdc++.h>
#include <time.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
int xx[4] = {1,-1,0,0};
int yy[4] = {0,0,1,-1};
const double eps = 1e-9;
typedef pair<int,int> P;
const int maxn = 2e6 + 5000;
const ll mod = 1e9 + 7;
inline int sign(db a) { return a < -eps ? -1 : a > eps;}
inline int cmp(db a,db b){ return sign(a - b);}
ll mul(ll a,ll b,ll c) { ll res = 1; while(b) { if(b & 1) res *= a,res %= c; a *= a,a %= c,b >>= 1; } return res;}
ll phi(ll x) { ll res = x; for(ll i = 2; i * i <= x; i++) { if(x % i == 0) res = res / i * (i - 1); while(x % i == 0) x /= i; } if(x > 1) res = res / x * (x - 1); return res;}
int fa[maxn];
int Find(int x) { if(x != fa[x]) return fa[x] = Find(fa[x]); return fa[x];}
ll c,n,k;
map<char,int>m;
int main() {
ios::sync_with_stdio(false);
while(cin >> n){
for(int i = 1; i <= 26;i++){
char op;
cin >> op;m[op] = i;
}
m['0'] = 0;
string str1, str2 ;
for(int j = 1;j <= n;j++){
cin >> str1 >> str2;
int len1 = str1.size(),len2 = str2.size();
if(len1 < len2){
while(len1 < len2) str1 += "0",len1++;}
if(len1 > len2){ while(len2 < len1) str2 += "0",len2++;}
for(int i = 0;i < len1;i++){
if(m[str1[i]] < m[str2[i]]){
cout << "<" << endl;
goto kk;
}else if(m[str1[i]] > m[str2[i]]){
cout << ">" << endl;
goto kk;
}
}
cout << "=" << endl;
kk:;
}
}
cerr << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
D题:CSL 的字符串
开始我写的贪心,wa了太多次了,可以发现,如果i位置的字符大于i+1位置,i不一定要删掉的,当时考虑了很多贪心的情况,只有这个过不去,后来模拟了一下,发现可以有个单调性,那就可以单调栈搞一下
首先把所有字符最后出现的位置记录一下,接着遍历一下,用个stack,如果在外面的元素不在栈内,并且该元素小于栈顶元素,而且栈顶元素的最后一个要大于该位置,就一直出栈
#include <bits/stdc++.h>
#include <time.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
int xx[4] = {1,-1,0,0};
int yy[4] = {0,0,1,-1};
const double eps = 1e-9;
typedef pair<char,int> P;
const int maxn = 2e6 + 5000;
const ll mod = 1e9 + 7;
inline int sign(db a) { return a < -eps ? -1 : a > eps;}
inline int cmp(db a,db b){ return sign(a - b);}
ll mul(ll a,ll b,ll c) { ll res = 1; while(b) { if(b & 1) res *= a,res %= c; a *= a,a %= c,b >>= 1; } return res;}
ll phi(ll x) { ll res = x; for(ll i = 2; i * i <= x; i++) { if(x % i == 0) res = res / i * (i - 1); while(x % i == 0) x /= i; } if(x > 1) res = res / x * (x - 1); return res;}
int fa[maxn];
int Find(int x) { if(x != fa[x]) return fa[x] = Find(fa[x]); return fa[x];}
ll c,n,k;
stack<P>s;
map<char,int>m;
map<char,int>vis;
int main() {
ios::sync_with_stdio(false);string str;
while(cin >> str){
for(int i = 0;i < str.size();i++) vis[str[i]] = i;
vector<char>ans;
for(int i = 0;i < str.size();i++){
if(m[str[i]]) continue;
while(!s.empty() && s.top().fi > str[i] && vis[s.top().fi] > i) m[s.top().fi] = 0 ,s.pop();
s.push(P(str[i],i));
m[str[i]] = 1;
}
while(!s.empty()){
ans.push_back(s.top().fi);
s.pop();
} reverse(ans.begin(),ans.end());
for(auto d:ans) cout << d;
cout << endl;
}
cerr << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
E:CSL 的魔法
#include <bits/stdc++.h>
#include <time.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
int xx[4] = {1,-1,0,0};
int yy[4] = {0,0,1,-1};
const double eps = 1e-9;
typedef pair<char,int> P;
const int maxn = 2e6 + 5000;
const ll mod = 1e9 + 7;
inline int sign(db a) { return a < -eps ? -1 : a > eps;}
inline int cmp(db a,db b){ return sign(a - b);}
ll mul(ll a,ll b,ll c) { ll res = 1; while(b) { if(b & 1) res *= a,res %= c; a *= a,a %= c,b >>= 1; } return res;}
ll phi(ll x) { ll res = x; for(ll i = 2; i * i <= x; i++) { if(x % i == 0) res = res / i * (i - 1); while(x % i == 0) x /= i; } if(x > 1) res = res / x * (x - 1); return res;}
int fa[maxn];
int Find(int x) { if(x != fa[x]) return fa[x] = Find(fa[x]); return fa[x];}
ll n,k,w,q;
ll a[maxn],b[maxn],c[maxn];
map<int,int>m1;
map<int,int>m2;
int main() {
ios::sync_with_stdio(false);
while(cin >> n){
for(int i = 1;i <= n;i++) cin >> a[i],c[i] = a[i];
for(int i = 1;i <= n;i++) cin >> b[i],m1[b[i]] = i;
sort(a + 1,a + 1 + n);
sort(b + 1,b + 1 + n);
for(int i = 1;i <= n;i++){
m2[a[i]] = m1[b[n - i + 1]];
}
ll ans=0;
for(int i = 1; i <= n;i++){
while(m2[c[i]] != i) swap(c[i],c[m2[c[i]]]),ans++;
}
cout <<ans << endl;
}
cerr << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
F题:CSL 的神奇序列
这个题意开始理解错了,他实际上就只是一个序列,而且只要w确定,那序列的值也确定了
开始找规律写一下,稍微计算一下
w = 1
a0 = 1,a1 = 1/2 v = 1
a0 = 1,a1 = 1/2,a2 = 3/8 v = 3
a0 = 1,a1 = 1/2,a2 = 3/8,a3 = 5/32 v = 15
a0 = 1,a1 = 1/2,a2 = 3/8,a3 = 5/32,a4 = 35/128 v = 105
然后求v = an * 2 ^ n * (n!)
1,3,15,105 可以看到1 * 3 , 3 * 5,15 * 7
倍数差是 3 5 7
所以可以得到一个公式
#include <bits/stdc++.h>
#include <time.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
int xx[4] = {1,-1,0,0};
int yy[4] = {0,0,1,-1};
const double eps = 1e-9;
typedef pair<char,int> P;
const int maxn = 2e6 + 5000;
const ll mod = 1e9 + 7;
inline int sign(db a) { return a < -eps ? -1 : a > eps;}
inline int cmp(db a,db b){ return sign(a - b);}
ll mul(ll a,ll b,ll c) { ll res = 1; while(b) { if(b & 1) res *= a,res %= c; a *= a,a %= c,b >>= 1; } return res;}
ll phi(ll x) { ll res = x; for(ll i = 2; i * i <= x; i++) { if(x % i == 0) res = res / i * (i - 1); while(x % i == 0) x /= i; } if(x > 1) res = res / x * (x - 1); return res;}
int fa[maxn];
int Find(int x) { if(x != fa[x]) return fa[x] = Find(fa[x]); return fa[x];}
ll c,n,k,w,q;
ll ans[maxn];
int main() {
ios::sync_with_stdio(false);
while(cin >> w >> q){
int cnt = 1;
ans[1] = w;
for(int i = 2;i <= 1e6 + 20;i++){
cnt++;
ans[i] = (cnt * 2 - 1) % 998244353 * ans[i - 1] % 998244353;
}
while(q--){
cin >> n;
cout << ans[n] << endl;
}
}
cerr << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}