链接:https://ac.nowcoder.com/acm/contest/5672/A
来源:牛客网

题目描述
Nowadays, the Kingdom of Dreamgrid is suffering from a national pandemic. Fortunately, president Baobao is working effectively with the Center for Disease Control (CDC) and they are trying their best to make everything under control.

President Baobao has announced a policy of Social Distancing to prevent the diffusion of the virus. As the chief of CDC, you are required to research on the following problem:

There are n n n people who need to be observed and you have already set a monitor in ( 0 , 0 ) (0,0) (0,0) on a 2 2 2-dimensional plane. Everyone should stay within the distance of r to the monitor. You also have to keep them stay away from each other as far as possible. To simplify the problem, you can only allocate them to integers coordinates.

Please maximize
∑ i = 1 n − 1 ∑ j = i + 1 n d ( i , j ) 2 \sum_{i=1}^{n-1}\sum_{j=i+1}^{n}d(i,j)^2 ∑i=1n−1​∑j=i+1n​d(i,j)2 ,
where d ( i , j ) d(i,j) d(i,j) means the Euclidean distance between the i i i-th and the j j j-th person.
输入描述:
There are multiple test cases. The first line of the input contains an integer T T T ( 1 ≤ T ≤ 250 ) (1 \leq T \leq 250) (1≤T≤250) , indicating the number of test cases.

For each test case, the only line contains two integers n , r n,r n,r ( 1 ≤ n ≤ 8 , 1 ≤ r ≤ 30 ) (1 \leq n \leq 8,1 \leq r \leq 30) (1≤n≤8,1≤r≤30).
输出描述:
Please output the answer in one line for each test case.
示例1

输入
2
4 2
5 10
输出
64
2496

设第 i i i个点的横坐标为 x i x_i xi​,纵坐标为 y i y_i yi​,则
∑ i = 1 n − 1 ∑ j = i + 1 n d ( i , j ) = ∑ i = 1 n − 1 ∑ j = i + 1 n ( x i − x j ) 2 + ∑ i = 1 n − 1 ∑ j = i + 1 n ( y i − y j ) 2 \sum_{i=1}^{n-1}\sum_{j=i+1}^nd(i,j)=\sum_{i=1}^{n-1}\sum_{j=i+1}^n(x_i-x_j)^2+\sum_{i=1}^{n-1}\sum_{j=i+1}^n(y_i-y_j)^2 i=1∑n−1​j=i+1∑n​d(i,j)=i=1∑n−1​j=i+1∑n​(xi​−xj​)2+i=1∑n−1​j=i+1∑n​(yi​−yj​)2
由于
∑ i = 1 n − 1 ∑ j = i + 1 n ( x i − x j ) 2 = ∑ i = 1 n − 1 ∑ j = i + 1 n ( x i 2 − 2 x i x j + x j 2 ) = ( n − 1 ) ∑ i = 1 n x i 2 − 2 ∑ i = 1 n − 1 ∑ j = i + 1 n x i x j = n ∑ i = 1 n x i 2 − ( ∑ i = 1 n x i 2 + 2 ∑ i = 1 n − 1 ∑ j = i + 1 n x i x j ) = n ∑ i = 1 n x i 2 − ( ∑ i = 1 n x i ) 2 \begin{aligned} \sum_{i=1}^{n-1}\sum_{j=i+1}^n(x_i-x_j)^2&=\sum_{i=1}^{n-1}\sum_{j=i+1}^n(x_i^2-2x_ix_j+x_j^2) \\ &=(n-1)\sum_{i=1}^nx_i^2-2\sum_{i=1}^{n-1}\sum_{j=i+1}^nx_ix_j\\ &=n\sum_{i=1}^nx_i^2-(\sum_{i=1}^nx_i^2+2\sum_{i=1}^{n-1}\sum_{j=i+1}^nx_ix_j)\\ &=n\sum_{i=1}^nx_i^2-(\sum_{i=1}^nx_i)^2 \end{aligned} i=1∑n−1​j=i+1∑n​(xi​−xj​)2​=i=1∑n−1​j=i+1∑n​(xi2​−2xi​xj​+xj2​)=(n−1)i=1∑n​xi2​−2i=1∑n−1​j=i+1∑n​xi​xj​=ni=1∑n​xi2​−(i=1∑n​xi2​+2i=1∑n−1​j=i+1∑n​xi​xj​)=ni=1∑n​xi2​−(i=1∑n​xi​)2​
因此 ∑ i = 1 n − 1 ∑ j = i + 1 n d ( i , j ) = n ∑ i = 1 n ( x i 2 + y i 2 ) − ( ∑ i = 1 n x i ) 2 − ( ∑ i = 1 n y i ) 2 \sum_{i=1}^{n-1}\sum_{j=i+1}^nd(i,j)=n\sum_{i=1}^n(x_i^2+y_i^2)-(\sum_{i=1}^nx_i)^2-(\sum_{i=1}^ny_i)^2 i=1∑n−1​j=i+1∑n​d(i,j)=ni=1∑n​(xi2​+yi2​)−(i=1∑n​xi​)2−(i=1∑n​yi​)2
令 d p [ i ] [ ∑ x ] [ ∑ y ] = m a x ( ∑ ( x 2 + y 2 ) ) dp[i][\sum x][\sum y]=max(\sum (x^2+y^2)) dp[i][∑x][∑y]=max(∑(x2+y2))
即 d p dp dp表示当前点数为 i i i,所有点的横坐标之和为 ∑ x \sum x ∑x,纵坐标之和为 ∑ y \sum y ∑y时所有点距离原点和 ∑ ( x 2 + y 2 ) \sum (x^2+y^2) ∑(x2+y2)的最大值。
状态转移方程为:
d p [ i ] [ ∑ x ] [ ∑ y ] = m i n ( d p [ i ] [ ∑ x ] [ ∑ y ] , d p [ i − 1 ] [ ∑ x − x j ] [ ∑ y − y j ] + ( x j 2 + y j 2 ) ) dp[i][\sum x][\sum y]=min(dp[i][\sum x][\sum y],dp[i-1][\sum x-x_j][\sum y-y_j]+(x_j^2+y_j^2)) dp[i][∑x][∑y]=min(dp[i][∑x][∑y],dp[i−1][∑x−xj​][∑y−yj​]+(xj2​+yj2​))
对于圆的半径 r r r从小到大各 d p dp dp一次。每次 d p dp dp完,更新 a n s [ i ] [ r ] = m a x ( a n s [ i ] [ r ] , i ⋅ d p [ i ] [ ∑ x ] [ ∑ y ] − ( ∑ x ) 2 − ( ∑ y ) 2 ) ans[i][r]=max(ans[i][r],i·dp[i][\sum x][\sum y]-(\sum x)^2-(\sum y)^2) ans[i][r]=max(ans[i][r],i⋅dp[i][∑x][∑y]−(∑x)2−(∑y)2)

#include<bits/stdc++.h>using namespace std;
const int base = 300;
int dp[10][605][605], ans[10][35];
vector<pair<int, pair<int, int>>> seq;
int now, T;int main() {for (int i = -30; i <= 30; ++i)for (int j = -30; j <= 30; ++j)seq.push_back({i * i + j * j, {i, j}});sort(seq.begin(), seq.end());memset(dp, -0x3f, sizeof(dp));dp[0][base][base] = 0;for (int r = 1; r <= 30; ++r) {while (seq[now].first <= r * r) {for (int i = 1; i <= 8; ++i)for (int x = base - r * i; x <= base + r * i; ++x)for (int y = base - r * i; y <= base + r * i; ++y)dp[i][x][y] = max(dp[i][x][y],dp[i - 1][x - seq[now].second.first][y - seq[now].second.second] + seq[now].first);now++;}for (int i = 1; i <= 8; ++i)for (int x = base - r * i; x <= base + r * i; ++x)for (int y = base - i * r; y <= base + r * i; ++y)if (dp[i][x][y] > 0)ans[i][r] = max(ans[i][r],i * dp[i][x][y] - ((x - base) * (x - base) + (y - base) * (y - base)));}scanf("%d", &T);while (T--) {int n, r;scanf("%d%d", &n, &r);printf("%d\n", ans[n][r]);}return 0;
}

Social Distancing相关推荐

  1. 【程序员の英文听写】Trump’s Totally Not Weird Way of Standing | The Daily Social Distancing Show

    Trump's Totally Not Weird Way of Standing | The Daily Social Distancing Show From The Daily Show wit ...

  2. 基于yolov5的行人检测跟踪与社交距离预测 (pedestrian detection and social distance prediction)

    代码.模型和示例DEMO下载地址: 下载地址 基本功能:通过距离分类人群的高危险和低危险距离. # 课程设计 # Social Distancing based on YOLOv5. 环境要求: Cy ...

  3. k3应付系统初始化应付票据_在家工作时应付无尽干扰的真实感觉

    k3应付系统初始化应付票据 Whether or not you have worked remotely before, you've likely never had to share your ...

  4. 计算机视觉 | YOLO开源项目汇总

    点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 1.Pytorch Yolo V3 使用PyTorch实现的YOLO v3对象检测算法 https:/ ...

  5. 汇总|Yolo开源项目

    点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 1.Pytorch Yolo V3 使用PyTorch实现的YOLO v3对象检测算法 https:/ ...

  6. 柳叶刀新文 | 利用统计模型与大数据探寻人口流动与新冠传播的潜在联系

    来源:运筹OR帷幄 本文约1400字,建议阅读7分钟 新冠预防,社交距离,人口流动趋势. 作者:杜鸿儒,约翰霍普金斯大学土木与系统工程系在读博士生,研究方向:流行病数据建模,人口流动模型,网络建模. ...

  7. 吴恩达的公司,发布了一款社交距离警告工具

    点击上方"AI遇见机器学习",选择"星标"公众号 重磅干货,第一时间送达 内容概要:提醒大家在公共场所保持距离,可以有效的防止交叉感染.近日吴恩达创立的公司 L ...

  8. IEEE CS:2021年的12大技术趋势

    来源:笑看国际风云 LOS ALAMITOS, Calif., 16 December 2020 – IEEE计算机协会(IEEE CS)公布了其2021技术预测报告(2021 Technology ...

  9. 深度学习用于视频检测_视频如何用于检测您的个性?

    深度学习用于视频检测 视频是新的第一印象! (Videos are the New First Impressions!) Think about the approximate number of ...

最新文章

  1. ConcurrentHashMap源码分析(1)——JDK1.7的实现
  2. android状态栏半透明灰色,Android7.0沉浸式状态栏蒙灰问题完美解决
  3. apue 2013-03-14
  4. JS本地加密防止嗅探
  5. 肿瘤坏死因子(TNF)阻断剂治疗幼年型银屑病关节炎: 有效吗
  6. 突破RHEL各种版本高阶应用限制!群集,虚拟化想怎么装就怎么装!!
  7. Linux中的configure、pkg-config、pkg_config_path
  8. Qt4_与主线程通信
  9. [C/C++标准库]_[0基础]_[优先队列priority_queue的使用]
  10. 【翻译】优秀网站的10个技巧
  11. ArcMAP 分类统计工具
  12. 计算机组成原理统一试卷,计算机组成原理试卷(含答案).doc
  13. WebRoot与WebContent区别
  14. mac电脑运行速度变慢的十种解决方法
  15. linux springboot开机启动,SpringBoot 部署到Linux开机自启动和运行
  16. u盘读不出来怎么修复?可以试试这个方法
  17. Oracle 序列使用整理
  18. C# 导出Excel文件 打开Excel文件格式与扩展名指定格式不一致。
  19. [机器学习-5]岭回归及python实现(Ridge Regression)
  20. JDK8 新特性Stream流的常用方法

热门文章

  1. 常用网络抓包工具推荐
  2. 程序员的专业主义精神——评《程序员的职业素养》
  3. javax.persistence.OneToMany.orphanRemoval()Z 解决办法
  4. 树莓派外设开发(快速上手)
  5. 第二十五章 使用系统监视器 - 应用程序监视器
  6. ubuntu安装mate桌面
  7. 魏永红java课后答案_基于J2ME技术的手机信息查询系统的设计与实现
  8. 【数据结构笔记】绪论
  9. 晕死了......冤
  10. 艾永亮:靠二次元起家的B站如何赢得1.3亿活跃用户?