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

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;
}

  

时间: 2024-10-09 00:17:28

Codeforces Round #422 (Div. 2) A-C的相关文章

Codeforces Round #422 (Div. 2) D. My pretty girl Noora

题目链接:Codeforces Round #422 (Div. 2) D. My pretty girl Noora 题意: 给你一个数n和t,l,r,让你求 t0·f(l)?+?t1·f(l?+?1)?+?...?+?tr?-?l·f(r). 其中f(n)是n个人的最少比较次数. 比如n为4,可以先2 2分,然后胜出2个人,最后再比较一次,所以f(4)=3. f(3)=3,因为3为质数,只能这样分. 题解: 这题半天没看清楚题意啊.- -!以为是任意分. 结果是选一个数x,每组都必须为x个人

Codeforces Round #422 (Div. 2) A. I&#39;m bored with life 暴力

A. I'm bored with life Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the

Codeforces Round #422 (Div. 2) C. Hacker, pack your bags! 排序+贪心

链接: http://codeforces.com/contest/822/problem/C 题意: 有x天的假期, 有n张旅行票, 每张票有起始时间l, 结束时间r, 花费cost, 想把假期分成两部分出去旅游, 两部分时间不能重合(ri < lj || rj < li), 问最小花费是多少, 如果不能两部分, 输出-1 题解: CF官方解法, 效率O(nlogn2) 设置一个结构体, struct P{int p, len, cost, type}; 将每张票(l, r, cost) 表

Codeforces Round #422 (Div. 2) C Hacker, pack your bags!

It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha. So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world.

Codeforces Round #422 (Div. 2) E. Liar 后缀数组+RMQ+DP

E. Liar The first semester ended. You know, after the end of the first semester the holidays begin. On holidays Noora decided to return to Vi?kopolis. As a modest souvenir for Leha, she brought a sausage of length m from Pavlopolis. Everyone knows th

Codeforces Round #422 (Div. 2)

A: 给你两个数 (最小的那个<=12)  问这两个数阶乘的GCD 我都吓傻了 直接fac(min(a,b)) 搞定 //By SiriusRen #include <bits/stdc++.h> using namespace std; int A,B; long long t=1; int main(){ scanf("%d%d",&A,&B); if(A>B)swap(A,B); for(int i=1;i<=A;i++)t=t*i;

Codeforces Round #422 (Div. 2) C. Hacker, pack your bags! 排序,贪心

C. Hacker, pack your bags! It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha. So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack co

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i