2016 ACM/ICPC 青岛赛区网络赛 XM Reserves
来源:互联网 发布:淘宝虚假宣传如何处罚 编辑:程序博客网 时间:2024/05/21 07:48
HDU5885
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
Time limit
10000 ms
Memory limit
102400 kB
此算法核心是利用FFT在
题目要求计算在
ps: 1e9 int/ll multiplications/additions in C++ is about 1.5/2 seconds 可利用here计算
若利用FFT计算,可以用一个向量表示位置信息和值,另一个向量表示某一个位置平移后的权。这样的复杂度为
向量A表示位置信息的值,最大为
注意到向量C最大为
式中
然后进行投影:
加R的原因是B中偏移量i,j最小为-R。
卷积计算结果即是向量C。
最后取C(的实部)中最大值即可。
//FFT 模板 Begin#include<algorithm> //swap max#include<cmath> //acos#include<vector>using namespace std;const double PI = acos(-1.0);struct Complex // 复数{ double r, i; Complex(double _r = 0, double _i = 0) :r(_r), i(_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); } Complex operator *(const Complex &b) { return Complex(r*b.r - i*b.i, r*b.i + i*b.r); }};void change(vector<Complex> &y, int len) // 二进制平摊反转置换 O(logn) { int i, j, k; for (i = 1, j = len / 2;i < len - 1;i++) { if (i < j) swap(y[i], y[j]); k = len / 2; while (j >= k) { j -= k; k /= 2; } if (j < k) j += k; }}void fft(vector<Complex> &y, int len, int on) //FFT:on=1; IFFT:on=-1{ change(y, len); for (int h = 2;h <= len;h <<= 1) { Complex wn(cos(-on * 2 * PI / h), sin(-on * 2 * PI / h)); for (int j = 0;j < len;j += h) { Complex w(1, 0); for (int k = j;k < j + h / 2;k++) { Complex u = y[k]; Complex t = w*y[k + h / 2]; y[k] = u + t; y[k + h / 2] = u - t; w = w*wn; } } } if (on == -1) for (int i = 0;i < len;i++) y[i].r /= len;}//FFT 模板 End#include<stdio.h>int main(){ #ifndef ONLINE_JUDGE freopen("D:/in.txt","r",stdin); #endif int n,m; double r; while(~scanf("%d%d%lf",&n,&m,&r)){ int R = floor(r); int M = max(n,m) + 2 * R; int len = 1; while (len<=M*M) len<<=1; //扩容至2^n vector<Complex> A(len,0); vector<Complex> B(len,0); vector<Complex> C(len,0); for(int i = 0;i<n;i++){ for(int j = 0;j<m;j++){ int p; scanf("%d",&p); A[i*M+j] = Complex(p); } } for(int i = - R;i<=R;i++){ for(int j = - R;j<=R;j++){ if(i*i + j*j < r*r){ B[(i+R)*M+j+R] = Complex(1/(sqrt(i*i + j*j) + 1)); } } } fft(A, len, 1); fft(B, len, 1); for (int i = 0;i < len;i++) { C[i] = A[i] * B[i]; } fft(C, len, -1); double ans = C[R*M+R].r; for(int i = 0;i<n;i++){ for(int j = 0;j<m;j++){ ans = ans>C[(i+R)*M+j+R].r?ans:C[(i+R)*M+j+R].r; } } printf("%.3f\n",ans); }}
- 2016 ACM/ICPC 青岛赛区网络赛 XM Reserves
- 2016ICPC青岛赛区网络赛 1001
- 2016ICPC青岛赛区网络赛 1002
- 2016ICPC青岛赛区网络赛 1004
- hdu 5878 I Count Two Three 2016ACM/ICPC青岛赛区网络赛1001
- hdu 5879 Cure 2016ACM/ICPC青岛赛区网络赛1002
- hdu 5881 Tea 2016ACM/ICPC青岛赛区网络赛1004
- hdu 5882 Balanced Game 2016ACM/ICPC青岛赛区网络赛1005
- hdu 5883 The Best Path 2016ACM/ICPC青岛赛区网络赛1006
- hdu 5884 Sort 2016ACM/ICPC青岛赛区网络赛1007
- hdu 5889 Barricade 2016ACM/ICPC青岛赛区网络赛1011
- hdu 5886 Tower Defence 2016ACM/ICPC青岛赛区网络赛1009
- 2016 ACM/ICPC 青岛赛区网络赛 I Count Two Three
- 2016 ACM-ICPC 亚洲区(青岛赛区)现场赛
- 2016icpc网络赛——青岛赛区
- ICPC青岛赛区网络赛总结
- 2017 ACM-ICPC 亚洲区(青岛赛区)网络赛 待补
- 2017 ACM-ICPC 亚洲区(青岛赛区)网络赛总结
- Linux oracle监听启动失败
- unity包内的内容读取
- 详解Javascript中正则表达式的使用
- CSS-表单伪类选择器
- dpvs 连接会话老化处理逻辑
- 2016 ACM/ICPC 青岛赛区网络赛 XM Reserves
- C#的远程post与get
- C#基础(7)——方法(函数)
- Lable+input 單選標籤的單擊事件執行兩次
- CSS-伪元素选择器
- qrcode动态生成二维码
- gulp详细入门教程
- HTML 動態添加的標籤綁定事件
- 【数据结构】实验二:栈与队列的应用---表达式求值