构造。应该有多种构造方法。做的时候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. POJ1556 The Doors 叉积+最短路

    题目大意:求从(0,5)到(10,5)的最短距离,起点与终点之间有n堵墙,每个墙有2个门. 题目思路:判断两点间是否有墙(判断两点的连线是否与某一堵墙的线段相交),建立一个图,然后最短路求出就可以了. ...

  2. MFC笔记<持续更新>

    1.设置垂直滚动条的位置在末尾 SCROLLINFO si; GetScrollInfo(SB_VERT, &si, SIF_PAGE | SIF_RANGE | SIF_POS); si.f ...

  3. php Memcached

    PHP 连接 Memcached 服务 在前面章节中我们已经介绍了如何安装 Memcached 服务,接下来我们为大家介绍 PHP 如何使用 Memcached 服务. PHP Memcache 扩展 ...

  4. Loadrunner之文件的下载(八)

    老猪提供: https://mp.weixin.qq.com/s?__biz=MzIwOTMzNDEwNw==&mid=100000013&idx=1&sn=624f5bc74 ...

  5. [转]用android LinearLayout和RelativeLayout实现精确布局

    先明确几个概念的区别: padding margin都是边距的含义,关键问题得明白是什么相对什么的边距. padding是控件的内容相对控件的边缘的边距. margin是控件边缘相对父控件的边距. a ...

  6. java 文件字节输出流

    Example10_5.java import java.io.*; public class Example10_5 { public static void main(String args[]) ...

  7. android ScrollView嵌套EditText

    editext.setOnTouchListener(new OnTouchListener() {                        @Override            publi ...

  8. Android传感器编程带实例(转)

    源:http://www.cnblogs.com/xiaochao1234/p/3894751.html 看了程序人生 网站的 编程高手的编程感悟 深有感触,好像也是一个android 程序员写的,推 ...

  9. oracle sql 分页

    Oracle实现分页时,需要引入一个rownum的函数,rownum可以给记录一个类似于id的字段. 以下收整理了常用的几种sql分页算法,数据库以Oracle中emp为例.查询结果如下: SQL&g ...

  10. Android------三种监听OnTouchListener、OnLongClickListener同时实现即其中返回值true或者false的含义

    引自:http://5200415.blog.51cto.com/3851969/1003113 android应用中常用的监听OnTouchListener.OnClickListener.OnLo ...