D1 D2
問題の意味
あなたは、文字列sとtを与えるサブシーケンスs tはまだ最長の部分文字列の長さを削除しようとしているように、文字列は、最長の部分文字列を削除する要求されています
問題の解決策
LとR Tと各配列要素は、最初と最後の登場の位置を記録します。最大に初期化MAXN(R [0]、| | S - L [| T | -1] - 1) - L [I MAXN = MAX(R [i]を有する配列の両端で表される部分文字列を、削除されます-1] - 1、MAXN)サブストリング中間欠失配列を表しますああ、おそらくいわば
#include <cstdio>
#include <cstring>
int main() {
char s[200010], t[200010];
int l[200010], r[200010];
scanf("%s %s", s, t);
int n = strlen(s), m = strlen(t);
for(int i = 0, j = 0; i < n && j < m; i++) {
if(s[i] == t[j]) {
l[j] = i;
j++;
}
}
for(int i = n - 1, j = m - 1; j >= 0 && i >= 0; i--) {
if(s[i] == t[j]) {
r[j] = i;
j--;
}
}
int maxn;
if(n - l[m-1] - 1 > r[0]) maxn = n - l[m-1] - 1;
else maxn = r[0];
for(int i = 1; i < m; i++) {
if(r[i] - l[i-1] - 1> maxn) maxn = r[i] - l[i-1] - 1;
}
printf("%d\n", maxn);
return 0;
}
E
問題の意味
あなたは順序を与え、シーケンス番号は1など、-1または+1彼の番号に変更することができますが、0より大きくなければなりませんのみ、2、1、2または3を回すことができる必要異なる順序になりますどのように多くの最大数?
問題の解決策
- [i]がある場合は、[I] -1を持っていない場合は、最初の時間(CNTは、[[I]] == 0)、そして、その後に置く[i]の[i]はなり1は、[i]は-1、それは変わらず、その後、登場しています。
[i]は初めてではない場合、(CNT [I]]> 0)、[I] [I] + +1なる置きます
CNT [I] [i]が数である表し
#include <cstdio>
#include <algorithm>
using std::sort;
int cnt[150010], a[150010];
int main() {
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
for(int i = 0; i < n; i++) {
if(cnt[a[i]]) cnt[a[i]+1]++;
else if(cnt[a[i] - 1] == 0 && a[i] > 1) cnt[a[i] - 1]++;
else cnt[a[i]]++;
}
int ans = 0;
for(int i = 1; i < 150002; i++) {
if(cnt[i]) ans++;
}
printf("%d\n", ans);
return 0;
}