UVA 10182 - Bee Maja
来源:互联网 发布:闪凌网络是真的吗 编辑:程序博客网 时间:2024/05/17 07:57
这道题如果只看左边那个图的话就会发现竖着的每一列纵坐标相同,而向左下方斜着的每一列纵坐标相同,但是这样并不能找出这些点的关系,就陷入了一个思维的误区,其实换个角度,如果把左边的坐标在直角坐标系上画出来,就比较容易看出这是一个很有规律的一个图,只需要 横 纵 坐标的加 减 就好了,至于加减多少那就看这个数所在的层数,层数是比较容易求出来的,因为中间是1个,下一圈是12,再下一圈18,除了中间那一个,其余每层增加了6个,然后根据坐标系便很容易看出每层需要加减多少;
code:
#include<stdio.h>
int find(int n)
{
int begin=2,end=8,num=2,x=0,y=1;
int cnt,i,j;
if(n==1)
{
printf(\"0 0\\n\");
return 1;
}
for(i=2; i<200; i++)
{
if(n>=begin&&n<=end)
{
cnt=i;
break;
}
else
{
begin = end;
end = end+6*i;
}
}
for(i=1; i<cnt; i++)
{
for(j=0; j<i; j++)
{
if(num==n)
{
printf(\"%d %d\\n\",x,y);
return 1;
}
else
x--;
num++;
}
for(j=0; j<i; j++)
{
if(num==n)
{
printf(\"%d %d\\n\",x,y);
return 1;
}
else
y--;
num++;
}
for(j=0; j<i; j++)
{
if(num==n)
{
printf(\"%d %d\\n\",x,y);
return 1;
}
else
{
x++;
y--;
}
num++;
}
for(j=0; j<i; j++)
{
if(num==n)
{
printf(\"%d %d\\n\",x,y);
return 1;
}
else
x++;
num++;
}
for(j=0; j<i; j++)
{
if(num==n)
{
printf(\"%d %d\\n\",x,y);
return 1;
}
else
y=y+1;
num++;
}
if(num==n)
{
printf(\"%d %d\\n\",x,y);
return 1;
}
else
y++;
num++;
for(j=0; j<i; j++)
{
if(num==n)
{
printf(\"%d %d\\n\",x,y);
return 1;
}
else
{
x--;
y++;
}
num++;
}
}
}
int main()
{
int n;
while(scanf(\"%d\",&n)!=EOF)
find(n);
return 0;
}
- UVA 10182 - Bee Maja
- UVa Problem 10182 Bee Maja (蜜蜂 Maja)
- UVa 10182 Bee Maja (规律&O(1)算法)
- programming-challenges Bee Maja (111204) 题解
- poj 2265 Bee Maja 模拟计数
- UVa, 11000 Bee
- UVA 11000 - Bee
- UVa 1531 - Problem Bee
- UVa 11000 - Bee
- UVa 11000 - Bee
- UVA, 11000 Bee
- Bee Breeding UVA
- UVA-11000 Bee-蜜蜂繁殖
- UVA 808(p342)----Bee Breeding
- bee
- bee
- Bee
- UVA 808 - Bee Breeding(数论+坐标系)
- UVA 10491-Cows and Cars
- UVA 10706 - Number Sequence
- UVA 10375 - Choose and divide
- UVA 10161-Ant on a Chessboard
- UVA 10177 - (234)-D SqrRectsCubesBoxes
- UVA 10182 - Bee Maja
- UVA 10195 - The Knights Of The Round Table
- UVA 10209 - Is This Integration
- UVA 10215 - The LargestSmallest Box ...
- UVA 10310 - Dog and Gopher
- UVA 439 - Knight Moves
- POJ 1979 - Red and Black
- POJ 3126 - Prime Path
- POJ 3278 - Catch That Cow