Sicily 4874. POGODAK

来源:互联网 发布:七上生物行知天下答案 编辑:程序博客网 时间:2024/06/08 20:15

4874. POGODAK

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

Mirko doesn’t like Latin homeworks so he made a bet with Slavko. Loser will be writing homeworks for both of them the entire month. Mirko wants to win so he designed this problem they could have something to bet on.
At his desk he found a cube, with numbers 1 to 6 on its faces. Cube is shown on the picture. Additionally, sum of the numbers on opposing faces is equal to 7. That means that 6 is on the opposite face of 1, 5 on the opposite of 2 and 4 on the
opposite face of 3.

Mirko has put the cube in the upper left field of the matrix of R rows and C columns. The cube is initially oriented in a way that upper side is showing number 1, and side to the right number 3. Mirko now makes te following moves:
1. He is rolling the cube to the right, until it reaches the last column
2. Then he rolls it down (to the next row)
3. Now he rolls the cube to the left, until it reaches first column
4. Like in step 2, he rolls it down (to the next row)
Mirko is repeating these steps for as long as he can, i.e. as long as he can roll the cube in the next row. When a cube reaches some field, Mirko writes down the number on the top of the cube. In the end he sums all of the numbers he had written.
Mirko made a bet with Slavko that he could calculate that sum without error. Help Slavko verifying Mirko’s solution!
 

 

Input

First and only line of input contains two positive integers. R and C (1 ≤ R, C ≤ 100 000), matrix dimensions.

Output

First and only line of input should contain the sum described in the task.

Sample Input

sample input 1:3 2sample input 2:3 4sample input 3:737 296

Sample Output

sample output 1:19sample output 2:42sample output 3:763532

Hint

First sample description: numbers Mirko wrote down are:
1 4
1 5
3 5

Problem Source

CROATIAN OPEN COMPETITION IN INFORMATICS 2011.12

凶残模拟题

#include <stdio.h>struct cube {    int u;    int d;    int l;    int r;    int f;    int b;    cube(){};    cube(int uu, int dd, int ll, int rr, int ff, int bb) {        u = uu;        d = dd;        l = ll;        r = rr;        f = ff;        b = bb;    }};int main() {    int row, col;    cube c(1, 6, 4, 3, 5, 2);    cube next_c;    scanf("%d %d", &row, &col);    bool is_go_right = true;    long long int sum_all = 0;    for (int i = 0; i < row; i++) {                int sum_4 = c.l + c.r + c.u + c.d;        int sum_row = (col / 4) * sum_4;        if (col % 4 == 1) {            sum_row += c.u;            cube n_c(c.u, c.d, c.l, c.r, c.f, c.b);            next_c = n_c;        } else if (col % 4 == 2) {            if (is_go_right) {                sum_row += c.u + c.l;                cube n_c(c.l, c.r, c.d, c.u, c.f, c.b);                next_c = n_c;            } else {                sum_row += c.u + c.r;                cube n_c(c.r, c.l, c.u, c.d, c.f, c.b);                next_c = n_c;            }        } else if (col % 4 == 3) {            if (is_go_right) {                sum_row += c.u + c.l + c.d;                cube n_c(c.d, c.u, c.r, c.l, c.f, c.b);                next_c = n_c;            } else {                sum_row += c.u + c.r + c.d;                cube n_c(c.d, c.u, c.r, c.l, c.f, c.b);                next_c = n_c;            }        } else {            cube n_c(c.l, c.r, c.u, c.d, c.f, c.b);            next_c = n_c;        }                sum_all += sum_row;                c.u = next_c.f;        c.d = next_c.b;        c.l = next_c.l;        c.r = next_c.r;        c.f = next_c.d;        c.b = next_c.u;        is_go_right = !is_go_right;    }    printf("%lld\n", sum_all);    return 0;}


0 0
原创粉丝点击