仙人球的残影

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6851    Accepted Submission(s): 3192

Problem Description
在美丽的HDU,有一名大三的同学,他的速度是众所周知的,跑100米仅仅用了2秒47,在他跑步过程中会留下残影的哎,大家很想知道他是谁了吧,他叫仙人球,既然名字这样了,于是他的思想是单一的,他总是喜欢从一点出发,经过3次转折(每次向右转90°),回到出发点,而且呢,他每次转折前总是跑相同长度的路程,所以很多人都想知道如果用‘1’算他跑步出发的第一个残影的话,那么回到起点的时候,他的残影是怎么样的呢?
Input
测试数据有多行,每一行为一个数N(1<=N<=10)(以0结尾,0不做处理),即仙人球在没有回到起点的时候,跑过留下N个残影后突然90°右转。
Output
每组测试数据输出一个结果,并且每个残影的计数位长度为3个字符长度。(当然N等于1的话,它的结果也是占用3个字符位置的)
Sample Input
4
Sample Output
1  2  3  4
12  5  11  6
10  9  8  7

找了半天规律,最后写出700B的代码,后来在讨论区看见了几个有趣的解法,贴出来的大家分享一下,侵转删。。

1.首先是我的AC代码

 #include <iostream>
#include <cstdio>
using namespace std; int main()
{
int n;
while(scanf("%d",&n)&&n)
{
if(n==)//仅一个的情况
{
printf(" 1\n");
continue;
}
for(int i=; i<=n; i++)//第一行
printf("%3d",i);//输出占三个字符
printf("\n");
for(int i=; i<=n-; i++)//除最后一行剩余行数
for(int j=; j<=n; j++)
{
if(j!=&&j!=n)//除首尾外输出空格
printf(" ");
else if(j==)
printf("%3d",n*n-(n-)*(n-)-i+);
else if(j==n)
printf("%3d\n",n+i-);
}
for(int i=; i<=n; i++)//最后一行
printf("%3d",n*n-(n-)*(n-)-(n-)-i+);
printf("\n");
}
return ;
}

2.这是一个给边缘赋值,中间为空由此输出三个空字符的算法,确实有一套。

 #include <stdio.h>
#include <string.h>
int x,y,n,m;
int a[][];
int main()
{
int i,j;
while(scanf("%d",&n)!=EOF&&n)
{
memset(a,,sizeof(a));
int x=,y=,s=;
while()//边缘赋值
{
while(y<n-) a[x][++y]=++s;
while(x<n-) a[++x][y]=++s;
while(y->=)a[x][--y]=++s;
while(!a[x-][])a[--x][y]=++s;
break;
}
for(i=;i<n;i++)//中间为空
{
for(j=;j<n;j++)
{
if(a[i][j]==)
printf(" ");
else
printf("%3d",a[i][j]);
}
printf("\n");
}
}
return ;
}

3.哈哈哈哈第三种看到时Kiven当场噗出生来,从某种意义上来说比我们这些找规律的机智多了。 我服!

 #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
using namespace std;
int main()
{ int n;
while(scanf("%d",&n)!=EOF && n)
{
if (n==) printf(" 1\n");
if (n==) printf(" 1 2\n 4 3\n");
if (n==) printf(" 1 2 3\n 8 4\n 7 6 5\n");
if (n==) printf(" 1 2 3 4\n 12 5\n 11 6\n 10 9 8 7\n");
if (n==) printf(" 1 2 3 4 5\n 16 6\n 15 7\n 14 8\n 13 12 11 10 9\n");
if (n==) printf(" 1 2 3 4 5 6\n 20 7\n 19 8\n 18 9\n 17 10\n 16 15 14 13 12 11\n");
if (n==) printf(" 1 2 3 4 5 6 7\n 24 8\n 23 9\n 22 10\n 21 11\n 20 12\n 19 18 17 16 15 14 13\n");
if (n==) printf(" 1 2 3 4 5 6 7 8\n 28 9\n 27 10\n 26 11\n 25 12\n 24 13\n 23 14\n 22 21 20 19 18 17 16 15\n");
if (n==) printf(" 1 2 3 4 5 6 7 8 9\n 32 10\n 31 11\n 30 12\n 29 13\n 28 14\n 27 15\n 26 16\n 25 24 23 22 21 20 19 18 17\n");
if (n==) printf(" 1 2 3 4 5 6 7 8 9 10\n 36 11\n 35 12\n 34 13\n 33 14\n 32 15\n 31 16\n 30 17\n 29 18\n 28 27 26 25 24 23 22 21 20 19\n");
}
}

HDOJ-2153的更多相关文章

  1. HDOJ(HDU) 2153 仙人球的残影(谜一样的题、、、)

    Problem Description 在美丽的HDU,有一名大三的同学,他的速度是众所周知的,跑100米仅仅用了2秒47,在他跑步过程中会留下残影的哎,大家很想知道他是谁了吧,他叫仙人球,既然名字这 ...

  2. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  4. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  6. hdoj 1385Minimum Transport Cost

    卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...

  7. HDOJ(2056)&HDOJ(1086)

    Rectangles    HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...

  8. 继续node爬虫 — 百行代码自制自动AC机器人日解千题攻占HDOJ

    前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机&quo ...

  9. 最近点对问题 POJ 3714 Raid && HDOJ 1007 Quoit Design

    题意:有n个点,问其中某一对点的距离最小是多少 分析:分治法解决问题:先按照x坐标排序,求解(left, mid)和(mid+1, right)范围的最小值,然后类似区间合并,分离mid左右的点也求最 ...

  10. BFS(八数码) POJ 1077 || HDOJ 1043 Eight

    题目传送门1 2 题意:从无序到有序移动的方案,即最后成1 2 3 4 5 6 7 8 0 分析:八数码经典问题.POJ是一次,HDOJ是多次.因为康托展开还不会,也写不了什么,HDOJ需要从最后的状 ...

随机推荐

  1. C语言补漏(1)--- char到int赋值的一个陷阱

    作为一个C的新手(虽然学的第一门语言就是C,可是用C实际开发项目却是最近的事情),对使用C过程中遇到的各类问题.疑惑.知识漏洞进行弥补无疑是非常有必要的,于是决定将每次遇到的知识漏洞写到博客上. 今天 ...

  2. 微信小程序设置控件权重

    项目中最常用的两种布局方式,水平布局和垂直布局,在微信小程序中实现起来也比较简单.       1.横向水平布局:         实现水平布局,需要四个view容器组件,其中一个是父容器.如下: & ...

  3. nagios-plugins安装报错--with-mysql: no

    --with-mysql: no 解决方法 yum安装mysql-devel yum install mysql-devel

  4. Html控件和Web控件(转)

    作为一名ASP.NET的初学者,了解并且区别一些混淆概念是很必须的,今天这篇博文 就是主要向大家介绍一下Html控件和Web控件.在ASP.net中,用户界面控件主要就是 Html控件和Web控件,在 ...

  5. sql server charindex函数和patindex函数详解(转)

    charindex和patindex函数常常用来在一段字符中搜索字符或字符串.假如被搜索的字符中包含有要搜索的字符,那么这两个函数返回一个非零的整数,这个整数是要搜索的字符在被搜索的字符中的开始位数. ...

  6. python中的特殊用法

    1 别名 from xxx import xxx as xxx;

  7. Kafka核心思想

    Kafka是2010年12月份开源的项目,采用Scala语言编写,使用了多种效率优化机制,整体架构比较新颖(push/pull),更适合异构集群. 设计目标: (1) 数据在磁盘上的存取代价为O(1) ...

  8. java 核心技术卷一 知识点

    第九章 集合 1.Iterator和Iterable接口类,作用. 2.Collection接口类,作用. 3.Map接口类,作用.

  9. OCR光学字符识别--STN-OCR 测试

    1.同文章中建议的使用ubuntu-python隔离环境,真的很好用 参照:http://blog.topspeedsnail.com/archives/5618启动虚拟环境:source env/b ...

  10. Java for LeetCode 132 Palindrome Partitioning II

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...