#NOIP 2014#day.2 T1 无限网络发射器选址
2016-07-26 11:29
302 查看
为了方便处理我们把x++,y++预留出一个空白行和空白列
#include<cstdio> #include<iostream> #include<cmath> #include<cstring> #include<algorithm> using namespace std; int d,n; #define maxn 140 int a[maxn][maxn]; int sum[maxn][maxn]; int ans = 0, tot = 0; int main() { #define LOC #ifdef LOC freopen("wireless.in","r",stdin); freopen("wireless.out","w",stdout); #endif scanf("%d",&d); scanf("%d",&n); int x,y; for(int i=0;i<n;i++) { scanf("%d%d",&x,&y); x++,y++; if(x>129||y>129)continue; scanf("%d",&a[x][y]); } sum[1][1]=a[1][1]; for(int i=2;i<=129;i++)sum[1][i]=sum[1][i-1]+a[1][i]; for(int j=2;j<=129;j++)sum[j][1]=sum[j-1][1]+a[j][1]; for(int i=2;i<=129;i++) { for(int j=2;j<=129;j++) { sum[i][j]=sum[i][j-1]+sum[i-1][j]+a[i][j]-sum[i-1][j-1]; } } for(int i=1;i<=129;i++) { for(int j=1;j<=129;j++) { int dx = max(0,i-d-1); int kx = min(129,i+d); int dy = max(j-d-1,0); int ky = min(129,j+d); int _tot = sum[kx][ky]-sum[dx][ky]-sum[kx][dy]+sum[dx][dy]; if(_tot==tot)ans++; else if(_tot>tot) { ans = 1; tot = _tot; } } } printf("%d %d",ans,tot); return 0; } /* 对于 100%的数据, 1 ≤ d ≤ 20, 1 ≤ n ≤ 20, 0 ≤ x ≤ 128, 0 ≤ y ≤ 128, 0 < k ≤1,000,000。 输出一行,包含两个整数, 用一个空格隔开,分别表示能覆盖最多公共场所的安装地点 方案数,以及能覆盖的最多公共场所的数量。 */
相关文章推荐
- C++ 多线程 前缀和
- Codeforces538F A Heap of Heaps【分块+差分求前缀和】
- hduacm 5480 Conturbatio前缀和
- Hdu 5307 He is Fly 2015ACM多校对抗赛第二场
- Hdu 4609 FFT
- 2015ACM多校对抗赛第四场 hdu 5327
- CodeForces 19D A and B and Interesting Substrings 【前缀和】
- cf#320 Div.2 Problem E Weakness and Poorness
- 【转】积性函数前缀和的求法——By Tangjz
- 多线程技术模拟并行计算之二:数组前缀和(Prefix Sum)
- BZOJ 1218 HNOI 2003 激光炸弹 模拟
- 浅谈一类积性函数的前缀和
- HDU 1556树状数组求解
- BZOJ 2160 拉拉队排练 Manacher + 前缀和
- Codeforces 17E Palisection Manacher ( 或 Panlindromic Tree ) + 前缀和
- 洛谷1147 连续自然数和
- 基于OpenCL的图像积分图算法实现
- 【前缀和】hdu 5480 Conturbatio
- 使用MPI并行求解前缀和(prefix sum)
- poj 2739 Sum of Consecutive Prime Numbers 小结