Codeforces Round #422 (Div. 2) A-C

A. I'm bored with life

水题

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
#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

字符串匹配

英语太差题意花了很久才读懂.....

题意:上面的字符串要把多少个字符变为?才可以变为下面字符串的子串 要变得数量尽可能的小

直接暴力匹配就可以做了

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#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!

结构体一顿瞎做

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#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;
}

  

 

posted @   Hyouka  阅读(160)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示