|-牛式-|

题目描述

下面是一个乘法竖式,如果用我们给定的那几个数字来取代 * ,可以使式子成立的话,我们就叫这个式子牛式。

  * * * 
x   * * 
------- 
  * * * 
* * * 
------- 
* * * * 

数字只能取代 * ,当然第一位不能为 0 。

写一个程序找出所有的牛式。

输入格式

第一行一个整数 N ,代表数字的个数。

第二行 : N 个用空格分开的数字 ( 每个数字都 ∈ { 1,2,3,4,5,6,7,8,9 } )。

输出格式

一个数字。表示牛式的总数。

样例

输入数据 1

5
2 3 4 6 8

输出数据 1

1

样例解释

下面是样例的那个牛式:

      2 2 2
    x   2 2
     ------
      4 4 4
    4 4 4
  ---------
    4 8 8 4

这题看似很复杂,实则一点也不简单难,只需枚举竖式上面的五个数(第一第二行),再进行判断即可。直接枚举,最多需要9^5次,肯定不会超时。

AC代码

#include<bits/stdc++.h>
using namespace std;
bool flag[10];
int sum;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        int x;
        cin>>x;
        flag[x]=true;
    }
    for(register int i=1;i<=9;++i)
    {
        if(flag[i])
        {
            for(register int j=1;j<=9;++j)
            {
                if(flag[j])
                {
                    for(register int k=1;k<=9;k++)
                    {
                        if(flag[k])
                        {
                            for(register int m=1;m<=9;m++)
                            {
                                if(flag[m])
                                {
                                    for(register int n=1;n<=9;n++)
                                    {
                                        if(flag[n])
                                        {
                                            bool p=true;
                                            int s1=i*100+j*10+k,s2=m*10+n;
                                            int temp=s1*m;//判断第三行数字 
                                            while(temp>0)
                                            {
                                                if(temp>999)
                                                {
                                                    p=false;
                                                    break;
                                                }
                                                int x=temp%10;
                                                if(!flag[x])
                                                {
                                                    p=false;
                                                    break;
                                                }
                                                temp/=10;
                                            }
                                            if(!p)continue;
                                            temp=s1*n;//判断第四行数字 
                                            while(temp>0)
                                            {
                                                if(temp>999)
                                                {
                                                    p=false;
                                                    break;
                                                }
                                                int x=temp%10;
                                                if(!flag[x])
                                                {
                                                    p=false;
                                                    break;
                                                }
                                                temp/=10;
                                            }
                                            if(!p)continue;
                                            temp=s1*s2;//判断最后一行数字 
                                            while(temp>0)
                                            {
                                                if(temp>9999)
                                                {
                                                    p=false;
                                                    break;
                                                }
                                                int x=temp%10;
                                                if(!flag[x])
                                                {
                                                    p=false;
                                                    break;
                                                }
                                                temp/=10;
                                            }
                                            if(!p)continue;
                                            sum++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    printf("%d",sum);
    return 0;
}

好啦,今天就讲到这里,拜拜!

import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from datetime import datetime import re # 解析表格数据 data = [] rows = [line for line in """ | A | B | C | D | E | F | G | H | I | J | K | L | |:----|:-----|:-----|:----------|:---|:-----|:-----|:-----|:----|:----|:----|:-----| | 关键词 | 博主名称 | 笔记类型 | 视频链接/首图链接 | 标题 | 正文内容 | 发布时间 | 发布地址 | 点赞数 | 收藏数 | 评论数 | 笔记链接 | | 饿了么 | 天天巨省钱 | 图文 | http://sns-webpic-qc.xhscdn.com/202505281033/6b87661da21eb78006f3e63eb2f9efa3/notes_pre_post/1040g3k031i0pbqgh6s0g5o9a0650bnh68jtoghg!nd_dft_wlteh_webp_3 | 简直了…饿了么啊!!! | 简直了…饿了么啊!!!<br>为什么不给我18-18?为什么不给我18-18?为什么不给我18-18?@饿了么福利社 @饿了么 @饿了么大蓝 @淘宝 @万能的淘宝 卸载你卸载你[生气R][生气R] @淘宝攻略[微笑R][微笑R]<br> <br>elm对用户数据有点过度了吧<br>开始蕞新大水18-18攻略教程⬇️<br>记住!一定要在逃饱的e了么([九R][六R][六R][八R][八R])<br>#不要太离谱 #还有人不知道 #饿了么 #家人们谁懂啊 #真让我大开眼界了 #想告诉全世界 #商战 #饿了么外卖 #省钱小妙招 #外卖 | 2025-05-28 09:10:26 | 北京 | 0 | 0 | 2 | https://www.xiaohongshu.com/search_result/68366281000000002300da99?xsec_token=ABlLblC0_WVPQdbtDz3EuvP8lnYYegM-Kt8NS7gF-GqIw=&xsec_source= | ...(完整数据)... """.split('\n') if line.strip()] # 提取列名 headers = [col.strip() for col in rows[1].split('|')[1:-1]] # 解析数据行 for row in rows[3:]: if not row.startswith('|'): continue cols = [re.sub(r'<br>|\s+', ' ', col.strip()) for col in row.split('|')[1:-1]] if len(cols) == len(headers): data.append(cols) # 创建DataFrame df = pd.DataFrame(data, columns=headers) # 转换数据类型 df['发布时间'] = pd.to_datetime(df['发布时间']) df['点赞数'] = pd.to_numeric(df['点赞数']) df['收藏数'] = pd.to_numeric(df['收藏数']) df['评论数'] = pd.to_numeric(df['评论数']) # 筛选日期范围 start_date = '2025-04-30' end_date = '2025-05-13' filtered_df = df[(df['发布时间'] >= start_date) & (df['发布时间'] <= end_date)] print(f"筛选后数据量: {len(filtered_df)}条") # 数据分析与可视化 plt.figure(figsize=(15, 12)) plt.suptitle(f'饿了么笔记数据分析 ({start_date}至{end_date})', fontsize=16) # 1. 笔记类型分布 plt.subplot(221) note_type = filtered_df['笔记类型'].value_counts() note_type.plot.pie(autopct='%1.1f%%', startangle=90) plt.title('笔记类型分布') plt.ylabel('') # 2. 热门发布地区TOP10 plt.subplot(222) top_locations = filtered_df['发布地址'].value_counts().head(10) sns.barplot(x=top_locations.values, y=top_locations.index, palette='viridis') plt.title('发布地区TOP10') plt.xlabel('数量') # 3. 每日发布趋势 plt.subplot(223) daily_count = filtered_df.set_index('发布时间').resample('D').size() daily_count.plot(marker='o') plt.title('每日发布数量趋势') plt.xlabel('日期') plt.ylabel('发布量') plt.grid(True) # 4. 互动量分析 plt.subplot(224) interaction = filtered_df[['点赞数', '收藏数', '评论数']].mean() sns.barplot(x=interaction.values, y=interaction.index, palette='Set2') plt.title('平均互动量对比') plt.xlabel('数量') plt.tight_layout(rect=[0, 0, 1, 0.96]) plt.savefig('eleme_data_analysis.png', dpi=300) plt.show() # 生成分析报告 report = f""" 数据分析报告 ({start_date}至{end_date}) ==================================== 1. 数据概况: - 总笔记数量: {len(filtered_df)}条 - 时间范围: {filtered_df['发布时间'].min().strftime('%Y-%m-%d')} 至 {filtered_df['发布时间'].max().strftime('%Y-%m-%d')} 2. 内容特征: - 笔记类型分布: 图文: {note_type.get('图文', 0)}条 ({note_type.get('图文', 0)/len(filtered_df):.1%}) 视频: {note_type.get('视频', 0)}条 ({note_type.get('视频', 0)/len(filtered_df):.1%}) - 热门地区: {top_locations.idxmax()} ({top_locations.max()}条) 3. 互动分析: - 平均点赞: {interaction['点赞数']:.1f} - 平均收藏: {interaction['收藏数']:.1f} - 平均评论: {interaction['评论数']:.1f} 4. 时间趋势: - 发布高峰日: {daily_count.idxmax().strftime('%Y-%m-%d')} ({daily_count.max()}条) """ print(report) 将这段代码中的# 解析表格数据 data = [] rows = [line for line in """ | A | B | C | D | E | F | G | H | I | J | K | L | |:----|:-----|:-----|:----------|:---|:-----|:-----|:-----|:----|:----|:----|:-----| | 关键词 | 博主名称 | 笔记类型 | 视频链接/首图链接 | 标题 | 正文内容 | 发布时间 | 发布地址 | 点赞数 | 收藏数 | 评论数 | 笔记链接 | | 饿了么 | 天天巨省钱 | 图文 | http://sns-webpic-qc.xhscdn.com/202505281033/6b87661da21eb78006f3e63eb2f9efa3/notes_pre_post/1040g3k031i0pbqgh6s0g5o9a0650bnh68jtoghg!nd_dft_wlteh_webp_3 | 简直了…饿了么啊!!! | 简直了…饿了么啊!!!<br>为什么不给我18-18?为什么不给我18-18?为什么不给我18-18?@饿了么福利社 @饿了么 @饿了么大蓝 @淘宝 @万能的淘宝 卸载你卸载你[生气R][生气R] @淘宝攻略[微笑R][微笑R]<br> <br>elm对用户数据有点过度了吧<br>开始蕞新大水18-18攻略教程⬇️<br>记住!一定要在逃饱的e了么([九R][六R][六R][八R][八R])<br>#不要太离谱 #还有人不知道 #饿了么 #家人们谁懂啊 #真让我大开眼界了 #想告诉全世界 #商战 #饿了么外卖 #省钱小妙招 #外卖 | 2025-05-28 09:10:26 | 北京 | 0 | 0 | 2 | https://www.xiaohongshu.com/search_result/68366281000000002300da99?xsec_token=ABlLblC0_WVPQdbtDz3EuvP8lnYYegM-Kt8NS7gF-GqIw=&xsec_source= | ...(完整数据)... """.split('\n') if line.strip()] 将这段内容改为# 直接从Excel文件读取数据 df = pd.read_excel('results(京东).xlsx', sheet_name='Sheet1') 并 增加数据清洗:检查缺失值,处理异常值。
最新发布
05-30
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值