zoukankan      html  css  js  c++  java
  • zoj 2818 Prairie dogs IV

    2818.   Prairie dogs IV
    Time Limit: 10.0 Seconds   Memory Limit: 65536K
    Total Runs: 205   Accepted Runs: 131



    Oh, my God! The lovely prairie dogs come again! We know they are very naughty and always play some funny games. This time, they play a game named Spiral Queue.

    Each of the prairie dogs has a number and they stand in a funny queue named Spiral Queue like in Figure 1.

    Given the coordinate, the direction of x-axis and y-axis is indicated in Figure 2. We suppose the coordinate of 1 is (0,0), then the coordinate of 2 is (1,0), the coordinate of 3 is (1,1) and the coordinate of 7 is (-1,-1).

    21   22  ...
    20   7   8   9  10
    19   6   1   2  11
    18   5   4   3  12
    17  16  15  14  13
    Figure1
    
    Find out the laws of the Spiral Queue.

    Your task is here: Given x and y (-1000 ≤ x,y ≤ 1000), the coordinate of a prairie dog, try to find out the number of the prairie dog.

    Input

    Each line of input will have two numbers x and y, indicating the coordinate of a prairie dog. The input stops when EOF (end of file) is reached.

    Output

    You must output the number of the prairie dog based on the coordinate (x,y), followed by a newline.

    Sample Input

    0 0
    -1 -1
    1 0
    1 1
    100 100
    1000 -1000
    

    Sample Output

    1
    7
    2
    3
    39801
    4004001
    

    Problem Setter: chhot@TJURocket

    Source: TJU Programming Contest 2007


    Submit   List    Runs   Forum   Statistics

    #include <iostream>
    #include 
    <string>
    #include 
    <cmath>
    #define MAX 11
    using namespace std;
    int n;
    string ch[MAX];
    int main()
    {
        
    int i,j;
        ch[
    0]="@";
        ch[
    1]="@ @";
        ch[
    2]="@ @   @ @";
        ch[
    3]="@ @   @ @         @ @   @ @";
        
    string str;
        
    for(i=4;i<=10;i++)
        {
            str
    ="";
            
    for(j=0;j<(int)(pow(3.0,i-1));j++)
                str
    +=" ";
            ch[i]
    =ch[i-1]+str;
            ch[i]
    +=ch[i-1];
        }
        
    while(scanf("%d",&n)!=EOF)
        {
            cout
    <<ch[n]<<endl;
        }
        
    return 0;
    }
  • 相关阅读:
    css-断网图片加载失败,图片表情与文字对齐
    工作中遇到一些不会写的样式
    基础知识题目
    前端基础知识html css
    js match
    jquery.extend()与jquery.fn.extend()的区别
    js apply 与 call
    jdk安装
    js数组操作各种方法
    js获取日期
  • 原文地址:https://www.cnblogs.com/forever4444/p/1457039.html
Copyright © 2011-2022 走看看