首页 > 编程语言 >UVa 10182 Bee Maja (规律&O(1)算法)

UVa 10182 Bee Maja (规律&O(1)算法)

时间:2023-04-14 10:31:43浏览次数:45  
标签:honey comb 10182 Maja hive Bee Willi bee


10182 - Bee Maja

Time limit: 3.000 seconds 

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1123

Maja is a bee. She lives in a bee hive with thousands of other bees. This bee hive consists of many hexagonal honey combs where the honey is stored in.
But bee Maja has a problem. Willi told her where she can meet him, but because Willi is a male drone and Maja is a female worker they have different coordinate systems.


Maja's Coordinate System

Willi's Coordinate System

Maja who often flies directly to a special honey comb has laid an advanced two dimensional grid over the whole hive.

Willi who is more lazy and often walks around just numbered the cells clockwise starting from 1 in the middle of the hive.




Help Maja to convert Willi's system to hers. Write a program which for a given honey comb number gives the coordinates in Maja's system.

Input Specification

The input file contains one or more integers which represent Willi's numbers. Each number stands on its own in a separate line, directly followed by a newline. The honey comb numbers are all less than 100 000.


Output Specification

You should output the corresponding Maja coordinates to Willi's numbers, each coordinate pair on a separate line.

Sample Input


1 2 3 4 5


Sample Output


0 0 0 1 -1 1 -1 0 0 -1



O(1)复杂度的思路:这道题如果只看左边那个图的话就会发现竖着的每一列纵坐标相同,而向左下方斜着的每一列纵坐标相同。但是这样并不能找出这些点的关系,其实换个角度,如果把左边的坐标在直角坐标系上画出来,就比较容易看出这是一个很有规律的一个图,只需要横纵坐标的加减就好了,至于加减多少那就看这个数所在的层数,层数可以根据x轴上的坐标的通项求出。


完整代码:

/*0.015s*/

#include<cstdio>
#include<cmath>

int main()
{
	int n, m, i, j;
	while (~scanf("%d", &m))
	{
		if (m == 1)
		{
			puts("0 0");
			continue;
		}
		--m;
		n = ceil((sqrt(12 * m + 9) - 3) / 6);
		if (3 * n * (n + 1) == m) printf("%d %d\n", n, 0);///x轴为起点
		else
		{
			--n;///前一个n
			m -= 3 * n * (n + 1);
			if (m <= n + 1) printf("%d %d\n", n - m + 1, m);
			else if (m <= (n + 1) << 1)
			{
				m -= (n + 1);
				printf("%d %d\n", -m, n + 1);
			}
			else if (m <= 3 * (n + 1))
			{
				m -= (n + 1) << 1;
				printf("%d %d\n", -(n + 1), n + 1 - m);
			}
			else if (m <= (n + 1) << 2)
			{
				m -= 3 * (n + 1);
				printf("%d %d\n", -(n - m + 1), -m);
			}
			else if (m <= 5 * (n + 1))
			{
				m -= (n + 1) << 2;
				printf("%d %d\n", m, -(n + 1));
			}
			else if (m <= 6 * (n + 1))
			{
				m -= 5 * (n + 1);
				printf("%d %d\n", n + 1, -(n + 1 - m));
			}
		}
	}
	return 0;
}


标签:honey,comb,10182,Maja,hive,Bee,Willi,bee
From: https://blog.51cto.com/u_5535544/6189589

相关文章

  • 2022山东高职Zigbee点对点开发
    2022山东高职Zigbee点对点开发题目3、ZigBee设备功能开发使用两个蓝色ZigBee节点盒进行组网通讯,并分别命名为节点端和控制端。节点端上安装双联继电器模块并外接风扇、照明灯。根据任务要求完成功能开发。任务要求:在控制端点击SW1键后,板上的LED1灯实现间隔0.5秒亮......
  • debian-kali 安装beef-xss (启动状态为failed)
    文档来自大佬https://www.cnblogs.com/xiatian09/p/9791040.html本人仅是自己做个记录给自己看,不喜欢的看的×这个界面就可以了,勿喷废话少说先看图问题和图└─#beef-xss[-]YouareusingtheDefaultcredentials[-](Passwordmustbedifferentfrom"beef")[-]Pleas......
  • Python DeprecationWarning: executable_path has been deprecated, please pass in a
    借鉴https://blog.csdn.net/lly1122334/article/details/106217320https://blog.csdn.net/qq_57377057/article/details/128463296https://blog.csdn.net/tangya3158613488/article/details/106902110 将之前谷歌浏览器的105版本替换为110版本解决Python:DeprecationWar......
  • GO框架 - beego简介
    bee工具是一个为了协助快速开发beego项目而创建的项目,通过bee您可以很容易的进行beego项目的创建、热编译、开发、测试、和部署。简单化:RESTful支持、MVC模型,可以使用bee工具快速地开发应用,包括监控代码修改进行热编译、自动化测试代码以及自动化打包部署。智能化:支......
  • (转)go语言web开发22 - beego框架之logs包使用
    原文:https://www.cnblogs.com/hei-ma/articles/13791609.htmlbeego框架的logs包是一个用来处理日志的库,目前支持的引擎有file(输出日志到文件)、console(终端输出)、net(输出到网络地址)、smtp(发送邮件)。 一、beego自带的日志功能(了解即可)beego有自带的日志功能(了解即可,即将被弃用......
  • 06-信道、互斥锁、异常处理、Gin框架beego的使用
    1goroutine协程//1并发和并行并发:同一时间段内,多个任务在执行(单个cpu,执行多个任务)并行:同一时刻,多个任务在执行(多个cpu的支持)//注:编程语言中,因为Python有GIL全局解释器锁,导致同一时刻,同一个进程中只能运行一个线程===>延伸出开启多进程,解决利用上多核优......
  • 无线短距通信技术标准:WIFI,蓝牙,ZigBee
    目前国际物联网最常用的无线通信技术标准主要有三种:WiFi、Zigbee和蓝牙。......
  • (转) beego中URL反转使用
    原文:https://www.cnblogs.com/hei-ma/articles/13626245.html什么是URL反转:根据“URL路径对应的处理函数“来获取到对应”URL方法“就是URL反转。 URL反转的好处:url改变不需要跟着改代码。 URL反转使用示例1、本示例的路由规则如下beego.Router("/login",......
  • Beego查数据库数据panic问题
    一开始没发现问题所在,请了位大佬帮忙排查错误逐步确定问题所在。问题起源于我查数据库没有得到正确的数据开始。一开始发现是数据类型问题,改过之后还是存在问题,于是debug一下,一步一步看问题出在哪里,结果走进了锁,就没仔细看,哪知在这中间出现了一个panic问题。但是这个panic没有打......
  • BEEM012 R语言代码解析
    BEEM012–EmpiricalAssignmentBriefAssignmentOverviewThegoalofthisassignmentistousethetoolsyouhavelearnedsofarinyourRassignmentsandapply......