SGU 416 Optimal Dartboard(找规律)

416. Optimal Dartboard
Time limit per test: 0.25 second(s) 
Memory limit: 262144 kilobytes
input: standard 
output: standard



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   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  a  i, then the risk is: 

R=∑  i=1  na  ia  i+22+∑  i=1  n/2a  2i-1a  2i2 

(we assume  a  n+1=a  1 and  a  n+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 even integer number  n (6 ≤  n ≤ 100). 

Output
Output  n integer numbers:  a  1a  2,...,  a  n, separated with single spaces. In case there are several possible solutions, output any. 

Example(s)

sample input
sample output
10
2 9 7 4 6 5 3 8 10 1


题意:
给你一个偶数n,表示一个内环有n/2个空,外环也有n/2个空,且内外环的空一一对应的图。如题目中的图所示,它表示n为20的图形。现在你要把1到n这n个数往空里填,使得每两个相邻的空的数的差的平方和最大。然后按照图示顺序输出这n个数。

思路:
很明显,要想使差的平方和最大,最小的那一个周围肯定是最大的三个数,然后第二大的数旁边要放上第二小的数,然后第三大的数旁边要放上第三小的数,依次类推,很容易把这个环形的每个空按要求填满。那么接下来就只需要按要求输出就行了。随便列几个情况,很容易发现规律,当n/2为偶数的时候,我们只需要按大小小大或小大大小的顺序输出即可,当n/2为奇数的时候,除了中间那一组以外其余的仍然是大小小大或小大大小的顺序,而中间那一组只要不变就行了,具体看代码。

AC代码:
#include <iostream>  
#include <cstdio>  
#include <cstring>  
#include <string>  
#include <cstdlib>  
#include <cmath>  
#include <vector>  
#include <queue>  
#include <map>  
#include <algorithm>  
#include <set>  
#include <functional>  
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9 + 5;
const int MAXN = 1005;
const int MOD = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1.0);
LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a%b); }
LL ppow(LL a, LL b){LL res = 1;for (int i = 1; i <= b; i++)res *= a;return res;}

int ans[105];

int main()
{
	int i, n, p, q;
	bool flag1, flag2;
	while (scanf("%d", &n) != EOF)
	{
		flag2 = n % 4 == 0 ? false : true;
		p = 1;
		q = n;
		flag1 = true;
		i = 0;
		while (p<n)
		{
			if (flag1)
			{
				ans[++i] = max(p, q);
				ans[++i] = min(p, q);
				p += 2;
				q -= 2;
			}
			else
			{
				ans[++i] = min(p, q);
				ans[++i] = max(p, q);
				p += 2;
				q -= 2;
			}
			if (flag2 == true && p > q)//跳过中间这一组的异或步骤
			{
				flag2 = false;
				continue;
			}
			flag1 ^= 1;
		}
		for (int j = 1; j <= i; j++)
			if (j == 1)
				printf("%d", ans[j]);
			else
				printf(" %d", ans[j]);
		printf("\n");
	}
}


内容概要:该题库专为研究生入学考试计算机组成原理科目设计,涵盖名校考研真题、经典教材课后习题、章节题库和模拟试题四大核心模块。名校考研真题精选多所知名高校的计算机组成原理科目及计算机联考真题,并提供详尽解析,帮助考生把握考研命题趋势与难度。经典教材课后习题包括白中英《计算机组成原理》(第5版)和唐朔飞《计算机组成原理》(第2版)的全部课后习题解答,这两部教材被众多名校列为考研指定参考书目。章节题库精选代表性考题,注重基础知识与重难点内容,帮助考生全面掌握考试大纲要求的知识点。模拟试题依据历年考研真题命题规律和热门考点,精心编制两套全真模拟试题,并附标准答案,帮助考生检验学习成果,评估应试能力。 适用人群:计划参加研究生入学考试并报考计算机组成原理科目的考生,尤其是需要系统复习和强化训练的学生。 使用场景及目标:①通过研读名校考研真题,考生可以准确把握考研命题趋势与难度,有效评估复习成效;②通过经典教材课后习题的练习,考生可以巩固基础知识,掌握解题技巧;③通过章节题库的系统练习,考生可以全面掌握考试大纲要求的各个知识点,为备考打下坚实基础;④通过模拟试题的测试,考生可以检验学习成果,评估应试能力,为正式考试做好充分准备。 其他说明:该题库不仅提供详细的题目解析,还涵盖了计算机组成原理的各个方面,包括计算机系统概述、数据表示与运算、存储器分层、指令系统、中央处理器、总线系统和输入输出系统等。考生在使用过程中应结合理论学习与实践操作,注重理解与应用,以提高应试能力和专业知识水平。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值