Google Map


Time Limit: 2 Seconds      Memory Limit: 65536 KB


GoogleMap is a useful tool and most of you should be familiar with it. As the best hacker in the world, Jack is planning to retrieve all the data on the GoogleMap server. But he soon gives up because the total amount of data exceeds 1000T bytes! But he has learnt the way in which Google stores their data on the server, and he turns to download only the parts that he's interested in. Here is the representation of the data that Jack has found:

First of all, you should know the basic background knowledge of GIS (Geography Information System). In GoogleMap, the whole world is represented in a whole flat image transformed from the surface of the earth by Mercator projection. The Mercator projection is a map projection which is widely used for navigation. The following equations place the x-axis of the projection on the equator (from West to East) and the y-axis at longitude 0 (from South to North)

  • x = longitude * pi / 180;
  • y = ln(tan(pi / 4 + (latitude * pi / 180) / 2))

Here, the latitude is between [-85, 85] (negative for South) and the longitude is between [-180, 180] (negative for West) The left of the map image is W180 and the right is E180. The top of the map image is N85 and the bottom is S85. The maps have different levels. In the first level, the whole image consists of only one tile with tag name "t". For each tile in one level, it will be clipped into 4 equally sized parts and magnified by 2 in the next level.

And the new tag name for the tiles in the next level will be the tag of their parent tile followed by the identifier of the clip area in the parent tile. (that is, q for left-top, r for right-top, t for left-bottom, s for right-bottom) For example:

 

So there will be 4L tiles in level L (Assume the first level is labeled as level 0). More interestingly, the filename of the tile on the server is just the tag name. Although Jack is very genius, he doesn't know any programming language, so he turns to you for writing a tool to generate the tags for him.

Input

The input contains multiple test cases!

In each case, there will be three numbers. The first two are the coordinates that indicate the longitude and latitude of the interested location, and the third is the level number required by Jack.

The longitude is between [-180, 180] (negative for West) and the latitude is between [-85, 85] (negative for South)

Output

Output the tag for the tile in the specified level that contains the location in a single line.

You can assume that the location will not be at the boundary of any tiles.

Sample Input

80 33 2
-80 -33 4
72.12 46.68 10

Sample Output

trt
ttrqt
trtrstqsrqs

Notes

You can use the 'log(double)' function to calculate the natural logarithm, and 'tan(double)' to calculate the tangent value. Both of these functions are included in the header '<math.h>' for C or '<cmath>' for C++.


Author: FAN, Xiang
Source: Zhejiang Provincial Programming Contest 2007

解题报告:这道题就是以一开始的图像为标准,一次缩小1/4,看一开始的位置在图像的四个部分的哪一个,依次类推即可;

代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
double PI = acos(-1);
//一下面作为一开始的标准
double N = log(tan(PI / 4.0 + (85.0 * PI / 180.0) / 2.0));//相当于把北纬85.0转化为图片的上边界
double S = log(tan(PI / 4.0 + (-85.0 * PI / 180.0) / 2.0));//相当于把南纬85.0转化为图片的下边界
double W = -PI;//相当于把西经180转化为图片的左边界
double E = PI;//相当于把东经转180化为图片的右边界
double n, s, w, e;//存储图像缩小时的边界
double longitude, latitude;//输入时的经纬度
int t;
void Judge(double p, double q)
{
if (p > (w + e) / 2.0)//在图像的右半部分
{
w = (w + e) / 2.0;
if (q > (n + s) / 2.0)//在图像的上半部分
{
s = (s + n) / 2.0;
printf("r");
}
else//在图像的下半部分
{
n = (n + s) / 2.0;
printf("s");
}
}
else//在图像的左半部分
{
e = (w + e) / 2.0;
if (q > (n + s) / 2.0)//在图像的上半部分
{
s = (s + n) / 2.0;
printf("q");
}
else//在图像的下半部分
{
n = (s + n) / 2.0;
printf("t");
}
}
}
int main()
{
int i;
while (scanf("%lf%lf%d", &longitude, &latitude, &t) != EOF)
{
n = N, s = S, w = W, e = E;
double p = (longitude * PI) / 180.0;//在图像的具体位置
double q = log(tan(PI / 4.0 + (latitude * PI / 180.0) / 2.0));//在图像的土体位置
printf("t");
for (i = 0; i < t; ++i)
{
Judge(p, q);
}
printf("\n");
}
return 0;
}



posted on 2012-04-01 20:58  Stephen Li  阅读(578)  评论(0编辑  收藏  举报