河南省多校脸萌第六场

URL http://acm.nyist.me/JudgeOnline/contest.php?cid=&cid=1013
这次题是最难的一次吧

B
《挑战》上的原题(差不多
复杂度 O(nlogn)

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;

typedef long long LL;
const double EPS = 1e-8;
const int INF = 0x3f3f3f3f;
const int MAXN = (int)(5e4) + 5;

int N, P;
int A[MAXN], B[MAXN];
void slove() {
    priority_queue<int> que;
    int ans = 0, tank = P;
    for(int i = 0; i < N; ++i) {
        int d = A[i];
        while(tank - d < 0) {
            if(que.empty()) {
                puts("-1");
                return ;
            }
            tank += que.top();
            que.pop();
            ++ans;
        }
        tank -= d;
        que.push(B[i]);
    }
    printf("%d\n", ans);
}

int main()
{
    while(scanf("%d%d", &P, &N) != EOF) {
        for(int i = 0; i < N; ++i) {
            scanf("%d", A + i);
        }
        for(int i = 0; i < N; ++i) {
            scanf("%d", B + i);
        }
        slove();
    }
    return 0;
}

C
复杂度 Θ(n)

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;

typedef long long LL;
const double EPS = 1e-8;
const int INF = 0x3f3f3f3f;

char s[10005];
int cnt[260];

int main()
{
    while(scanf("%s", s) != EOF) {
        int ans = 1;
        memset(cnt, 0, sizeof cnt);
        for(int i = 0; s[i]; ++i) {
            ++cnt[s[i]];
        }
        int mod = 0;
        for(int i = 0; i < 260; ++i) {
            if(cnt[i] > cnt[mod]) mod = i;
        }
        for(int i = 1; s[i]; ++i) {
            ans *= s[i]^s[i - 1];
            ans %= mod;
        }
        printf("%d\n", ans);
    }
    return 0;
}

D
复杂度 Θ(1)

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;

typedef long long LL;
const double EPS = 1e-8;
const int INF = 0x3f3f3f3f;
const double PI = acos((double)(-1.0));

int main()
{
    double R, r;
    while(scanf("%lf%lf", &R, &r) != EOF) {
        if(r >= R) {
            puts("2");
            continue;
        }
        double a = (R * R - r * r * 2.0) / (R * R);
        a = acos(a);
        printf("%.0lf\n", ceil(PI * 4.0 / a));
    }
    return 0;
}

F
复杂度 Θ(1)

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;

typedef long long LL;
const double EPS = 1e-8;
const int INF = 0x3f3f3f3f;

int main()
{
    int n, a, b;
    while(scanf("%d%d%d", &n, &a, &b) != EOF) {
        if(n < a) {
            puts("YES");
            continue;
        }
        n -= a;
        n %= a + b;
        puts(n < a ? "NO" : "YES");
    }
    return 0;
}

G
初看题,心想什么鬼?直接跳过,最后看有人过了,也重新看了下题,发现三块只能拼成一种单位矩形—— 4 × 8的,这样就是老问题了。
轮廓线dp或直接状压dp都是可以的,可以查看下面这篇文章,(其实也是参考《挑战》的
http://blog.youkuaiyun.com/ctsas/article/details/77606567
轮廓线dp复杂度 Θ(n24+logn)

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;

typedef long long LL;
int dp[2][1<<4];
const int MOD = 1000000007;
int modpow(int a, int n) {
    int res = 1;
    while(n) {
        if(n&1) res = 1LL * res * a % MOD;
        a = 1LL * a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main()
{
    int n;
    while(scanf("%d", &n) != EOF) {
        if(n % 4) {
            puts("-1");
            continue;
        }
        int m = n / 4;
        memset(dp, 0, sizeof(dp));
        int *crt = dp[0], *next = dp[1];
        crt[0] = 1;
        for(int i = m - 1; ~i; --i) {
            for(int j = 4 - 1; ~j; --j) {
                for(int s = 0; s < 1<<4; ++s) {
                    if(s>>j&1) {
                        next[s] = crt[s&~(1<<j)];
                        continue;
                    }
                    next[s] = crt[s|(1<<j)];
                    if(j + 1 < 4 && !(s>>(j + 1)&1)) {
                        next[s] += crt[s|(1<<j+1)];
                        next[s] %= MOD;
                    }
                }
                swap(crt, next);
            }
        }
        int ans = 1LL * crt[0] * modpow(2, n) % MOD;
        printf("%d\n", ans);
    }
    return 0;
}

I
xjb写就行了,复杂度 Θ(125)

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
const int INF = 0x3f3f3f3f;
int best;
struct node{
    char S[10];
}s;

void dfs(int now, node ste) {
    if(now > 5) return ;
    bool flag = true;
    for(int i = 1; i <= 9; ++i) {
        if(i != ste.S[i - 1] - '0') flag = false;
    }
    if(flag && best > now) best = now;
    node tmp = ste;
    for(int k = 0; k < 3; ++k) {
        int x = k, y = k;
        int z = x * 3;
        ste = tmp;
        node tt = ste;
        for(int i = 1; i <= 2; ++i) {
            char t = ste.S[z + 2];
            ste.S[z + 2] = ste.S[z + 1];
            ste.S[z + 1] = ste.S[z];
            ste.S[z] = t;
            dfs(now + 1, ste);
        }
        for(int i = 1; i <= 2; ++i) {
            char t = tt.S[y];
            tt.S[y] = tt.S[y + 3];
            tt.S[y + 3] = tt.S[y + 6];
            tt.S[y + 6] = t;
            dfs(now + 1, tt);
        }
    }
}

int main()
{
    while(scanf("%s", s.S) != EOF) {
        best = INF;
        dfs(0, s);
        if(best > 5) puts("impossible");
        else printf("%d\n", best);
    }
    return 0;
}

其他的题有时间再补—————————

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值