【蓝桥杯第十四届省赛B】(部分详解)

【01串的熵】

https://www.lanqiao.cn/problems/3498/learning/?subject_code=1&group_code=4&match_num=14&match_flow=1&origin=cup

#include <iostream>
#include<cmath>
using namespace std;
int main()
{
     double n=23333333;
     double sum=0;
     for(int x=0;x<=n/2;x++)
     {
        sum=0;
        sum-=x*(x/n)*log2(x/n)+(n-x)*(n-x)/n*log2((n-x)/n);
        if(sum>11625907.5&&sum<11625907.6)
        {
        cout<<x;
        break;
        }
     }
		return 0;
}

填空题难度还行,没有考虑每次循环都要初始化sum为0(出来挨打)(小数记得double一下)

【日期统计】

https://www.lanqiao.cn/problems/3492/learning/?subject_code=1&group_code=4&match_num=14&match_flow=1&origin=cup

#include <iostream>
using namespace std;

int main()
{
    int array[100] = {
        5, 6, 8, 6, 9, 1, 6, 1, 2, 4, 9, 1, 9, 8, 2, 3, 6, 4, 7, 7,
        5, 9, 5, 0, 3, 8, 7, 5, 8, 1, 5, 8, 6, 1, 8, 3, 0, 3, 7, 9,
        2, 7, 0, 5, 8, 8, 5, 7, 0, 9, 9, 1, 9, 4, 4, 6, 8, 6, 3, 3,
        8, 5, 1, 6, 3, 4, 6, 7, 0, 7, 8, 2, 7, 6, 8, 9, 5, 6, 5, 6,
        1, 4, 0, 1, 0, 0, 9, 4, 8, 0, 9, 1, 2, 8, 5, 0, 2, 5, 3, 3
    };
    int count = 0;
    int monthday[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    //方便一一对照月份
    
    for (int month = 1; month <= 12; month++)
    {
        for (int day = 1; day <= monthday[month]; day++)
        {
            int k = 0;
            int date[8] = {2, 0, 2, 3, month / 10, month % 10, day / 10, day % 10};
           //0几的内种
            
            for (int i = 0; i < 100; i++)
            {
                if (array[i] == date[k])
                    k++;
                
                if (k == 8)
                {
                    count++;
                    break;
                }
            }
        }
    }
     cout << count;
    return 0;
}

很久之前写的了,今天又敲了一遍。先循环构造对照数组,再一一比对就o了(少了个日期,朕说怎么过不了,被自己蠢笑啦~(比心)爱笑的小女孩自从学算法之后更爱笑了)

【字串简写】

https://www.lanqiao.cn/problems/3514/learning/?subject_code=1&group_code=4&match_num=14&match_flow=1&origin=cup

#include <iostream>
#include<string>
using namespace std;
int main()
{
    int k;
    cin>>k;
    string s;
    char c1,c2;
    cin>>s>>c1>>c2; 
    long long cnt=0,res=0;
    for(int i=0,j=k-1;j<s.length();i++,j++)//
    {
        if(s[i]==c1)
        cnt++;
        if(s[j]==c2)
        res+=cnt;
    }
    cout << res;
    return 0;
}

LL 必须永远被坚定地选择,第一次做有个bug就是不能同时满足等于c1和c2,这样就只会筛选长度为4的串了,所以得先筛一个存着,碰到第二个就加一下

【冶炼金属】

#include <iostream>
#include<algorithm>
using namespace std;
using LL=long long;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
   // vo=x;
    LL n,a,b,x,y,vmin,vmax;
    cin>>n; 
   
    for(int i=1;i<=n;i++)
    {
     cin>>a>>b;   
     x=a/b;       
     y=a/(b+1)+1; 
     vmin=max(vmin,y);
     vmax=min(vmax,x);
	 }
    cout<<vmin<<" "<<vmax;
  return 0;
}

在这里插入图片描述

【飞机降落】

感觉难起来了

在这里插入代码片

【接龙数列】

线性dp

#include <iostream>
using namespace std;
using LL=long long;
const LL N=1e5+3;
int dp[10];
int main()
{
    int n;
    cin>>n;
    int ma=0;
    string s;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        int x=s[0]-'0';
        int y=s[s.size()-1]-'0';

        dp[y]=max(dp[x]+1,dp[y]);
        ma=max(ma,dp[y]);
      }
       cout<<n-ma;
 // 请在此输入您的代码
  return 0;

在这里插入图片描述

dp[y]=max(dp[x]+1,dp[y])
如果首位和前面存的末位相同的话说明可以形成接龙数列,在末位存储上++;如果不能就重新形成一个接龙数列
以第五个数据为例,以3开头以2结尾,3!=2,如果选择则重新开辟以3为首的存储,如果不选还是保持之前dp[2]的存储状态

相关推荐

  1. B】(部分详解

    2024-03-31 03:48:04       18 阅读
  2. C++B组题解

    2024-03-31 03:48:04       20 阅读
  3. 大学B组(C/C++)整数删除

    2024-03-31 03:48:04       21 阅读
  4. 大学B组填空题(c++)

    2024-03-31 03:48:04       15 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-31 03:48:04       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-31 03:48:04       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-31 03:48:04       20 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-31 03:48:04       20 阅读

热门阅读

  1. 代码随想录刷题day39|不同路径&不同路径II

    2024-03-31 03:48:04       20 阅读
  2. antdp | 解决问题tcp 8080 bind address already in use

    2024-03-31 03:48:04       18 阅读
  3. Android SystemUI关机和重启的UI

    2024-03-31 03:48:04       17 阅读
  4. ElasticSearch之优化篇

    2024-03-31 03:48:04       20 阅读
  5. 智慧工地整体解决方案(1)

    2024-03-31 03:48:04       22 阅读
  6. sort和priority_queue的自定义比较函数

    2024-03-31 03:48:04       22 阅读
  7. 智能合约测试例子

    2024-03-31 03:48:04       24 阅读
  8. vector快速入门

    2024-03-31 03:48:04       21 阅读
  9. 【MySQL】MySQL中SQL语句的索引分析

    2024-03-31 03:48:04       18 阅读
  10. QT5.14.2 码上热浪,用Qt5狂暴轰入多媒体狂潮

    2024-03-31 03:48:04       20 阅读