CF L. Rolling Cube

题目:CF L. Rolling Cube



tag:模拟

#include <cstring>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define maxn 100010
int b[7];
struct Cube
{
    int a[7];
    void right()
    {
        memcpy(b,a,sizeof(a));
        a[1]=b[1];
        a[5]=b[5];
        a[2]=b[4];
        a[3]=b[2];
        a[4]=b[6];
        a[6]=b[3];
    }
    void left()
    {
        memcpy(b,a,sizeof(a));
        a[1]=b[1];
        a[5]=b[5];
        a[2]=b[3];
        a[6]=b[4];
        a[4]=b[2];
        a[3]=b[6];
    }
    void down()
    {
        memcpy(b,a,sizeof(a));
        a[3]=b[3];
        a[4]=b[4];
        a[1]=b[2];
        a[2]=b[5];
        a[5]=b[6];
        a[6]=b[1];
    }
    long long get()
    {
        return a[2];
    }
    long long row()
    {
        return a[2]+a[4]+a[6]+a[3];
    }
    void Print()
    {
        cout<<a[2]<<":"<<a[4]<<":"<<a[6]<<":"<<a[3]<<endl;
        cout<<endl;
    }
}cube;
int main()
{
    int r,c;
    while(scanf("%d%d",&r,&c)!=EOF)
    {
        cube.a[6]=6;
        cube.a[2]=1;
        cube.a[3]=3;
        cube.a[4]=4;
        cube.a[5]=5;
        cube.a[1]=2;
        long long ans=1;
        int tmp=(c-1)%4;
        bool ok=1;
        for(int i=1;i<=r;i++)
        {
            //cout<<i<<":"<<ans<<endl;
            ans+=(c-1)/4*cube.row();
            if(ok)
            {
                for(int j=1;j<=tmp;j++)
                {
                    cube.right();
                    //cout<<cube.get()<<endl;
                    ans+=cube.get();
                }
                ok=0;
            }
            else
            {
                for(int j=1;j<=tmp;j++)
                {
                    cube.left();
                    //cout<<cube.get()<<endl;
                    ans+=cube.get();
                }
                ok=1;
            }
            if(i==r)
                break;
            cube.down();
            ans+=cube.get();
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值