其他分享
首页 > 其他分享> > 「NOIP2016」愤怒的小鸟

「NOIP2016」愤怒的小鸟

作者:互联网

传送门
Luogu

解题思路

首先这个数据范围十分之小啊。
我们考虑预处理出所有可以带来贡献的抛物线 三点确定一条抛物线都会噻
然后把每条抛物线可以覆盖的点状压起来,然后状压DP随便转移就好了。
有一个小小的优化就是每次枚举打掉哪两头猪的时候可以钦定打掉编号最小的那头。

细节注意事项

参考代码

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
    s = 0; int f = 0; char c = getchar();
    while (!isdigit(c)) f |= c == '-', c = getchar();
    while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
    s = f ? -s : s;
}

const double eps = 1e-7;

int n, m; double x[20], y[20];
int t[20][20], dp[1 << 19];

inline void solve() {
    read(n), read(m);
    for (rg int i = 1; i <= n; ++i)
        scanf("%lf%lf", x + i, y + i);
    for (rg int i = 1; i <= n; ++i) {
        for (rg int j = i + 1; j <= n; ++j) {
            t[i][j] = 0;
            double x1 = x[i], y1 = y[i], x2 = x[j], y2 = y[j];
            double a = (y1 * x2 - y2 * x1) / (x1 * x2 * (x1 - x2));
            double b = (y1 * x2 * x2 - y2 * x1 * x1) / (x1 * x2 * (x2 - x1));
            if (a < -eps) {
                for (rg int k = 1; k <= n; ++k)
                    if (fabs(a * x[k] * x[k] + b * x[k] - y[k]) <= eps)
                        t[i][j] |= 1 << (k - 1);
            }
        }
    }
    memset(dp, 0x3f, sizeof dp), dp[0] = 0;
    for (rg int s = 0; s < 1 << n; ++s) {
        int i;
        for (i = 1; s & 1 << (i - 1); ++i);
        dp[s | 1 << (i - 1)] = min(dp[s | 1 << (i - 1)], dp[s] + 1);
        for (rg int j = i + 1; j <= n; ++j)
            dp[s | t[i][j]] = min(dp[s | t[i][j]], dp[s] + 1);
    }
    printf("%d\n", dp[(1 << n) - 1]);
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
    freopen("out.out", "w", stdout);
#endif
    int T; read(T);
    while (T--) solve();
    return 0;
}

完结撒花 \(qwq\)

标签:NOIP2016,20,int,小鸟,抛物线,isdigit,include,愤怒,getchar
来源: https://www.cnblogs.com/zsbzsb/p/11785401.html