首页 > 其他分享 >「解题报告」CF1290F Making Shapes

「解题报告」CF1290F Making Shapes

时间:2023-06-08 14:23:53浏览次数:38  
标签:cur int sum Shapes CF1290F npy npx && Making

最近好像一直懒得写题解,但是感觉还是写一写比较好。

首先若干个向量组成一个凸包有经典做法,就是把向量按照极角排序,然后按照极角顺序依次拼接,得到的就是一个凸包,且方案唯一(由于本题限制不存在共线的两个向量)。

那么我们实际上只需要知道每个向量最终用了多少就可以了。设第 \(i\) 个向量用了 \(c_i\) 个,那么这个向量集合能拼成凸包当且仅当它们的和为 \(0\),也就是 \(\sum_{x_i > 0} c_i x_i = \sum_{x_i < 0} c_i (-x_i), \sum_{y_i > 0} c_i y_i = \sum_{y_i < 0} c_i (-y_i)\)。

考虑高度的限制,由于凸包一定是先正后负,容易发现这就是在要求 \(\sum_{x_i > 0} c_i x_i \le m, \sum_{y_i > 0} c_i y_i \le m\)。

那么我们要求的就是满足:

\[\sum_{x_i > 0} c_i x_i = \sum_{x_i < 0} c_i (-x_i), \sum_{y_i > 0} c_i y_i = \sum_{y_i < 0} c_i (-y_i), \sum_{x_i > 0} c_i x_i \le m, \sum_{y_i > 0} c_i y_i \le m \]

的 \(\{c_i\}\) 的数量。看起来不好做,但是注意到 \(x_i\) 很小,所以我们可以考虑数位 DP,按位确定 \(c_i\) 的值。这样这些限制很容易满足,直接做就行了。

#include <bits/stdc++.h>
using namespace std;
const int P = 998244353;
int n, m;
int x[5], y[5];
int g[18][18][18][18][2][2][30];
void add(int &a, int b) {
    a += b;
    if (a >= P) a -= P;
}
int f(int px, int nx, int py, int ny, bool xb, bool yb, int i) {
    if (i == 30) return px == 0 && nx == 0 && py == 0 && ny == 0 && xb && yb;
    int &cur = g[px][nx][py][ny][xb][yb][i];
    if (cur != -1) return cur;
    cur = 0;
    for (int s = 0; s < (1 << n); s++) {
        int npx = px, nnx = nx, npy = py, nny = ny;
        for (int j = 0; j < n; j++) if (s >> j & 1) {
            if (x[j] > 0) npx += x[j];
            if (x[j] < 0) nnx -= x[j];
            if (y[j] > 0) npy += y[j];
            if (y[j] < 0) nny -= y[j];
        }
        if ((npx & 1) != (nnx & 1) || (npy & 1) != (nny & 1)) continue;
        bool nxb = xb ? ((npx & 1) <= (m >> i & 1)) : ((npx & 1) < (m >> i & 1)),
             nyb = yb ? ((npy & 1) <= (m >> i & 1)) : ((npy & 1) < (m >> i & 1));
        add(cur, f(npx >> 1, nnx >> 1, npy >> 1, nny >> 1, nxb, nyb, i + 1));
    }
    return cur;
}
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &x[i], &y[i]);
    }
    memset(g, -1, sizeof g);
    printf("%d\n", (f(0, 0, 0, 0, 1, 1, 0) - 1 + P) % P);
    return 0;
}

标签:cur,int,sum,Shapes,CF1290F,npy,npx,&&,Making
From: https://www.cnblogs.com/apjifengc/p/17466328.html

相关文章

  • [重读经典论文]RepVGG: Making VGG-style ConvNets Great Again
    1.参考视频:14.1RepVGG网络讲解博客:RepVGG网络简介2.主要内容2.1.与其他网络对比如下图所示,RepVGG无论是在精度还是速度上都已经超过了ResNet、EffcientNet以及ReNeXt等网络。2.2.创新点,结构重参数化在训练时,使用一个类似ResNet-style的多分支模型,而推理时转化成VGG-st......
  • 前端树形结构图treeShapeStruct,可拖拽移动,点击展开收缩,无限添加子集
    快速实现树形结构图,可拖拽移动,点击展开收缩,无限添加子集;下载完整代码请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=12650效果图如下:  实现代码如下:#treeShapeStruct树形结构图,可拖拽移动,点击展开收缩,无限添加子集使用方法####HTML代码部分```......
  • Shapes布局-文字环绕动画
    @目录说明实现以及语法动画渐变裁切图形变换的动画效果说明Shapes也有形状、图形的意思,我们可以在页面中创建图形,并让内容环绕在定义的图形边上。Shapes的官方文档:https://developer.mozilla.org/zh-CN/docs/Web/CSS/CSS_Shapes/From_box_values我们经常在一些宣传手册上看到......
  • Codeforces 1229B Kamil and Making a Stream
    \(\gcd\)一个性质:对于正整数\(x\),重复\(x\leftarrow\gcd(x,i)\)(\(i\ge0\))直到\(x=1\),\(x\)出现的值个数上限为\(\log_2(x)+1\)证明:考虑到\(x\)是逐渐变小,则在\(x\)变小的情况下,对于\(x=\prod_{i=1}^kp_i^{c_i}\)(\(p_i\\operatorname{为质数}\))中的\(c_i\)......
  • POJ - 3666 Making the Grade(DP)
    题目大意:给你一个数组A,要求将这个数组变成数组B,使得Sum(abs(A[i]-B[i]))达到最小,且B是单调的解题思路:因为答案要求输出单调非递增或者单调非递减的的任意一个,那就只考虑单调非递增吧,因为两个的思路是相同的如果要变化的话,且变化的值要达到最小的话,那么只能变成和前一个相同或者......
  • FIT5094 IT for Management Decision Making
    FIT5094ITforManagementDecisionMakingSemester1,2023Assignment1–AnalysisofaStrategicDecisionFormat:IndividualReportWeight:25%ofthemarksavailableforFIT5094IndicativeLength:2,500–3,000wordsDuedate:ThursdayApril6,2023@4:30......
  • Making a Plugin System with c++
      cplusplus.comTUTORIALS REFERENCE ARTICLES FORUM signup login[Legacyversion]C++TutorialsReferenceArticlesForum......
  • Codeforces 1630 E Making It Bipartite 题解 (Dilworth定理)
    题目链接首先可以想到把题目中的那张图G建出来,由于要求这张图是二分图,把它复制一遍(\(G\toG'\)),然后对于每个u,连一条无向边\(u-u'\),这样就变成了最大独立集问题。但是一......
  • Codeforces 1630 E Making It Bipartite 题解 (Dilworth定理)
    题目链接首先可以想到把题目中的那张图G建出来,由于要求这张图是二分图,把它复制一遍(\(G\toG'\)),然后对于每个u,连一条无向边\(u-u'\),这样就变成了最大独立集问题。但是一......
  • [Typescript] Extract the Result From Several Possible Function Shapes
    Let'simagineyou'rebuildingatypehelpertoextractoutthevaluefromseveraldifferent'parsers'.Hereareafewdifferentexamplesofwhataparsercanb......