srm 558

欢迎点此阅读QvQ

275


Description

懒得写了= =自己看吧。。。

Solution

直接dp即可,用二进制的小技巧表示相同颜色即可

Code

#include <bits/stdc++.h>
using namespace std ;
typedef long long LL;
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N = 55, inf = 1e7;
int a[N], dp[N];
class Stamp {
    public:
        int getMinimumCost(string s, int A, int B) {
            int n = s.size();
            for (int i = 0; i < n; ++i) {
                if (s[i] == 'R')    a[i] = 1;
                if (s[i] == 'G')    a[i] = 2;
                if (s[i] == 'B')    a[i] = 4;
                if (s[i] == '*')    a[i] = 7;
            }
            int ans = inf;
            for (int l = 1; l <= n; ++l) {
                fill(dp, dp + n + 1, inf);
                dp[0] = 0;
                for (int i = 0; i < n; ++i) {
                    int now = 7;
                    for (int j = i; j < n; ++j) {
                        now &= a[j];
                        if (!now)   break;
                        int len = j - i + 1;
                        if (len >= l && dp[i] != inf)   dp[j + 1] = min(dp[j + 1], dp[i] + ((len + l - 1) / l) * B);
                    }
                }
                if (dp[n] != inf)   ans = min(ans, dp[n] + A * l);
            }
            return ans;
        }
};

550


Description

看图泥就懂题意了= =

Solution

首先枚举两个蓝色点,再枚举 B 点,复杂度可以接受
从小到大枚举B点时可以同时记录可以满足条件的 A 的个数,然后二分求出右面C,D的个数,统计即可

Code

#include <bits/stdc++.h>
using namespace std ;
typedef long long LL;
#define mp make_pair
#define pb push_back
#define F first
#define S second
class Ear {
    public:
        long long getCount(vector <string> redX, vector <string> blueX, vector <string> blueY) {
            string a, b, c;
            vector<int> r, bx, by;
            for (int i = 0; i < redX.size(); ++i)   a += redX[i];
            for (int i = 0; i < blueX.size(); ++i)  b += blueX[i];
            for (int i = 0; i < blueY.size(); ++i)  c += blueY[i];
            stringstream sa(a), sb(b), sc(c);
            int x;
            while (sa >> x) r.pb(x);
            while (sb >> x) bx.pb(x);
            while (sc >> x) by.pb(x);
            sort(r.begin(), r.end());
            LL ans = 0;
            int n = bx.size(), m = r.size();
            for (int i = 0; i < n; ++i)
                for (int j = 0; j < n; ++j) {
                    if (i == j) continue;
                    if (by[i] > by[j]) {
                        int tot = 0;
                        for (int k = 0; k < m; ++k) {
                            if (r[k] < bx[j]) {
                                int R = max(bx[i], bx[j]) + 1;
                                double x = 1e50;
                                if (bx[i] != bx[j]) {
                                    double k = (double)(by[i] - by[j]) / (bx[i] - bx[j]);
                                    x = bx[i] - (double)by[i] / k;
                                    R = max(R, (int)floor(x + 1e-6) + 1);
                                }
                                int RR = lower_bound(r.begin(), r.end(), R) - r.begin();
                                int LL = upper_bound(r.begin(), r.end(), bx[j]) - r.begin();
                                ans += 1ll * tot * (RR + m - LL * 2 - 1) * (m - RR) / 2;
                                if (r[k] < bx[i] && r[k] < x - 1e-6)    ++tot;
                            }       
                        }
                    }
                }
            return ans;
        }
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值