NOI模拟题6 Problem C: Circle
Solution
首先这个矩阵, 很明显的就是Vandermonde矩阵. 我们有公式:
\]
套圈的半径, 显然就是最小圆覆盖问题.
考虑到数据范围比较大, 我们直接做肯定是不行的. 这时候就涉及到一个神奇的东西:
我们知道假如行列式的某两行相同, 则该行列式的值为\(0\). 考虑这道题, 我们发现它生成数据的方式非常奇怪, 假设生成\(x\)组询问, 则所有询问两两不相同的概率为
\]
这个概率会迅速地下降, 因此期望不需要太多的次数, 行列式的值就会变为\(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的更多相关文章
- 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 ...
- NOI模拟题5 Problem A: 开场题
Solution 注意到\(\gcd\)具有结合律: \[ \gcd(a, b, c) = \gcd(a, \gcd(b, c)) \] 因此我们从后往前, 对于每个位置\(L\), 找到每一段不同的 ...
- NOI模拟题4 Problem C: 填格子(board)
Solution 首先我们要有敏锐的直觉: 我们将每一列中不选哪种颜色看作是一个序列, 则我们发现这个序列要求相邻两位的颜色不同. 我们还发现, 一个这样的序列对应两种不同的合法的棋盘, 因此统计合法 ...
- NOI模拟题4 Problem B: 小狐狸(fox)
Solution 考虑分开统计朝向每一个方向的所有狐狸对答案的贡献. 比如说以向右为例, 我们用箭标表示每一只狐狸的方向, 用\('\)表示当前一步移动之前的每一只狐狸的位置. \[ \begin{a ...
- NOI模拟题4 Problem A: 生成树(mst)
Solution 我们考虑答案的表达式: \[ ans = \sqrt{\frac{\sum_{i = 1}^{n - 1} (w_i - \overline{w})^2}{n - 1}} \] 其中 ...
- 花海漫步 NOI模拟题
题目好像难以看懂? 题目大意 给出一个字符串\(S\),统计满足以下条件的\((i,j,p,q)\)的数量. \(i \leq j, p \leq q\) \(S[i..j],S[p..q]\)是回文 ...
- 神奇的矩阵 NOI模拟题
神奇的矩阵 题目大意 有一个矩阵\(A\),第一行是给出的,接下来第\(x\)行,第\(y\)个元素的值为数字\(A_{x-1,y}\)在\(\{A_{x-1,1},A_{x-1,2},A_{x-1, ...
- 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 ...
- 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 ...
随机推荐
- codeforce GYM 100741 A Queries
A. Queries time limit per test:0.25 s memory limit per test:64 MB input:standard input output:standa ...
- “帮你APP”团队冲刺6
1.整个项目预期的任务量 (任务量 = 所有工作的预期时间)和 目前已经花的时间 (所有记录的 ‘已经花费的时间’),还剩余的时间(所有工作的 ‘剩余时间’) : 所有工作的预期时间:88h 目前已经 ...
- 文件处理之复杂,在于内置方法-----python
抛砖引玉: 文件是我们储存信息的地方,我们经常要对文件进行读.写.删除等的操作,在Python中,我们可用Python提供的函数和方法方便地操作文件. ************************ ...
- Selenium - WebDriver: Waits
These days most of the web apps are using AJAX techniques. When a page is loaded to browser, the ele ...
- [错误解决]paramiko.ssh_exception.SSHException: Error reading SSH protocol banner 设置
报错信息 上午的时候数据组的同事跟我说有几个程序报错,经过查看log发现找到报错信息: paramiko.ssh_exception.SSHException: Error reading SSH p ...
- Box 类
public class Box extends JComponent implements Accessible使用 BoxLayout 对象作为其布局管理器的一个轻量级容器.Box 提供几个对使用 ...
- jquery中attr和prop的区别介绍
在高版本的jquery引入prop方法后,什么时候该用prop?什么时候用attr?它们两个之间有什么区别?这些问题就出现了. 关于它们两个的区别,网上的答案很多.这里谈谈我的心得,我的心得很简单: ...
- LAMP第四部分 mysql相关
1. 忘记root密码http://www.lishiming.net/thread-252-1-1.html 进入mysqlwhich mysql/usr/local/mysql/bin/mysql ...
- 【bzoj4869】[Shoi2017]相逢是问候 扩展欧拉定理+并查集+树状数组
题目描述 Informatik verbindet dich und mich. 信息将你我连结. B君希望以维护一个长度为n的数组,这个数组的下标为从1到n的正整数.一共有m个操作,可以分为两种:0 ...
- 编译静态库tinyxml2
tinyxml的makefile文件默认是编译可执行的二进制文件xmltest. 需要改成静态库. 更改OUTPUT := xmltest 为:OUTPUT := libtinyxml.a 删除SR ...