ConvexScore
时间限制: 1 Sec 内存限制: 128 MB
提交: 48 解决: 21
[提交] [状态] [讨论版] [命题人:admin]
题目描述
You are given N points (xi,yi) located on a two-dimensional plane. Consider a subset S of the N points that forms a convex polygon. Here, we say a set of points S forms a convex polygon when there exists a convex polygon with a positive area that has the same set of vertices as S. All the interior angles of the polygon must be strictly less than 180°.
For example, in the figure above, {A,C,E} and {B,D,E} form convex polygons; {A,C,D,E}, {A,B,C,E}, {A,B,C}, {D,E} and {} do not.
For a given set S, let n be the number of the points among the N points that are inside the convex hull of S (including the boundary and vertices). Then, we will define the score of S as 2n−|S|.
Compute the scores of all possible sets S that form convex polygons, and find the sum of all those scores.
However, since the sum can be extremely large, print the sum modulo 998244353.
Constraints
1≤N≤200
0≤xi,yi<104(1≤i≤N)
If i≠j, xi≠xj or yi≠yj.
xi and yi are integers.
输入
The input is given from Standard Input in the following format:
N
x1 y1
x2 y2
:
xN yN
输出
Print the sum of all the scores modulo 998244353.
样例输入
4
0 0
0 1
1 0
1 1
样例输出
5
提示
We have five possible sets as S, four sets that form triangles and one set that forms a square. Each of them has a score of 20=1, so the answer is 5.
题意
给定 N 个点,对于一个凸 n 边形,称其的 n 个顶点构成一个集合 S,并且这个多边形内及其边上有 k 个顶点,定义这个 S 的 score 为 2k−n.
对所有的 score 求和,输出 mod 998244353 的值。
思路
考虑一个凸 n 边形,其内与其上共 k 个顶点,那么它对最后答案的贡献是 2k−n。这意味着什么呢?就是除去顶点以外的 k−n 个顶点取不取的所有情况数。
取 0 个,取 1 个,取若干个,取所有,事实上这些所有情况的点的效果都是那一个凸 n 边形(因为已经固定取了那 n 个点作为顶点)。
所以可以说,对于任意 m 个点,只要其中有一个子集能构成一个凸多边形,那么其对最后答案就有贡献为。
贡献为多少呢?我们猜想是 1。所以究竟可不可能重复呢?是不可能的。因为对于给定的 m 个点,其最外面的一圈轮廓(…)是确定下来的,而顶点的 n 个点也随之确定。
于是就得到了一个双射,问题就转化成了,有多少个点集满足其子集能构成凸多边形,也即有多少个点集不是所有点共线。
这里有两种做法。
暴力
复杂度:O(n3)O(n3)
枚举两个顶点,看有多少个点在这两个顶点连成的线上。枚举的两个点固定,其他所有点中至少取一个,情况数就是这条线上共线的点集个数。显然,不会有重复。累和,即为最终答案。
PS 怎么说,这个题我看了半小时,压根没看懂啥意思,原谅我英语菜,我还只是个孩子。。。。。。。。。。。。
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
int x[205], y[205], p[205];
int main(void)
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d%d", &x[i], &y[i]);
p[0] = 1;
for (int i = 0; i < n; i++)
p[i + 1] = (p[i] << 1) % MOD;
int ans = p[n] - n - 1;// 要组成凸多边形 所有情况减去取一个点的情况减去都不取的情况
for (int i = 0; i < n; i++) {//固定两个点枚举其他点
for (int j = 0; j < i; j++) {
int cnt = 0;
for (int k = 0; k < j; k++) {
if ((x[i] - x[j]) * (y[i] - y[k]) == (x[i] - x[k]) * (y[i] - y[j]))//斜率相等 共线
cnt++;
}
ans =(ans-p[cnt]+MOD)%MOD;
}
}
printf("%d\n", ans);
return 0;
}