• NOIP模拟:饼干(简单规律推导)


    题目描述

    小美有一张很大的网格:2 n * 2 n 。
    每次小美会选一个小矩阵 2 x * 2 x , x > 0,小矩阵不能超过网格的边
    界。然后把右上一半都放上饼干。
    下图是当 x=1或2 的时候:


    每个格子不能放 2 个饼干。
    问最少能空几个格子不放饼干.

     

     

    输入格式

    从文件 cookies.in 中读入数据。
    第一行一个整数 n。

    输出格式

    输出到文件 cookies.out 中。
    一行一个答案。如果答案太大了,就模 10 6 + 3。

    样例输入

    3

    样例输出
      9
      数据规模
      对于 100% 的数据 1 ≤ n ≤ 1000

    题目分析

      简单画图分析可知答案为3n - 1,预处理就好。

    CODE

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<cmath>
    #include<vector>
    #include<map>
    using namespace std;
    
    const int MOD = 1e6 + 3;
    int n;
    int pow3[1050];
    
    inline int read(){
        int i = 0, f = 1; char ch = getchar();
        for(; (ch < '0' || ch > '9') && ch != '-'; ch = getchar());
        if(ch == '-') f = -1, ch = getchar();
        for(; ch >='0' && ch <= '9'; ch = getchar())
            i = (i << 3) + (i << 1) + (ch - '0');
        return i * f;
    }
    
    inline void init(){
        pow3[0] = 1;
        for(int i = 1; i <= 1050; i++)
            pow3[i] = (pow3[i - 1] * 3) % MOD;
    }
    
    int main(){
        //freopen("cookies.in", "r", stdin);
        //freopen("cookies.out", "w", stdout);
        n = read();
        init();
        cout<<pow3[n - 1];
        return 0;
    }
  • 相关阅读:
    元祖操作
    列表操作
    字符串操作
    zabbix监控脚本
    nginx 使用php-fpm的配置php环境参数
    网卡切换脚本
    mysql数据备份脚本
    docker概念
    网络链路质量监控smokeping
    搭建speedtest
  • 原文地址:https://www.cnblogs.com/CzYoL/p/7152509.html
Copyright © 2020-2023  润新知