构造。应该有多种构造方法。做的时候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. 字符串编码问题(Ascii、Unicode、UCS-2、GBK、UTF-8)

    1.字符编码的发展 第一阶段:ASCII阶段,(American Standard Code for Information Interchange, "美国信息交换标准码),计算机当时只支 ...

  2. POJ 1308/并查集

    题目链接 /* 判断一棵树: * 1.There is exactly one node, called the root, to which no directed edges point. * 2 ...

  3. android 原生的DownloadManager

    代码: public class MainActivity extends Activity { private DownloadManager downloadManager; public sta ...

  4. Win7下配置Django+Apache+mod_wsgi+Sqlite

    搭建环境: win7 64位 Django 1.8.5 Apache2.4.17 mod_wsgi_ap24py27.so Python2.7.9 1 安装Apache 下载Apache Haus版, ...

  5. ubuntu11.10server 安装php-redis插件

    1.下载php-redis插件 1 sudo wget https://github.com/nicolasff/phpredis/archive/master.zip 2.安装 1 2 3 4 5 ...

  6. CSS3线性渐变

    万恶的IE!!! <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  7. 第15章 I/O(输入/输出)

    在变量.数组和对象中存储的数据是暂时存在的,程序结束后它们就会丢失.为了能够永久地保存创建的数据,需要将其保存在磁盘文件中,这样就可以在其它程序中使用它们.Java的I/O技术可以将数据保存到文本文件 ...

  8. Oracle\PLSQL Developer报“动态执行表不可访问,本会话的自动统计被禁止”的解决方案

    现象: 第一次用PLSQL Developer连接数据库,若用sys用户登录并操作则正常,若用普通用户比如haishu登录并创建一个表则报错“动态执行表不可访问,本会话的自动统计被禁止.在执行菜单里你 ...

  9. IP 网际协议

    1. IP数据首部长度: 4位版本号 : 4 位,用于标明 IP 版本号,0100 表示 IPv4,0110 表示 IPv6.目前常见的是 IPv4. 4位首部长度: 首部长度是占4位,可表示的最大十 ...

  10. Hadoop webHDFS设置和使用说明

    1.配置 namenode的hdfs-site.xml是必须将dfs.webhdfs.enabled属性设置为true,否则就不能使用webhdfs的LISTSTATUS.LISTFILESTATUS ...