BestCoder 1st Anniversary


题目传送:BestCoder 1st Anniversary




1001


AC代码:

#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define INF 0x7fffffff
using namespace std;

int n, m, p, q;

int main() {
    int T;
    scanf("%d", &T);
    while(T --) {
        scanf("%d %d %d %d", &n, &m, &p, &q);
        if(q <= p) {
            int sum = n / m;
            if(n % m > 0) sum ++;
            int ans = sum * q;
            printf("%d\n", ans);
        }
        else if(q > p && ((q * 1.0) / m < p) ) {
            int sum = n / m;
            int ans = sum * q;
            if((n % m) * p < q) ans += (n % m) * p;
            else ans += q;
            printf("%d\n", ans);
        }
        else if(q > p && ((q * 1.0) / m >= p) ) {
            printf("%d\n", n * p);
        }
    }
    return 0;
}






1002


AC代码:

#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define INF 0x7fffffff
using namespace std;

const char an[] = "anniversary";

char s[105];
int len;

bool dfs(int a, int b, int c) {
    int tb = b;
    for(int i = a; i < len && b < 11; i ++) {
        if(s[i] == an[b]) {
            int j;
            for(j = i; j < len && b < 11; j ++, b ++) {
                if(s[j] != an[b]) break;
//                cout << s[j];
            }
//            cout << endl;
            if(b == 11 && c <= 2) return true;
            if(dfs(j, b, c + 1)) return true;
            else {
                b = tb;
            }
        }
    }
    
    return false;
}

int main() {
    int T;
    scanf("%d", &T);
    while(T --) {
        scanf("%s", s);
        len = strlen(s);
        if(dfs(0, 0, 0)) {
            printf("YES\n");
        }
        else {
            printf("NO\n");
        }
    }
    return 0;
}






你可能感兴趣的:(ACM,BestCoder)