UVA10182: Bee Maja (模拟)

https://vjudge.net/problem/UVA-10182

 

题意分析:

题意很明显,有两个蜂巢的编号方式,给出右边的,求左边的编号。

解题思路:

图中可以看出来第1层有1个,第2层有6*1=6个,第3层有6*2=12个,......第n层有6*(n-1)个。

先找出在第几层然后模拟即可。

#include <stdio.h>
int px, py;
void f1()
{
	px--;
	py++;
}
void f2()
{
	px--;
}
void f3()
{
	py--;
} 
void f4()
{
	px++;
	py--;
}
void f5()
{
	px++;
}
void f6()
{
	py++;
}
int main()
{
	int n, sum, pw, t;
	while(scanf("%d", &n)!=EOF)
	{
		sum=0;pw=0;
		while(sum<n)
		{
			pw++;
			sum+=pw*6;		
		}
		
		sum-=pw*6;	
		n=n-sum;
		if(n==1)
			printf("%d 0
", pw-1);
		else{
			px=pw;
			py=0;
			n--;
			t=pw;
			while(n && t)
			{
				n--;t--;
				f1();
			}
				
			t=pw;
			while(n && t)
			{
				n--;t--;
				f2();
			}
				
			t=pw;
			while(n && t)
			{
				n--;t--;
				f3();
			}
				
			t=pw;
			while(n && t)
			{
				n--;t--;
				f4();
			}
				
			t=pw;
			while(n && t)
			{
				n--;t--;
				f5();
			}
				
			t=pw;
			while(n && t)
			{
				n--;t--;
				f6();
			}
				
			printf("%d %d
", px, py);
		}
	}
	return 0;
}
原文地址:https://www.cnblogs.com/zyq1758043090/p/11852607.html