zoukankan      html  css  js  c++  java
  • 第十届蓝桥杯B组省赛第D题

    试题 D: 数的分解 (40785

    【问题描述】 

    把 2019 分解成 3 个各不相同的正整数之和,并且要求每个正整数都不包 含数字 2 和 4,一共有多少种不同的分解方法? 

    注意交换 3 个整数的顺序被视为同一种方法,例如 1000+1001+18 和 1001+1000+18 被视为同一种。

    #include <stdio.h>

    int main(){

        int i,j,k;

        int ii,jj,kk;

        int cc=1,z,temp=0;

        for(i=1;i<2019;i++)

        {

            for(j=i+1;j<2019;j++)

            {

                for(k=j+1;k<2019;k++)

                {

                    if(i+k+j==2019){

                        ii=i;jj=j;kk=k;cc=1;

                        while(ii){

                            z=ii%10;

                            if(z==2&&ii!=0){

                                cc=0;break;

                            }

                            if(z==4&&ii!=0){

                                cc=0;break;

                            }

                            ii=ii/10;

                        }

                        while(jj){

                            z=jj%10;

                            if(z==2&&jj!=0){

                                cc=0;break;

                            }

                            if(z==4&&jj!=0){

                                cc=0;break;

                            }

                            jj=jj/10;

                        }

                        while(kk){

                            z=kk%10;

                            if(z==2&&kk!=0){

                                cc=0;break;

                            }

                            if(z==4&&kk!=0){

                                cc=0;break;

                            }

                            kk=kk/10;

                        }

                        if(cc) temp++;

                    }

                }

            }

        }

        printf("%d",temp);          //40785

    }

    欢迎来我们oj刷题 oj地址:http://www.npumdacm.top/
  • 相关阅读:
    lunix查询jdk安装路径
    (四)爬虫之动态网页
    (二)爬虫之数据提取
    图及其衍生算法(Graphs and graph algorithms)
    树及其衍生算法(Trees and tree algorithms)
    数据结构之链表(Linked list)
    查找与排序算法(Searching adn Sorting)
    数据结构之双端队列(Deque)
    数据结构之队列(Queue)
    多个git账号的SSH配置
  • 原文地址:https://www.cnblogs.com/tlysMoodspace/p/11856611.html
Copyright © 2011-2022 走看看