Problem Description

As an eligible Ingress Resistance Agent you should know your power source, the Exotic Matter.
We call it XM, which is the driving force behind all of our actions in Ingress.
XM allows us to construct items through hacking portals, to attack enemy portals, make links and create fields.
We try to collect XM from the ground. XM concentration come from location based services, meaning that areas with a lot of foot traffic have higher amounts versus places that don't.
You can collect XM by moving through those areas.
The XM will be automatically harvested by your Scanner when it is within your interaction circle/range.
Alice decides to select a location such that she can collect XM as much as possible.
To simplify the problem, we consider the city as a grid map with size `n*m' numbered from (0,0) to (n−1,m−1).
The XM concentration inside the block (i,j) is p(i,j).
The radius of your interaction circle is r.
We can assume that XM of the block (i,j) are located in the centre of this block.
The distance between two blocks is the Euclidean distance between their centres.

Alice stands in the centre of one block and collects the XM.
For each block with the distance d smaller than r to Alice, and whose XM concertation is p(i,j), Alice's scanner can collects p(i,j)/(1+d) XM from it.
Help Alice to determine the maximum XM which she can collect once he stands in the centre of one block.

 
Input
There are multiple cases.
For each case, the first line consists two integers n,m (1≤n,m≤500) and one float-point number r (0≤r≤300).
Each of the following n line consists m non-negative float-point numbers corresponding to the XM concentrations inside each blocks.
Output
For each case, output the maximum XM which Alice can collect in one line.
Your answers should be rounded to three decimal places.
 
Sample Input
3 3 1
1 3 6
7 9 4
2 8 1
3 3 2
1 3 6
7 9 4
2 8 1
5 5 1.
5 4 3 2 9
1 3 4 3 2
8 9 4 3 2
1 2 3 0 1
2 6 3 4 3 1
 
Sample Output
9.000
24.142
17.956
 
题意就是给你一个n*m的格子,每个格点上有一个p[i,j]
让你选取一个位置,对于所有在以这个点为中心,半径为r的圆内的点的Σp(i,j)/(d+1)最大, d为点到圆心的距离
 
思路:我们可以对于每个点统计它能对那些格点造成的贡献,然后我们遍历每一个格点就能找到答案了
我们从坐标变换的角度来思考,假如一个点的坐标为(x,y),圆心跟它的坐标差为(dx,dy)那么圆心的坐标
就是(x+dx,y+dy),由于格点横纵坐标都是整数,我们可以在整数上离散化dx,dy,实际上-r<=dx,dy<=r
那么我们对于一个格点,如果它当作圆心(也就是我们选取的位置),剩下能对它产生贡献的点(称为贡献点)都有一个共同的特性
那就是对于每一个贡献点经过一个(dx,dy)的向量偏移后都会到达圆心,即对于所有贡献点(xi+dx,yi+dy)都相等
联想到FFT是来求什么的?两个多项式做乘积,能得出结果中每个幂次的系数,我们把每个圆心的坐标看成是多项式乘积结果的每个幂次
就把这个问题转化成了一个卷积的问题了
不要忘了坐标是二维的,我们就把坐标转换成一维的, (x,y)→x*M+j (M=max(n+2R,m+2R))
我们看下叉姐的题解...

为什么要用M呢?为什么要加个2R呢?   我们注意到dx,dy是有可能是负数,为了避免这种情况我们在定义坐标转换的时候把dx,dy都加上R对应图上B数组
这样一行原本m个数,最后经过dx,dy平移后就有了m+2*R种位置
举个例子B[(-2+R)*M+3+R]里面存的其实是向量(2.3),即横坐标-2,纵坐标+3
 #include <bits/stdc++.h>

 using namespace std;
const int maxn = <<;
const double pi = acos(-1.0);
#define fft FFT
#define r real
struct Complex
{
double r,i;
Complex(double _r,double _i):r(_r),i(_i){}
Complex(){}
Complex operator +(const Complex &b)
{
return Complex(r+b.r,i+b.i);
}
Complex operator -(const Complex &b)
{
return Complex(r-b.r,i-b.i);
}
Complex operator *(const Complex &b)
{
return Complex(r*b.r-i*b.i,r*b.i+i*b.r);
}
};
void change(Complex y[],int len)
{
int i,j,k;
for(i = , j = len/;i < len-;i++)
{
if(i < j)swap(y[i],y[j]);
k = len/;
while( j >= k)
{
j -= k;
k /= ;
}
if(j < k)j += k;
}
}
void fft(Complex y[],int len,int on)
{
change(y,len);
for(int h = ;h <= len;h <<= )
{
Complex wn(cos(-on**pi/h),sin(-on**pi/h));
for(int j = ;j < len;j += h)
{
Complex w(,);
for(int k = j;k < j+h/;k++)
{
Complex u = y[k];
Complex t = w*y[k+h/];
y[k] = u+t;
y[k+h/] = u-t;
w = w*wn;
}
}
}
if(on == -)
for(int i = ;i < len;i++)
y[i].r /= len;
}
Complex a[maxn],b[maxn];
int n,m;
double rr;
int main()
{
//freopen("de.txt","r",stdin);
while (~scanf("%d%d%lf",&n,&m,&rr)){
int R = ceil(rr);
int M = max(n,m)+*R;
int len = ;
while (len<=M*M) len<<=;
for (int i=;i<len;++i)
a[i]=Complex(0.0,0.0),b[i]=Complex(0.0,0.0);
for (int i=;i<n;++i){
for(int j=;j<m;++j){
double p;
scanf("%lf",&p);
a[i*M+j]=Complex(p,);
}
}
for (int i=-R;i<=R;++i){
for (int j=-R;j<=R;++j){
if (sqrt(i*i+j*j)<rr)
b[(i+R)*M+j+R]=Complex(1.0/(sqrt(i*i+j*j)+),0.0);
}
}
FFT(a,len,);
FFT(b,len,);
for (int i=;i<len;++i)
a[i] = a[i]*b[i];
FFT(a,len,-);
double ans = ;
for (int i=;i<n;++i){
for(int j=;j<m;++j)
ans = max(ans,a[(i+R)*M+j+R].r);//答案让求实数的时候后面"+0.5"精度处理就不加了
}
printf("%.3lf\n",ans);
}
return ;
}

hdu 5885 XM Reserves (FFT建模)的更多相关文章

  1. hdu 5885 FFT

    XM Reserves Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)T ...

  2. hdu 5142 NPY and FFT

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5142 NPY and FFT Description A boy named NPY is learn ...

  3. HDU 4609 3-idiots(FFT)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4609 题意:给出n个正整数(数组A).每次随机选出三个数.问这三个数能组成三角形的概率为多大? 思路: ...

  4. hdu 5730 Shell Necklace fft+cdq分治

    题目链接 dp[n] = sigma(a[i]*dp[n-i]), 给出a1.....an, 求dp[n]. n为1e5. 这个式子的形式显然是一个卷积, 所以可以用fft来优化一下, 但是这样也是会 ...

  5. HDU 4609 3-idiots (组合数学 + FFT)

    题意:给定 n 条边,问随机选出 3 条边,能组成三角形的概率是多少. 析:答案很明显就是  能组成三角形的种数 / (C(n, 3)).现在的问题是怎么求能组成三角形的种数. 这个博客说的非常清楚了 ...

  6. HDU 1402 大数乘法 FFT、NTT

    A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. HDU 4609 3-idiots ——(FFT)

    这是我接触的第一个关于FFT的题目,留个模板. 这题的题解见:http://www.cnblogs.com/kuangbin/archive/2013/07/24/3210565.html. FFT的 ...

  8. hdu 4609: 3-idiots (FFT)

    题目链接 题意:从N个数中,选出三个两两不同的数,求这三个数能够作为一个三角形的三边长的概率. 题解:用一个数组num[]记录大小为 i 的数出现的次数,通过 num[] 卷 num[] 得到 num ...

  9. 2016 ACM/ICPC Asia Regional Qingdao Online

    吐槽: 群O的不是很舒服 不知道自己应该干嘛 怎样才能在团队中充分发挥自己价值 一点都不想写题 理想中的情况是想题丢给别人写 但明显滞后 一道题拖沓很久 中途出岔子又返回来搞 最放心的是微软微软妹可以 ...

随机推荐

  1. 01 spring security入门篇

    1. 环境搭建 使用SpringBoot搭建开发环境,只需在pom.xml添加如下依赖即可. <?xml version="1.0" encoding="UTF-8 ...

  2. 趣头条基于 Flink 的实时平台建设实践

    本文由趣头条实时平台负责人席建刚分享趣头条实时平台的建设,整理者叶里君.文章将从平台的架构.Flink 现状,Flink 应用以及未来计划四部分分享. 一.平台架构 1.Flink 应用时间线 首先是 ...

  3. 【LeetCode 85】最大矩形

    题目链接 [题解] 把所有的"1"矩形分成m类. 第j类的矩形.他的右边界跟第j列紧靠. 那么. 我们设f[i][j]表示(i,j)这个点往左最长能延伸多少个数目的"1& ...

  4. LOJ 2719 「NOI2018」冒泡排序——模型转化

    题目:https://loj.ac/problem/2719 首先要发现合法的充要条件是 | LDS | <=2 ! 因为有没用的步数,说明一个元素先往左移.又往右移(不会先往右移再往左移,因为 ...

  5. NOIP普及组:买铅笔

    参加考试的时候,第一题我足足花了四十多分钟(因为那奇葩的键盘,幸好我向老师报告更换了键盘),还是只得了五十分... 题目描述: P老师需要去商店买n支铅笔作为小朋友们参加NOIP的礼物.她发现商店一共 ...

  6. Spring CGLlB动态代理

    JDK 动态代理使用起来非常简单,但是它也有一定的局限性,这是因为 JDK 动态代理必须要实现一个或多个接口,如果不希望实现接口,则可以使用 CGLIB 代理. CGLIB(Code Generati ...

  7. 117、TensorFlow变量共享

    # sharing variables # Tensorflow supports two ways of sharing variables # 1.Explicitly passing tf.Va ...

  8. jmeter 导入csv数据中json格式数据取值不完整

    1.jmeter中添加csv数据文件时,数据是json格式 2.jmeter中执行取值发现只取了一部分 分析原因,json格式数据,中间有逗号,而csv是根据逗号来分割的,这回导致我们取值错位. 解决 ...

  9. ss证书问题

    #SSL--校验网站证书 #一.什么是SSL证书 from urllib import request #ssl免验证 import ssl ssl._create_default_https_con ...

  10. 关于ExtJS对javascript中的Object的扩展

    关于ExtJS对javascript中的Object的扩展,可以参考其帮助文档,文档下载地址:http://download.csdn.net/detail/z1137730824/7748893 下 ...