第十二届蓝桥杯省赛C/C++题解

 

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int s[10];
bool check(int n)
{
    while(n)
    {
        int m = n%10;
        n /= 10;
        if(--s[m]<0)
        {
            return false;
        }
    }
    return true;
}
int main()
{
    for (int i = 0; i < 10; i ++ )
    {
        s[i]=2021;
    }
    for (int i = 1; ; i ++ )
    {
        if(!check(i))
        {
            cout<<i-1<<endl;
            return 0;
        }
    }
    return 0;
}

 

#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 200000;
struct Line
{
    double k,b;
    bool operator< (const Line& L)const
    {
        if(k<L.k) return k<L.k;
        return b<L.b;
    }
}l[N];
int n;
int main()
{
    for(int x1=0;x1<20;x1++)
    {
        for(int y1=0;y1<21;y1++)
        {
            for(int x2=0;x2<20;x2++)
            {
                for(int y2=0;y2<21;y2++)
                {
                    if(x1!=x2)
                    {
                        double k = (double)(y2-y1)/(x2-x1);
                        double b = y1 -k*x1;
                        l[n++]={k,b};
                    }
                }
            }
        }
    }
    sort(l,l+n);
    int res = 1;
    for (int i = 1; i < n; i ++ )
    {
        if(fabs(l[i].b-l[i-1].b)>1e-8||fabs(l[i].k-l[i-1].k)>1e-8)
        {
            res++;
        }
    }
    cout<<res+20;
}

 

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
int main()
{
    LL n;
    cin>>n;
    vector<LL> d;
    for (LL i = 1; i*i < n; i ++ )
    {
        if(n%i==0)
        {
            d.push_back(i);
            if(n/i!=i)
            {
                d.push_back(n/i);
            }
        }
    }
    int res = 0;
    for(auto a:d)
        for(auto b:d)
            for(auto c:d)
                if(a*b*c==n)
                    res++;
    cout<<res<<endl;
    return 0;
}

 

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 2200,M=N*50;
int h[N], e[M], w[M], ne[M], idx;
int q[N], dist[N];
bool st[N];
int n;
void spfa()  // 求1号点到n号点的最短路距离
{
    int hh = 0, tt = 0;
    memset(dist, 0x3f, sizeof dist);
    dist[1] = 0;
    q[tt ++ ] = 1;
    st[1] = true;

    while (hh != tt)
    {
        int t = q[hh ++ ];
        if (hh == N) hh = 0;
        st[t] = false;
        
        for (int i = h[t]; i != -1; i = ne[i])
        {
            int j = e[i];
            if (dist[j] > dist[t] + w[i])
            {
                dist[j] = dist[t] + w[i];
                if (!st[j])     // 如果队列中已存在j,则不需要将j重复插入
                {
                    q[tt ++ ] = j;
                    if (tt == N) tt = 0;
                    st[j] = true;
                }
            }
        }
    }
}
int gcd(int a, int b)  // 欧几里得算法
{
    return b ? gcd(b, a % b) : a;
}
void add(int a, int b, int c)  // 添加一条边a->b,边权为c
{
    e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++ ;
}

int main()
{
    n  = 2021;
    memset(h, -1, sizeof h);
    for (int i = 1; i <= n; i ++ )
        for(int j = max(1,i-21);j<=min(1,i+21);j++)
        {
            int d = gcd(i,j);
            add(i,j,i*j/d);
        }
    spfa();
    cout<<dist[n]<<endl;
    return 0;
}

 

#include<bits/stdc++.h>
using namespace std;
const int N = 110;
const int M = 200010;
const int B = M/2;
int n,m;
int w[N];
bool f[N][M];
int main()
{
    cin>>n;
    for (int i = 1; i <= n; i ++ )
    {
        cin>>w[i];
        m+=w[i];
    }
    f[0][B]=true;
    for (int i = 1; i <= n; i ++ )
    {
        for (int j = -m; j <=m; j ++ )
        {
            f[i][j+B]=f[i-1][j+B];
            if(j-w[i]>=-m)
            {
                f[i][j+B]|=f[i-1][j-w[i]+B];
            }
            if(j+w[i]<=m)
            {
                f[i][j+B]|=f[i-1][j+w[i]+B];
            }
        }
    }
    int res = 0;
    for (int j = 1; j <=m; j ++ )
    {
        if(f[n][j+B])
        {
            res++;
        }
    }
    cout<<res;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值