Solution

首先这个矩阵, 很明显的就是Vandermonde矩阵. 我们有公式:

\[|F_n| = \prod_{1 \le j < i \le n} (a_i - a_j)
\]

套圈的半径, 显然就是最小圆覆盖问题.

考虑到数据范围比较大, 我们直接做肯定是不行的. 这时候就涉及到一个神奇的东西:

我们知道假如行列式的某两行相同, 则该行列式的值为\(0\). 考虑这道题, 我们发现它生成数据的方式非常奇怪, 假设生成\(x\)组询问, 则所有询问两两不相同的概率为

\[\prod_{k = n}^{n - x + 1} \frac k n
\]

这个概率会迅速地下降, 因此期望不需要太多的次数, 行列式的值就会变为\(0\)...

真是有意思...

#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <algorithm> using namespace std;
namespace Zeonfai
{
inline int getInt()
{
int a = 0, sgn = 1; char c;
while (! isdigit(c = getchar())) if (c == '-') sgn *= -1;
while (isdigit(c)) a = a * 10 + c - '0', c = getchar();
return a * sgn;
}
}
const int N = (int)1e5, M = (int)1e5, MOD = (int)1e9 + 7;
struct point
{
double x, y;
inline point friend operator -(const point &a, const point &b) { point res; res.x = a.x - b.x; res.y = a.y - b.y; return res; }
inline double friend operator *(const point &a, const point &b) { return a.x * b.y - a.y * b.x; }
}p[N + 1];
double r[M + 1];
int L[M + 1], R[M + 1];
inline double sqr(double a) { return a * a; }
inline double getDistance(point a, point b) { return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)); }
inline point getCentre(point a, point b, point c)
{
point ret;
double a1 = b.x - a.x, b1 = b.y - a.y, c1 = (a1 * a1 + b1 * b1) / 2;
double a2 = c.x - a.x, b2 = c.y - a.y, c2 = (a2 * a2 + b2 * b2) / 2;
double d = a1 * b2 - a2 * b1;
ret.x = a.x + (c1 * b2 - c2 * b1) / d;
ret.y = a.y + (a1 * c2 - a2 * c1) / d;
return ret;
}
int main()
{ #ifndef ONLINE_JUDGE freopen("circle.in", "r", stdin);
freopen("circle.out", "w", stdout); #endif using namespace Zeonfai;
int n = getInt();
for (int i = 1; i <= n; ++ i) p[i].x = getInt(), p[i].y = getInt();
int m = getInt();
int ans = 1;
for (int i = 1; i <= m; ++ i)
{
L[i] = getInt(), R[i] = getInt();
if (! ans) { printf("%lld\n", (long long)L[i] * R[i]); continue; }
point cen = p[L[i]]; r[i] = 0;
for (int j = L[i] + 1; j <= R[i]; ++ j) if (getDistance(p[j], cen) > r[i])
{
cen = p[j]; r[i] = 0;
for (int k = L[i]; k < j; ++ k) if (getDistance(p[k], cen) > r[i])
{
cen.x = (p[j].x + p[k].x) / 2; cen.y = (p[j].y + p[k].y) / 2;
r[i] = getDistance(p[j], cen);
for (int l = L[i]; l < k; ++ l) if (getDistance(p[l], cen) > r[i])
{
if ((p[k] - p[j]) * (p[l] - p[j]) == 0)
{
cen.x = (p[j].x + p[l].x) / 2; cen.y = (p[j].y + p[l].y) / 2;
r[i] = getDistance(p[l], cen);
}
else cen = getCentre(p[j], p[k], p[l]), r[i] = getDistance(p[l], cen);
}
}
}
for (int j = 1; j < i; ++ j) ans = (long long)ans * ((long long)r[i] - (long long)r[j] + MOD) % MOD;
printf("%lld\n", (long long)ans + L[i] * R[i]);
}

NOI模拟题6 Problem C: Circle的更多相关文章

  1. NOI模拟题1 Problem A: sub

    题面 Sample Input 5 7 2 -1 -3 1 1 1 2 1 3 3 4 3 5 2 1 3 0 2 1 2 1 2 1 1 -3 2 Sample Output 2 4 5 2 HIN ...

  2. NOI模拟题5 Problem A: 开场题

    Solution 注意到\(\gcd\)具有结合律: \[ \gcd(a, b, c) = \gcd(a, \gcd(b, c)) \] 因此我们从后往前, 对于每个位置\(L\), 找到每一段不同的 ...

  3. NOI模拟题4 Problem C: 填格子(board)

    Solution 首先我们要有敏锐的直觉: 我们将每一列中不选哪种颜色看作是一个序列, 则我们发现这个序列要求相邻两位的颜色不同. 我们还发现, 一个这样的序列对应两种不同的合法的棋盘, 因此统计合法 ...

  4. NOI模拟题4 Problem B: 小狐狸(fox)

    Solution 考虑分开统计朝向每一个方向的所有狐狸对答案的贡献. 比如说以向右为例, 我们用箭标表示每一只狐狸的方向, 用\('\)表示当前一步移动之前的每一只狐狸的位置. \[ \begin{a ...

  5. NOI模拟题4 Problem A: 生成树(mst)

    Solution 我们考虑答案的表达式: \[ ans = \sqrt{\frac{\sum_{i = 1}^{n - 1} (w_i - \overline{w})^2}{n - 1}} \] 其中 ...

  6. 花海漫步 NOI模拟题

    题目好像难以看懂? 题目大意 给出一个字符串\(S\),统计满足以下条件的\((i,j,p,q)\)的数量. \(i \leq j, p \leq q\) \(S[i..j],S[p..q]\)是回文 ...

  7. 神奇的矩阵 NOI模拟题

    神奇的矩阵 题目大意 有一个矩阵\(A\),第一行是给出的,接下来第\(x\)行,第\(y\)个元素的值为数字\(A_{x-1,y}\)在\(\{A_{x-1,1},A_{x-1,2},A_{x-1, ...

  8. Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem K. UTF-8 Decoder 模拟题

    Problem K. UTF-8 Decoder 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c702 ...

  9. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem I. Interest Targeting 模拟题

    Problem I. Interest Targeting 题目连接: http://codeforces.com/gym/100714 Description A unique display ad ...

随机推荐

  1. [原]sencha touch之carousel

    carousel组件是个非常不错的东东,自带可滑动的效果,效果如下图 上面部分可以左右滑动,下面部分可以上下滑动,效果还是不错的,app程序中很有用的布局 代码如下: Ext.application( ...

  2. 码农与UI沟通的日常

    事情是这样的,这是一个兴趣群组的效果图. 我看了一眼没有帖子时的提示,觉得这样的提示 不走心 不能展现出我们团队对于人生及世界的深度理解和高尚的品格. 于是,我选择了表达内心的真实感受. 我觉得这完美 ...

  3. Careercup - Microsoft面试题 - 24313662

    2014-05-12 07:27 题目链接 原题: Convert a number to a number 题目:把二进制数转化成四进制数. 解法:四是二的倍数,所以两位变一位就可以了. 代码: / ...

  4. Python框架之Django学习笔记(六)

    模板 上篇博文学习了动态视图,但是,视图中返回文本的方式有点特别. 也就是说,HTML被直接硬编码在 Python 代码之中. def current_datetime(request): now = ...

  5. stdlib.h中自带的两个算法qsort,bsearch

    http://zh.cppreference.com/w/c/algorithm ========== void qsort( void *ptr, size_t count, size_t size ...

  6. 如何删除本地docker images镜像

    背景 本地空间较小,想删除无效的docker镜像内容. 操作步骤 查看本地docker镜像 尝试删除本地镜像 发现无法直接删除镜像 原因分析: 有关联docker容器,无法删除 删除docker容器 ...

  7. docker log 批量删除报错: find: `/var/lib/docker/containers/': 没有那个文件或目录

    问题描述: 服务器上面docker log太多,打算用之前写的批量清理shell脚本清理掉,但是发现报错. find: `/var/lib/docker/containers/': 没有那个文件或目录 ...

  8. GDOI2018前夕 错误总结

    算法易错点 $FFT$ 1.注意精度,以及是否取整 2.注意$complex$类不要写错,复数乘法是这样的: complex operator *(const complex &b){retu ...

  9. BZOJ 3509 [CodeChef] COUNTARI ——分块 FFT

    分块大法好. 块内暴力,块外FFT. 弃疗了,抄SX队长$silvernebula$的代码 #include <map> #include <cmath> #include & ...

  10. 配置ubuntu16.04下Theano使用GPU运行程序的环境

    ubuntu16.04默认安装了python2.7和python3.5 .本教程使用python3.5 第一步:将ubuntu16.04默认的python2修改成默认使用python3 . sudo ...