Discuz! Board

 找回密码
 立即注册
查看: 196|回复: 1

老师怎么写

[复制链接]

9

主题

29

帖子

243万

积分

论坛元老

Rank: 8Rank: 8

积分
2438098

烈空座 Lv:100
发表于 2024-12-3 19:32:47 | 显示全部楼层 |阅读模式
#include<iostream>
#include<cstdio>
using namespace std;
const int mod=12345;
int num[1010][2];
int main()
{
    int n;
    num[1][0]=9;    num[1][1]=1;
    scanf("%d",&n);
    int x = num[1][0];
    for (int i=2; i<=n; ++i)
    {
        if (i==n)--x;
        num[i][0]=(num[i-1][0]*x+num[i-1][1])%mod;
        num[i][1]=(num[i-1][1]*x+num[i-1][0])%mod;
    }
    printf("%d\n", num[n][0]);
        return 0;
}
回复

使用道具 举报

660

主题

846

帖子

243万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2435557

烈空座 Lv:100
发表于 2024-12-4 13:08:36 | 显示全部楼层
网上找的吧
能看懂也行哦
#include<iostream>
#include<cstdio>
using namespace std;
const int mod=12345;
int num[1010][2];//二维数组num[i][j] 分别用来存储 i 位数时,含奇数个3的数的个数,含偶数个3的数的个数
int main()
{
    int n;
    num[1][0]=9;    num[1][1]=1;//1位数时,含偶数个3的数有9个,包括0,含奇数个3的数有1个
    scanf("%d",&n);
    int x = num[1][0];
    for (int i=2; i<=n; ++i)//循环类推
    {
        if (i==n)--x;//最后一次循环时,最高位不能为0,所以x=8
        num[i][0]=(num[i-1][0]*x+num[i-1][1])%mod;//两位数的偶数个3的数的个数=1位数的奇数3的个数*1+1位数的奇数3的个数*9
        num[i][1]=(num[i-1][1]*x+num[i-1][0])%mod;//两位数的奇数个3的数的个数=1位数的奇数3的个数*9+1位数的偶数3的个数*1
    }
    printf("%d\n", num[n][0]);
        return 0;
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|DiscuzX

GMT+8, 2025-5-29 05:25 , Processed in 0.054639 second(s), 34 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.. 技术支持 by 巅峰设计

快速回复 返回顶部 返回列表