hdu 5885 XM Reserves (FFT建模)
Problem Description
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.
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.
Your answers should be rounded to three decimal places.
#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建模)的更多相关文章
- hdu 5885 FFT
XM Reserves Time Limit: 10000/10000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)T ...
- hdu 5142 NPY and FFT
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5142 NPY and FFT Description A boy named NPY is learn ...
- HDU 4609 3-idiots(FFT)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4609 题意:给出n个正整数(数组A).每次随机选出三个数.问这三个数能组成三角形的概率为多大? 思路: ...
- hdu 5730 Shell Necklace fft+cdq分治
题目链接 dp[n] = sigma(a[i]*dp[n-i]), 给出a1.....an, 求dp[n]. n为1e5. 这个式子的形式显然是一个卷积, 所以可以用fft来优化一下, 但是这样也是会 ...
- HDU 4609 3-idiots (组合数学 + FFT)
题意:给定 n 条边,问随机选出 3 条边,能组成三角形的概率是多少. 析:答案很明显就是 能组成三角形的种数 / (C(n, 3)).现在的问题是怎么求能组成三角形的种数. 这个博客说的非常清楚了 ...
- HDU 1402 大数乘法 FFT、NTT
A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 4609 3-idiots ——(FFT)
这是我接触的第一个关于FFT的题目,留个模板. 这题的题解见:http://www.cnblogs.com/kuangbin/archive/2013/07/24/3210565.html. FFT的 ...
- hdu 4609: 3-idiots (FFT)
题目链接 题意:从N个数中,选出三个两两不同的数,求这三个数能够作为一个三角形的三边长的概率. 题解:用一个数组num[]记录大小为 i 的数出现的次数,通过 num[] 卷 num[] 得到 num ...
- 2016 ACM/ICPC Asia Regional Qingdao Online
吐槽: 群O的不是很舒服 不知道自己应该干嘛 怎样才能在团队中充分发挥自己价值 一点都不想写题 理想中的情况是想题丢给别人写 但明显滞后 一道题拖沓很久 中途出岔子又返回来搞 最放心的是微软微软妹可以 ...
随机推荐
- JS中数据结构之队列
队列是一种列表,不同的是队列只能在队尾插入元素,在队首删除元素.队列用于存储按 顺序排列的数据,先进先出. 队列的两种主要操作是:向队列中插入新元素和删除队列中的元素.插入操作也叫做入 队,删除操作也 ...
- [CF1168D]Anagram Paths
题意:给一棵\(n\)个节点的二叉树,每条边上有一个小写字母或者\(?\),\(q\)次修改操作,每次修改某条边上的字符,问修改后是否存在一种方案,使得给所有\(?\)填上小写字母后,所有叶子到根的路 ...
- 【BZOJ1396】识别子串(后缀自动机,线段树)
题意: 一行,一个由小写字母组成的字符串S,长度不超过10^5 思路:论文题 设p为自动机上的合法结点,r为右端点,len=st[fa[p]]]+1 位置[r-st[p]+1,r-len+1]与r-i ...
- KVM(多电脑切换器)
KVM:Keyboard Video Mouse的缩写.KVM 交换机通过直接连接键盘.视频和鼠标 (KVM) 端口,让您能够访问和控制计算机.KVM 技术无需目标服务器修改软件.这就意味着可以在 W ...
- BZOJ 4710: [Jsoi2011]分特产(容斥)
传送门 解题思路 首先所有物品是一定要用完的,那么可以按照物品考虑,就是把每种物品分给\(n\)个人,每个人分得非负整数,可以用隔板法计算.设物品有\(m\)个,方案数为\(C(n+m-1,n-1)\ ...
- JS 中的offset、scroll、client总结
经常碰到offset.scroll.client这几个关键字,每次都要各种实验,这里总结一下. 两张图镇楼,随时翻阅 1. offset offset 指偏移,包括这个元素在文档中占用的所有显示宽度, ...
- python中的open()函数
定义: python open() 函数用于打开一个文件,创建一个 file 对象,相关的方法才可以调用它进行读写 参数: 模式 描述 r 以只读方式打开文件.文件的指针将会放在文件的开头.这是默认模 ...
- Spring Boot学习一之配置类及自动配置
一.配置类 1. 导入其他配置类 你不需要将所有的 @Configuration 放进一个单独的类, @Import 注解可以用来导入其他配置类.另外,你也可以使用 @ComponentScan 注解 ...
- nginx中如何设置gzip(总结)
nginx中如何设置gzip(总结) 一.总结 一句话总结: 真正用的时候,花一小点时间把gzip的各个字段的意思都看一下,会节约大量时间 直接gzip on:在nginx的配置中就可以开启gzip压 ...
- java 字符串的操作方法
方法 作用 范例 indexOf() 找到第一个字符出现的位置,()以下标来判断,返回的是字符所在的下标 int num = String.indexOf("字符") l ...