构造。应该有多种构造方法。做的时候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. LA2965 n个数中选出最多个数异或和为0

    intput n 1<=n<=24 n串只有大写字母的字符串 output 选出最多个字符串且每个大写字母出现的次数为偶数 第一行输出个数x 第二行输出x个字符串的下标 做法:将每个字符串 ...

  2. linux(视频学习)2

    第二部分(javaee的开发环境的搭建): 1. 安装jdk的过程: 安装ios的镜像文件,挂载到/mnt目录下.挂载: mount  /mnt/cdrom卸载: umount  /mnt/cdrom ...

  3. javascript语句语义大全(5)

    1. var str = "abcd";alert(str.length);alert(str.charAt(0));//获取下标为0的字符alert(str.charCodeAt ...

  4. GenericApp SampleApp SimpleAp的区别

    SampleApp3.2 Zigbee2007 协议栈实验例程表演说明C:\Texas Instruments\ZStack-2.0.0-1.2.0\Projects\zstack\Samples\S ...

  5. JavaScript(四)---- 函数

    函数主要用来封装具体的功能代码. 函数是由这样的方式进行声明的:关键字 function.函数名.一组参数,以及置于括号中的待执行代码. 格式: function 函数名(形参列表){         ...

  6. jq判断元素是否显示

    为了判断元素是否显示,jquery中用is()来实现, $(function(){ $(obj).bind('click',function(){ if(obj.is(:visible)){ //编写 ...

  7. 玩Mega8 智能充电器-12. 终于实现-dV检测(转)

    源:http://blog.chinaunix.net/uid-10701701-id-91873.html 2010.1.3 5:30终于补齐了. 电池充电的-dv 的检测系列图片请移步: http ...

  8. Server对象

    Server是服务器对象,定义了一个与Web服务器相关的类,用于访问服务器上的资源. 属性 MachineName   获取服务器的计算机名.    返回本地计算机的名称 ScriptTimeout  ...

  9. Hibernate分页查询小结

    通常使用的Hibernate通常是三种:hql查询,QBC查询和QBE查询: 1.QBE(Qurey By Example)检索方式 QBE 是最简单的,但是功能也是最弱的,QBE的功能不是特别强大, ...

  10. Recover Polygon (easy)

    Recover Polygon (easy) The zombies are gathering in their secret lair! Heidi will strike hard to des ...