构造。应该有多种构造方法。做的时候WA了好几发,怀疑做法是错的,事实上是代码写搓了。。

我是这样构造的:先从上往下左右放奇数,再从下往上左右填偶数

(一)如果n/2是偶数(以12为例) 左边列是内环,右边列是外环

(二)如果n/2是奇数(以10为例) 左边列是内环,右边列是外环

#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <queue>
#include <stack>
#include <map>
#include<cmath>
#include <vector>
using namespace std; int a[],b[];
int n;
int ans[];
int tot; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n); int num=n/;
memset(a,,sizeof a);
memset(b,,sizeof b); int small=;
int large=n-;
for(int i=;i<=(num+)/;i++)
{
if(i%==)
{
b[i]=small;
b[num-i+]=large;
} else
{
a[i]=small;
a[num-i+]=large;
}
small=small+;
large=large-;
} int x=;
for(int i=num;i>=;i--)
{
if(a[i]==) a[i]=x;
else b[i]=x;
x=x+;
} // for(int i=1;i<=n/2;i++) printf("%d ",a[i]); printf("\n");
// for(int i=1;i<=n/2;i++) printf("%d ",b[i]); printf("\n"); tot=;
for(int i=n/;i>=;i--)
{
ans[tot]=a[i]; tot++;
ans[tot]=b[i]; tot++;
} ans[n+]=ans[]; ans[n+]=ans[]; int sum=;
for(int i=;i<=n;i++)
sum=sum+(ans[i]-ans[i+])*(ans[i]-ans[i+]); for(int i=;i<=n/;i++)
sum=sum+(ans[*i-]-ans[*i])*(ans[*i-]-ans[*i]); printf("%d\n",sum);
} return ;
}

HUST 1353 Dartboard的更多相关文章

  1. HUST 1017 - Exact cover (Dancing Links 模板题)

    1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0 ...

  2. ubuntu 16.04 source (HUST and 163)

    #HUST deb http://mirrors.hust.edu.cn/ubuntu/ xenial main restricted universe multiverse deb http://m ...

  3. Dancing Link --- 模板题 HUST 1017 - Exact cover

    1017 - Exact cover Problem's Link:   http://acm.hust.edu.cn/problem/show/1017 Mean: 给定一个由0-1组成的矩阵,是否 ...

  4. 递推DP URAL 1353 Milliard Vasya's Function

    题目传送门 /* 题意:1~1e9的数字里,各个位数数字相加和为s的个数 递推DP:dp[i][j] 表示i位数字,当前数字和为j的个数 状态转移方程:dp[i][j] += dp[i-1][j-k] ...

  5. hust 1010 最短循环节点

    题目链接:http://acm.hust.edu.cn/problem/show/1010 KMP失配指针的利用: next数组前缀和后缀最长公共长度,这样len - next[len];就是最短的循 ...

  6. URAL 1353 Milliard Vasya's Function(DP)

    题目链接 题意 : 让你找出1到10^9中和为s的数有多少个. 思路 : 自己没想出来,看的题解,学长的题解报告 题解报告 //URAL 1353 #include <iostream> ...

  7. ural 1353. Milliard Vasya's Function

    http://acm.timus.ru/problem.aspx?space=1&num=1353 #include <cstdio> #include <cstring&g ...

  8. HUST 1017(DLX)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=65998#problem/A 题意:求01矩阵的精确覆盖. DLX学习资料:ht ...

  9. [ACM] HUST 1017 Exact cover (Dancing Links,DLX模板题)

    DESCRIPTION There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is ...

随机推荐

  1. docker的一些常用命令整理

    docker清除命令: 杀掉所有容器:docker kill $(docker ps -q) ; 清除所有容器:docker rm $(docker ps -a -q) ; 清除所有镜像:docker ...

  2. ligerUI调用$.ligerDialog.open弹出窗口,关闭后无法获取焦点问题

    1:调用父窗口某一个文件框,获取焦点,   parent.window.document.getElementByIdx_x("roleName").focus(); 2:关闭父窗 ...

  3. UVALive - 3942 Remember the Word

    input 字符串s  1<=len(s)<=300000 n 1<=n<=4000 word1 word2 ... wordn 1<=len(wordi)<=10 ...

  4. http请求连接

    1.在Info.plist中添加NSAppTransportSecurity类型Dictionary.2.在NSAppTransportSecurity下添加NSAllowsArbitraryLoad ...

  5. VS2013使用技巧汇总

    1. Peek View 在不新建TAB的情况下快速查看.编辑一个函数的代码. 以前要看一个函数的实现,需要在使用的地方点击F12跳转到该函数,实际上这是很浪费时间的.VS2013Peek View便 ...

  6. sqlserver 2008 查看表描述,和表结构

    sp_help sys_user sp_columns   sys_user --表结构 THEN obj.name ELSE '' END AS 表名, col.colorder AS 序号 , c ...

  7. jQuery Mobile 学习

    jQuery Mobile 学习系列 http://blog.csdn.net/bao990423420/article/details/13995021

  8. selenium和pythond的区别

    selenium和pythond的区别 天宇6169 | 浏览 137 次 2016-03-18 10:25 2016-03-18 12:24 最佳答案   selenium ide是用来录制的!大概 ...

  9. getByClassName2016/4/21

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  10. 转:Selenium借助AutoIt识别上传(下载)详解

    AutoIt目前最新是v3版本,这是一个使用类似BASIC脚本语言的免费软件,它设计用于Windows GUI(图形用户界面)中进行自动化操作.它利用模拟键盘按键,鼠标移动和窗口/控件的组合来实现自动 ...