POJ 2265 Bee Maja (找規律)

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   ar   2014   

題目連結

題意 : 給你兩個蜂巢的編號,給你一個的編號讓你輸出在另外一個蜂巢中對應的編號。

思路 : 先將蜂巢分層,第一層一個數,第二層6個數,第三層12個數…………然後用公式表示出第n層的最後一個數是多少,中豎著的是x座標,斜著的是y座標,往左橫座標+1,往右橫座標-1,以斜線為準往上縱座標-1,往下縱座標+1,(1,1)也就是18是第三圈的第一個數,(2,1)也就是20是第四圈的第一個數。

 

 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <cstdlib> 5  6 using namespace std ; 7  8 int main() 9 {10     int a ;11     while(scanf("%d",&a) !=EOF)12     {13         if(a == 1)14         {15             printf("0 0\n") ;16             continue ;17         }18         int n = 0;19         while(3 * (n-1) * n + 1 < a)//3 * (n-1) * n + 1表示第n圈的最後一個數是多少20             n++;//找到該數屬於第幾圈21         n--;22         a -= 3*(n-1)*n+1;23         int x , y;24         //分為6個邊,每個邊上n個數,可以根據題目裡的兩個圖找找規律,看看每條邊上的xy的規律是多少25         if(a<=n)26         {27             x = n-a;28             y = a;29         }30         else if(a>n&&a<=2*n)31         {32             x = n-a;33             y = n;34         }35         else if(a>2*n&&a<=3*n)36         {37             x = -n;38             y = 3*n-a;39         }40         else if(a>3*n&&a<=4*n)41         {42             x = a-4*n;43             y = 3*n-a;44         }45         else if(a>4*n&&a<=5*n)46         {47             x = a-4*n;48             y = -n;49         }50         else51         {52             x = n;53             y = a-6*n;54         }55         printf("%d %d\n",x,y) ;56     }57     return 0 ;58 }
View Code

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.