蓝桥杯 第八届

来源:互联网 发布:unity3d游戏开发教程 编辑:程序博客网 时间:2024/06/03 15:30

第一题 购物单 

            思路:数学题

第七题 编程题   日期计算 

            思路:模拟

1#include <iostream>  2 22  #include<cstdio> 3    #include<stdlib.h> 4     5    const int maxn=100010; 6    using namespace std; 7     8    struct data 9    { 10    11     int year,month,day; 12    13   }date[maxn]; 14   int  judge(int year) 15   { 16       if(year%4==0&&year%100!=0||year%400!=0) 17       { 18           return 1; 19    20       } 21       return 0; 22   } 23   int main() { 24    25       int a,b,c; 26       scanf("%02d/%02d/%02d",&a,&b,&c); 27       int k=0; 28       for(int i=1960;i<=2059;i++) 29       { 30           if(b>12||c>31) 31           { 32               continue; 33           } 34           if(judge(i)) 35           { 36               if(b==2&&c>28) 37               { 38                   continue; 39               } 40           } 41           int t[2]; 42           t[0] = i / 10 % 10; 43           t[1] = i % 10; 44           if (t[0] * 10 + t[1] == a) 45           { 46               date[k].year = i; 47               date[k].month = b; 48               date[k].day = c; 49               k++; 50           } 51       } 52       for(int i=1960;i<=2059;i++) 53       { 54           if(judge(i)) 55           { 56               if(a==2&&b>28) 57               { 58                   continue; 59               } 60           } 61           int t[2]; 62           t[0]=i/10%10; 63           t[1]=i%10; 64    65           if(t[0]*10+t[1]==c) 66           { 67               date[k].year=i; 68               date[k].month=a; 69               date[k].day=b; 70               k++; 71           } 72       } 73       for(int i=1960;i<=2059;i++) 74       { 75           if(judge(i)) 76           { 77               if(a>28&&b==2) 78               { 79                   continue; 80               } 81           } 82           int t[2]; 83           t[0]=i/10%10; 84           t[1]=i%10; 85           if(t[0]*10+t[1]==c) 86           { 87               date[k].year=i; 88               date[k].month=b; 89               date[k].day=a; 90               k++; 91    92           } 93       } 94       int ans=k; 95       for(int i=0;i<k;i++) 96       { 97           for(int j=i+1;j<k;j++) 98           { 99    100              if(date[i].year==0&&date[i].month==0&&date[i].day==0) 101              { 102                  continue; 103              } 104              if(date[i].month==date[j].month&&date[i].year==date[j].year&&date[i].day==date[j].day) 105   106              { 107                  ans=ans-1; 108                  date[j].year=0; 109                  date[j].month=0; 110                  date[j].day=0; 111              } 112          } 113      } 114   115   116      for(int i=0;i<ans;i++) 117      { 118          for(int j=i;j<ans;j++) 119          { 120   121              if(date[i].year>date[j].year||(date[i].year==date[j].year&&date[i].month>date[j].month)||(date[i].year==date[j].year&&date[i].month==date[j].month&&date[i].day>date[j].day)) 122              { 123                  data temp; 124                  temp=date[j]; 125                  date[j]=date[i]; 126                  date[i]=temp; 127              } 128          } 129      } 130   131      for(int i=0;i<ans;i++) 132      { 133          if(date[i].year!=0&&date[i].month!=0&&date[i].day!=0) 134          cout<<date[i].year<<"-"<<date[i].month<<"-"<<date[i].day<<endl; 135      } 136   137   138      return 0; 139  }


第4题:  

标题:方格分割6x6的方格,沿着格子的边线剪开成两部分。要求这两部分的形状完全相同。如图:p1.png, p2.png, p3.png 就是可行的分割法。试计算:包括这3种分法在内,一共有多少种不同的分割方法。注意:旋转对称的属于同一种分割法。请提交该整数,不要填写任何多余的内容或说明文字。


这里写图片描述这里写图片描述这里写图片描述


#include <algorithm>#include <string.h>#include <iostream>#include <stdio.h>#include <string>#include <vector>#include <queue>#include <map>#include <set>using namespace std;const int N = 6;int ans = 0;int mpt[N+1][N+1];int dir[4][2] = {0,1,1,0,0,-1,-1,0};void dfs(int x,int y){    if(x == 0 || y == 0 || x == N || y == N){        ans ++;        return;    }    for(int i = 0 ; i < 4 ; i ++)    {        int tx = x + dir[i][0];        int ty = y + dir[i][1];        if(mpt[tx][ty])continue;        mpt[tx][ty] = 1;        mpt[N-tx][N-ty] = 1;        dfs(tx,ty);        mpt[tx][ty] = 0;        mpt[N-tx][N-ty] = 0;    }}int main() {    mpt[N / 2][N / 2] = 1;    dfs(N / 2, N / 2);    cout<<ans/4<<endl;        return 0;}
第8题  包子凑数
小明几乎每天早晨都会在一家包子铺吃早餐。他发现这家包子铺有N种蒸笼,其中第i种蒸笼恰好能放Ai个包子。每种蒸笼都有非常多笼,可以认为是无限笼。每当有顾客想买X个包子,卖包子的大叔就会迅速选出若干笼包子来,使得这若干笼中恰好一共有X个包子。比如一共有3种蒸笼,分别能放3、4和5个包子。当顾客想买11个包子时,大叔就会选2笼3个的再加1笼5个的(也可能选出1笼3个的再加2笼4个的)。当然有时包子大叔无论如何也凑不出顾客想买的数量。比如一共有3种蒸笼,分别能放4、5和6个包子。而顾客想买7个包子时,大叔就凑不出来了。小明想知道一共有多少种数目是包子大叔凑不出来的。输入----第一行包含一个整数N。(1 <= N <= 100)以下N行每行包含一个整数Ai。(1 <= Ai <= 100)  输出----一个整数代表答案。如果凑不出的数目有无限多个,输出INF。例如,输入:2  4  5   程序应该输出:6  再例如,输入:2  4  6    程序应该输出:INF样例解释:对于样例1,凑不出的数目包括:1, 2, 3, 6, 7, 11。  对于样例2,所有奇数都凑不出来,所以有无限多个。  资源约定:峰值内存消耗(含虚拟机) < 256MCPU消耗  < 1000ms请严格按要求输出,不要画蛇添足地打印类似:“请您输入...” 的多余内容。注意:main函数需要返回0;只使用ANSI C/ANSI C++ 标准;不要调用依赖于编译环境或操作系统的特殊函数。所有依赖的函数必须明确地在源文件中 #include <xxx>不能通过工程设置而省略常用头文件。提交程序时,注意选择所期望的语言类型和编译器类型。
#include <iostream>#include<string.h>#include<vector>using namespace std;int gcd(int a,int b){    if(b==0)    {        return a;    }    return gcd(b,a%b);}int arr[110],n;const int N=10010;bool bk[N];int main() {    cin>>n;    for(int i=0;i<n;i++)    {        cin>>arr[i];    }    int g=arr[0];    for(int i=1;i<n;i++)    {        g=gcd(g,arr[i]);    }    if(g!=1)    {        cout<<"INF"<<endl;    }    else    {        bk[0]=true;        for(int i=0;i<n;i++)        {            for(int j=0;j+arr[i]<N;j++)            {                if(bk[j])                {                    bk[j+arr[i]]=true;                }            }        }        int ans=0;        for(int i=N-1;i>=0;i--)        {            if(bk[i]==false)            {                ans++;            }        }        cout<<ans<<endl;    }    return 0;}








0 0
原创粉丝点击