HUST 1353 Dartboard
来源:互联网 发布:mac双系统卸载windows 编辑:程序博客网 时间:2024/06/16 06:52
Description
A dartboard is a disc divided into n segments, with each segment labeled with a distinct positive integer between 1 and n. That integer indicates the score for hitting the segment. To make the game more interesting, the arrangement of numbers is chosen in such a way that the risk is maximized. The risk is estimated based on the differences in scores of adjacent segments. We're studying the following 'double-layered' structure of segments in this problem: i.e., n is always even, and we split the disc into two layers of n/2 parts along the circumference. We enumerate the segments in the following manner: the first segment is some outer segment, the second segment is the corresponding inner segment, the third segment is some adjacent outer segment, etc. An example of this enumeration is shown on the picture above. The total risk is defined as the sum of squared differences between the scores of adjacent segments. If the value assigned to segment i is ai, then the risk is: R=∑ i=1n(a i-a i+2) 2+∑ i=1n/2(a 2i-1-a 2i) 2 (we assume a n+1=a 1 and an+2=a 2 in this formula). You are to place the numbers from 1 through n into the segments in such a way that the total risk R is maximized.
Input
The input file contains an integer T means there are T cases followed. The next T lines: there is an even integer n (6 ≤ n ≤ 100) in each line.
Output
Output the MAX(R);
Sample Input
2106
Sample Output
46187
这个可以通过观察发现内外圈的和就是n+1然后相邻的位置方向倒过来就可以了
#include<cstdio>#include<cstring>#include<cmath>#include<queue>#include<vector>#include<iostream>#include<algorithm>#include<bitset>#include<functional>using namespace std;typedef unsigned long long ull;typedef long long LL;const int INF = 0x7FFFFFFF;const int maxn = 1e5 + 10;const int mod = 1e9 + 7;int T, n, a[maxn], ans;int sqr(int x, int y){return (x - y)*(x - y);}int main(){cin >> T;while (T--){cin >> n;int l = 1, r = n;ans = 0;a[0] = l;a[1] = r;for (int q = 2, h = n - 2, i = 0; q <= h; q += 2, h -= 2, i++){a[q] = --r; a[q ^ 1] = ++l;if (q < h) a[h] = --r, a[h ^ 1] = ++l;if (i & 1) {swap(a[q], a[q ^ 1]); if (q < h) swap(a[h], a[h ^ 1]);}}for (int i = 0; i < n; i++) ans += sqr(a[i], a[(i - 2 + n) % n]) + sqr(a[i], a[(i + 2) % n]) + sqr(a[i], a[i ^ 1]);printf("%d\n", ans / 2);}return 0;}
0 0
- HUST 1353 Dartboard
- HUST
- HUST
- HUST
- HUST
- SGU 416 Optimal Dartboard(找规律)
- SGU 416 Optimal Dartboard(脑洞YY乱搞)
- HUST 1328
- HUST-1010
- HUST 1408
- hust 1602
- HUST 1525
- hust 1010
- HUST 1422
- HUST 1563
- hust 1592
- HUST 1017
- HUST 1017
- Java类加载过程(3)
- 平衡二叉树(Balance Binary Tree) --AVL树
- MarkdownPad 2 安装使用之二三事
- 我有博客啦!
- 1031. Hello World for U (20)
- HUST 1353 Dartboard
- Factory
- 不错的链接地址
- HUST 1354 Rubiks
- oracle重复数据操作
- java encapsulation
- Linux常用命令之六:关机
- Xcode7 配置pch文件
- 信息指纹