HDOJ-2153
仙人球的残影
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6851 Accepted Submission(s): 3192Problem Description在美丽的HDU,有一名大三的同学,他的速度是众所周知的,跑100米仅仅用了2秒47,在他跑步过程中会留下残影的哎,大家很想知道他是谁了吧,他叫仙人球,既然名字这样了,于是他的思想是单一的,他总是喜欢从一点出发,经过3次转折(每次向右转90°),回到出发点,而且呢,他每次转折前总是跑相同长度的路程,所以很多人都想知道如果用‘1’算他跑步出发的第一个残影的话,那么回到起点的时候,他的残影是怎么样的呢?Input测试数据有多行,每一行为一个数N(1<=N<=10)(以0结尾,0不做处理),即仙人球在没有回到起点的时候,跑过留下N个残影后突然90°右转。Output每组测试数据输出一个结果,并且每个残影的计数位长度为3个字符长度。(当然N等于1的话,它的结果也是占用3个字符位置的)Sample Input4Sample Output1 2 3 412 5 11 610 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的更多相关文章
- HDOJ(HDU) 2153 仙人球的残影(谜一样的题、、、)
Problem Description 在美丽的HDU,有一名大三的同学,他的速度是众所周知的,跑100米仅仅用了2秒47,在他跑步过程中会留下残影的哎,大家很想知道他是谁了吧,他叫仙人球,既然名字这 ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1004 Let the Balloon Rise
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- hdoj 1385Minimum Transport Cost
卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...
- HDOJ(2056)&HDOJ(1086)
Rectangles HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...
- 继续node爬虫 — 百行代码自制自动AC机器人日解千题攻占HDOJ
前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机&quo ...
- 最近点对问题 POJ 3714 Raid && HDOJ 1007 Quoit Design
题意:有n个点,问其中某一对点的距离最小是多少 分析:分治法解决问题:先按照x坐标排序,求解(left, mid)和(mid+1, right)范围的最小值,然后类似区间合并,分离mid左右的点也求最 ...
- BFS(八数码) POJ 1077 || HDOJ 1043 Eight
题目传送门1 2 题意:从无序到有序移动的方案,即最后成1 2 3 4 5 6 7 8 0 分析:八数码经典问题.POJ是一次,HDOJ是多次.因为康托展开还不会,也写不了什么,HDOJ需要从最后的状 ...
随机推荐
- 仿易讯clientloading效果
以下来实现一个loading效果.详细效果例如以下: 首先对这个效果进行拆分,它由以下部分组成: 1 一个"闪电"样式的图案. 2 "闪电"图案背后是一个圆角矩 ...
- 【BZOJ4826】[Hnoi2017]影魔 单调栈+扫描线
[BZOJ4826][Hnoi2017]影魔 Description 影魔,奈文摩尔,据说有着一个诗人的灵魂.事实上,他吞噬的诗人灵魂早已成千上万.千百年来,他收集了各式各样的灵魂,包括诗人.牧师.帝 ...
- 限制线程数 Limit the number of threads started by colly 随机延迟
random delay | Colly http://go-colly.org/docs/examples/random_delay/
- pjax + tp5,实现局部无刷新返回数据
文件1:\application\admin\controller\Setting.php 最后一句代码:要fetch原页面 <?php namespace app\admin\controll ...
- 【题解】Sumdiv
[题解]Sumdiv 传送门 根据组合的乘法原理,一个数的所有约数和 \[ sum=\prod_{i=1} \Sigma_j^{a_i} p_i^j \] 所以任务就变成了分解\(A\)的质因数,分解 ...
- SPFA的两个优化:SLF与LLL
先举出个例题:洛谷P3371 [模板]单源最短路径 一眼扫去:最短路径. spfa不接受反驳... 附上代码: #include<iostream> #include<algorit ...
- Why use async requests instead of using a larger threadpool?(转载)
问: During the Techdays here in the Netherlands Steve Sanderson gave a presentation about C#5, ASP.NE ...
- Java基础教程:多线程基础(4)——Lock的使用
Java基础教程:多线程基础(4)——Lock的使用 快速开始 Java 5中Lock对象的也能实现同步的效果,而且在使用上更加方便. 本节重点的2个知识点是:ReentrantLock类的使用和Re ...
- html5/CSS3鼠标滑过图片特效插件
在线演示 本地下载
- GDB调试core文件(3)
列出一些常见问题: 一,如何使用core文件 使用core文件 在core文件所在目录下键入: gdb -c core 它会启动GNU的调试器,来调试core文件,并且会显示生成此core文件的程序名 ...