日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Social Distancing

發布時間:2024/5/14 编程问答 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Social Distancing 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

鏈接: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) (1T250) , 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) (1n8,1r30).
輸出描述:
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=1n?1?j=i+1n?d(i,j)=i=1n?1?j=i+1n?(xi??xj?)2+i=1n?1?j=i+1n?(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=1n?1?j=i+1n?(xi??xj?)2?=i=1n?1?j=i+1n?(xi2??2xi?xj?+xj2?)=(n?1)i=1n?xi2??2i=1n?1?j=i+1n?xi?xj?=ni=1n?xi2??(i=1n?xi2?+2i=1n?1?j=i+1n?xi?xj?)=ni=1n?xi2??(i=1n?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=1n?1?j=i+1n?d(i,j)=ni=1n?(xi2?+yi2?)?(i=1n?xi?)2?(i=1n?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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。