A
注意A、B的条件即可
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define mst(a, b) memset(a, b, sizeof a)
#define REP(i, x, n) for(int i = x; i <= n; ++i)
const int qq = 2e5 + 10;
int a[qq], b[qq];
int main(){
int A, B; scanf("%d%d", &A, &B);
LL ans = 1;
for(int i = 1; i <= min(A, B); ++i)
ans *= (LL)i;
printf("%lld\n", ans);
return 0;
}
B
题意:给出两个字符串s、t,问把s中某些字符改变成?使得字符串s是字符串t的某个字串,问改变字符最少的是多少
思路:枚举s串是t串中某个字串,记录最小改变次数即可
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define mst(a, b) memset(a, b, sizeof a)
#define REP(i, x, n) for(int i = x; i <= n; ++i)
const int qq = 2e5 + 10;
int n, m;
char s[1005], t[1005];
map<string, int> mp;
int main(){
scanf("%d%d", &n, &m);
scanf("%s%s", s + 1, t + 1);
int lens = strlen(s + 1), lent = strlen(t + 1);
int l = 0, r = 0, minx = 1e9;
for(int i = lens; i <= lent; ++i){
int cnt = 0;
for(int j = i - lens + 1, k = 1; j <= i; ++j, ++k)
if(s[k] != t[j]){
cnt++;
}
if(cnt < minx){
minx = cnt;
l = i - lens + 1, r = i;
}
}
printf("%d\n", minx);
for(int i = l, k = 1; i <= r; ++i, ++k){
if(s[k] != t[i]){
printf("%d ", k);
}
}
puts("");
return 0;
}
C
题意:n个区间,l、r、c,问选择两个不相交的区间使得c的和最小,并且两个区间长度的和等于x
思路:这类思维题其实碰到过几次,每次就是想不到点上去,可以这样想,每次如果我确定的某个区间的l值,那么我能选择的就是比l小的区间r值,这样一定能保证选到答案
确定的l,然后更新r。
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b) memset(a, b, sizeof a)
#define REP(i, x, n) for(int i = x; i <= n; ++i)
const int qq = 2e5 + 10, INF = 2e9 + 10;
vector<pill> a[qq], b[qq];
int n, x, cost[qq];
int main(){
scanf("%d%d", &n, &x);
for(int i = 0; i < n; ++i){
int l, r, c; scanf("%d%d%d", &l, &r, &c);
a[l].pb({r - l + 1, c});
b[r].pb({r - l + 1, c});
}
fill(&cost[0], &cost[0] + qq, INF);
int ans = INF;
for(int i = 0; i < qq; ++i){
for(auto p : a[i]){
if(p.first >= x) continue;
if(cost[x - p.first] < INF)
ans = min(ans, p.second + cost[x - p.first]);
}
for(auto p : b[i]) cost[p.first] = min(cost[p.first], p.second);
}
if(ans == INF) puts("-1");
else printf("%d\n", ans);
return 0;
}