仙人球的残影

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. iOS对象(数组)转化为JSon字符串

    - (void)seabc { NSArray *arry=[NSArray arrayWithObjects:@"0081",@"0082",@"0 ...

  2. Fragment 生命周期:

    Fragment每个生命周期方法的意义.作用(注意红色的不是生命周期方法):setUserVisibleHint():设置Fragment可见或者不可见时会调用此方法.在该方法里面可以通过调用getU ...

  3. EasyNVR RTSP转RTMP-HLS流媒体服务器前端构建之:通过接口获取实时信息

    对于动态网站,要实时更新网站的信息,通过接口来获取实时信息是一个必不可少的部分.EasyNVR可以接入IPC等前端设备,必须要实时获取到对应的IPC实时信息进行展示. 本篇主要说明Ajax来获取数据. ...

  4. 九度OJ 1037:Powerful Calculator(强大的计算器) (大整数运算)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1821 解决:528 题目描述: Today, facing the rapid development of business, SJTU ...

  5. 性能测试--Jmeter随机生成/随机选取/csv读取关键字

    Jmeter随机生成/随机选取/csv读取关键字 一.随机生成关键字 随机生成关键字,需要组件:随机变量配置元件(Random Variable)  该组件的作用是生成字符+随机数字格式的字符串,并保 ...

  6. SAP数据表相关

    [转]SAP 数据表相关信息 今天用到了根据字段取数据元素描述,以前做过忘啦,在谢兄的帮助下搞定,把他的总结粘出来记住. 存储域(Domain)信息的表为DD01L:存储数据元素(Data Eleme ...

  7. JAVA使用相对路径读取配置文件

    JAVA使用相对路径读取配置文件[align=center][/align][size=medium][/size]   在软件开发中经常遇到读取配置文件,以及文件定位问题.今天做个总结.   (一) ...

  8. webpack为什么加载不了css?

    原文地址: https://segmentfault.com/q/1010000005099261 这个app是用react写的. webpack的loader设置是这样的 module:{ load ...

  9. c#使用itextsharp输出pdf(动态填充表单内容,显示中文)

    相关链接: iText的简单应用-字体 c#程序为PDF文件填写表单内容 示例代码: static void Main(string[] args) { BaseFont font = BaseFon ...

  10. oracle数据库如何备份一张表

    --用户名:tms--创建表ts_dictionary的备份create table ts_dictionary_20160715 as select * from ts_dictionary; 补充 ...