A. I'm bored with life
水题
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w",stdout);
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long LL;
typedef pair<int, int> PII;
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int c = min(a, b);
int ans = 1;
for(int i = 1; i <= c; i++) ans *= i;
cout << ans << endl;
return 0;
}
B. Crossword solving
字符串匹配
英语太差题意花了很久才读懂.....
题意:上面的字符串要把多少个字符变为?才可以变为下面字符串的子串 要变得数量尽可能的小
直接暴力匹配就可以做了
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w",stdout);
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long LL;
typedef pair<int, int> PII;
using namespace std;
const int maxn = 1000 + 5;
char a[maxn];
char b[maxn];
int p[maxn];
int p1[maxn];
int main() {
//FIN
int n, m;
scanf("%d%d", &n, &m);
scanf("%s", a);
scanf("%s", b);
int mx = -1;
int c = 0;
for(int i = 0; i <= m - n; i++) {
int num = 0;
int cnt = 0;
for(int j = 0; j < n; j++) {
if(b[i+j] == a[j]) {
num++;
}
else {
p[cnt] = j + 1;
cnt++;
}
}
//cout << num << endl;
if(num > mx) {
mx = num;
for(int j = 0; j < cnt; j++) {
p1[j] = p[j];
}
c = cnt;
}
}
printf("%d\n", n - mx);
for(int i = 0; i < c; i++) printf("%d ", p1[i]);
return 0;
}
C. Hacker, pack your bags!
结构体一顿瞎做
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w",stdout);
#define INFLL 0x3f3f3f3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long LL;
typedef pair<double, double> PII;
const long long INF = 1e16;
const int maxn = 1e6 + 5;
int n, x;
LL money[maxn];
struct node {
int st, ed, cost, time, flag;
}a[maxn];
int cmp(node aa, node bb) {
if(aa.st == bb.st) return aa.flag > bb.flag;
else return aa.st < bb.st;
}
bool check(node aa, node bb) {
if(aa.st < bb.st && aa.ed > bb.st) return 0;
else if(aa.st < bb.st && aa.ed > bb.ed) return 0;
else if(bb.st < aa.st && bb.ed > aa.st) return 0;
else if(bb.st < aa.st && bb.ed > aa.ed) return 0;
else if(bb.st == aa.st || bb.st == aa.ed || bb.ed == aa.st || bb.ed == aa.ed) return 0;
if(aa.time + bb.time != x) return 0;
return 1;
}
int main() {
//FIN
while(cin >> n >> x) {
int cas = 0;
for(int i = 1; i <= n; i++) {
cin >> a[cas].st >> a[cas].ed >> a[cas].cost;
a[cas].time = a[cas].ed - a[cas].st + 1;
a[cas].flag = 1;
cas++;
a[cas].st = a[cas-1].ed;
a[cas].ed = -1;
a[cas].flag = -1;
a[cas].time = a[cas-1].time;
a[cas].cost = a[cas-1].cost;
cas++;
}
//memset(money, INF, sizeof(money));
for(int i = 0; i <= x; i++) {
money[i] = INF;
}
LL ans = INF;
sort(a, a + cas, cmp);
for(int i = 0; i < cas; i++) {
if(a[i].flag == 1) {
if(x - a[i].time > 0) ans = min(ans , money[x - a[i].time] + (LL)a[i].cost);
//cout <<"i="<<i<<" "<<money[x-a[i].time]<<endl;
//cout << "ans="<<ans<<endl;
}
else {
//cout <<"i="<<i<<" "<<money[x-a[i].time]<<endl;
money[a[i].time] = min(money[a[i].time], (LL)a[i].cost);
}
}
if(ans == INF) cout << "-1" << endl;
else cout << ans << endl;
}
return 0;
}