CF427 C star sky 二維數組首碼和

來源:互聯網
上載者:User

標籤:memset   blank   sky   logs   log   scanf   print   set   一個   

用pre[t][i][j]存時間等價於t時座標(1, 1) 和(i, j)組成的矩形地區的星星總亮度。再注意一下一個座標處可以有多顆星星就可以了。

 star sky

 1 // http://codeforces.com/contest/835/problem/C 2 #include <cstdio>  3 #include <cstring> 4 const int M = 12, N = 102; 5 int pre[M][N][N]; 6 int main() 7 { 8     int n, q, c; 9     while(~scanf("%d%d%d", &n, &q, &c)) {10         memset(pre, 0, sizeof pre);11         c++;12         int x, y, s;13         while(n--) {14             scanf("%d%d%d", &x, &y, &s);15             for (int i = 0; i < c; ++i)16                 pre[i][x][y] += (s + i) % c; //不易注意的地方,同一個座標可能有多顆小星星 17         }18         for (int t = 0; t < c; ++t) //時間t,求下二維首碼和 19             for (int i = 1; i <= 100; ++i)20                 for (int j = 1; j <= 100; ++j)21                     pre[t][i][j] += pre[t][i-1][j] + pre[t][i][j-1] - pre[t][i-1][j-1];22         int t, x1, y1, x2, y2;23         while(q--) {24             scanf("%d%d%d%d%d", &t, &x1, &y1, &x2, &y2);25             t %= c;26             int sum = pre[t][x2][y2] - pre[t][x1-1][y2] - pre[t][x2][y1-1] + pre[t][x1-1][y1-1];27             printf("%d\n", sum); 28         }29     }30     31     return 0;32 }

 

CF427 C star sky 二維數組首碼和

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.