HUST 1353 Dartboard
构造。应该有多种构造方法。做的时候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的更多相关文章
- HUST 1017 - Exact cover (Dancing Links 模板题)
1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0 ...
- ubuntu 16.04 source (HUST and 163)
#HUST deb http://mirrors.hust.edu.cn/ubuntu/ xenial main restricted universe multiverse deb http://m ...
- Dancing Link --- 模板题 HUST 1017 - Exact cover
1017 - Exact cover Problem's Link: http://acm.hust.edu.cn/problem/show/1017 Mean: 给定一个由0-1组成的矩阵,是否 ...
- 递推DP URAL 1353 Milliard Vasya's Function
题目传送门 /* 题意:1~1e9的数字里,各个位数数字相加和为s的个数 递推DP:dp[i][j] 表示i位数字,当前数字和为j的个数 状态转移方程:dp[i][j] += dp[i-1][j-k] ...
- hust 1010 最短循环节点
题目链接:http://acm.hust.edu.cn/problem/show/1010 KMP失配指针的利用: next数组前缀和后缀最长公共长度,这样len - next[len];就是最短的循 ...
- URAL 1353 Milliard Vasya's Function(DP)
题目链接 题意 : 让你找出1到10^9中和为s的数有多少个. 思路 : 自己没想出来,看的题解,学长的题解报告 题解报告 //URAL 1353 #include <iostream> ...
- ural 1353. Milliard Vasya's Function
http://acm.timus.ru/problem.aspx?space=1&num=1353 #include <cstdio> #include <cstring&g ...
- HUST 1017(DLX)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=65998#problem/A 题意:求01矩阵的精确覆盖. DLX学习资料:ht ...
- [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 ...
随机推荐
- OpenGL编程指南第版本学习笔记 --- OpenGL程序实现过程(win32 + OpenGL)
1. 先上代码 头文件glCommon.h #include <GL/glew.h> #include <GL/GL.h> #include <GL/GLU.h> ...
- 项目管理实践教程一、工欲善其事,必先利其器【Basic Tools】
今天,我们首先安装一些必须的软件,主要有下面的4个,其中软件1和2使用在服务器机上,软件3和4安装在客户端机上.另外,我们还有用到MSBuild.RoboCopy.WebDeployment等等,在下 ...
- 初探JavaScript魅力
<style> #div1{width:200px; height:200px; background:red;} </style> </head> <scr ...
- ios 基础学习二
1:@property @synthesize 属性(类似java里的get set) 上面那个类原先的实现是这样: #import @interface Photo : NSObject { NS ...
- Windows编译安装mod_wsgi,配合使用Django+Apahce
编译环境: 均是32位版本 Microsoft Visual Studio 10.0 Microsoft SDKs v7.1 Apache2.4 Python3.4 mod_wsgi-4.5.0 要求 ...
- 转:Jmeter 用户思考时间(User think time),定时器,和代理服务器(proxy server)
在负载测试中需要考虑的的一个重要要素是思考时间(think time), 也就是在两次成功的访问请求之间的暂停时间. 有多种情形挥发导致延迟的发生: 用户需要时间阅读文字内容,或者填表,或者查找正确的 ...
- android:editable is deprecated: Use an <EditText> to make it editable
问题:android:editable is deprecated: Use an to make it editable 意思:Android的:编辑是反对:使用<</span> ...
- plat模板修改记录
每个栏目显示文章数 homepage.hph 94行 $loop = new WP_Query('post_type=post&showposts=6&category_name=xi ...
- linux无法解析主机地址(could not resolve host)解决办法
修改/etc/hosts文件: ip地址 域名 例:192.30.253.120 codeload.github.com
- 我的android学习脚步----------- 的第一个应用
刚刚开始学android开发,以前都是在别人调好的应用中修改JNI,现在需要自己一步步走 开发环境:Eclipse+ADT 配置不多讲了,引自:http://www.cnblogs.com/allen ...