• 微信公众号:美女很有趣。 工作之余,放松一下,关注即送10G+美女照片!

第十二节蓝桥杯

开发技术 开发技术 1周前 (05-04) 8次浏览

A. 空间

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    cout << 256 * 1024 * 1024 / 4 << endl;
    return 0;
}
答案:67108864

B. 卡片

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int s[10];

bool check(int x)
{
    while (x)
    {
        int t = x % 10;
        x /= 10;
        if ( -- s[t] < 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;
}
答案:3181

C. 直线

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

const int N = 200000;

int n;
struct Line
{
    double k, b;
    bool operator< (const Line& t) const
    {
        if (k != t.k) return k < t.k;
        return b < t.b;
    }
}l[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].k - l[i - 1].k) > 1e-8 || fabs(l[i].b - l[i - 1].b) > 1e-8)
            res ++ ;
    cout << res + 20 << endl;//注意加上开始的20条斜率为0的直线

    return 0;
}
答案:40257

D:货物摆放

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;

int main()
{
    vector<LL> v;
    LL n = 2021041820210418;
    for(LL i = 1; i * i <= n; i ++ )
    {
        if(n % i == 0)
        {
            v.push_back(i);
            if(n / i != i)v.push_back(n / i);//一次vector进入两个数,注意特判i * i = n的情况,
        }
    }
    int res = 0;
    for(auto a : v)
        for(auto b : v)
            for(auto c : v)
            {
                if(a * b * c == n)res ++;
            }
    cout << res << endl;
    return 0;
}

答案:2430


E:路径



程序员灯塔
转载请注明原文链接:第十二节蓝桥杯
喜欢 (0)