2024 河南萌新联赛 6
装备二选一(一)
直接比较结果即可
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls now<<1
#define rs now<<1|1
const int N = 1e5+7, mod = 1e9+7;
void solve(){
int a, b, c, d;
cin >> a >> b >> c >> d;
int t1 = 100 * b * a + 100 * (100 - a);
int t2 = 100 * d * c + 100 * (100 - c);
cout << (t2 > t1 ? "YES\n" : "NO\n");
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
while(t--) solve();
return 0;
}
|
追寻光的方向
开一个 $suf$ 数组,用于记录 $i$ 位置后最大的数的位置,再用 $cnt$ 统计一共需要多少次转移即可
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (now<<1)
#define rs (now<<1|1)
const int N = 1e5+7, mod = 1e9+7;
int n, l[N], suf[N];
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> l[i];
suf[n]=suf[n-1]=n;
suf[n] = n;
for (int i = n-1; i > 0; i--) {
if (l[i+1] > l[suf[i+1]]) suf[i] = i+1;
else suf[i] = suf[i+1];
}
// for(int i=1;i<=n;i++)cout<<suf[i]<<" ";
int cnt = 0, now = 1;
while (now < n) {
now = suf[now];
cnt++;
}
cout << cnt - 1 << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
|
百变吗喽
本身想用 $kmp$ 找最长前缀最长后缀二者两加为 $n$ 时即符合条件,一直只对 $95%$,改不出来,换题解的思路了,标记前缀后缀相同的位置,如果二者能碰到,或超过,就有答案存在,方案数为 $l-r+1$ 个
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,i1,i2;
string s1,s2;
int main(){
cin>>s1>>s2;
n=s2.length();
for(i1=0;i1<n-1 && s1[i1]==s2[i1];i1++);
for(i2=n-1;i2>=0 && s1[i2-1]==s2[i2];i2--);
if(i2<=i1){
cout<<i1-i2+1<<endl;
for(int i=i2;i<=i1;i++)
cout<<i<<" "<<s2[i]<<endl;
}
else cout<<0<<endl;
return 0;
}
|