头像

Bobby


访客:1756

离线:1个月前


活动打卡代码 AcWing 1424. 文具订购

Bobby
2个月前
#include <bits/stdc++.h>
using namespace std;

int s, n, t, x, y, z, k;

int main()
{
//  freopen("order.in", "r", stdin);
//  freopen("order.in", "r", stdout);
    cin >> n;
    s = n / 14;
    x = y = z = s;
    t = n % 14;
    if (t % 3 == 0) z += t / 3;
    else if (t % 4 == 0 && t != 12) y += t / 4;
    if (t == 1)
    {
        y++;
        z--;
    }
    if (t == 2)
    {
        y += 2;
        z -= 2;
    }
    if (t == 5) z += 3, y--;
    if (t == 7) z++, y++;
    if (t == 10) z += 2, y++;
    if (t == 11) z++, y += 2;
    if (t == 13) z += 3, y++;
    while (min(x, min(y, z)) < x)
    {
        x--;
        y++;
        z++;
    }
    if (x >= 0 && y >= 0 && z >= 0 && (x * 7 + y * 4 + z * 3) == n) cout << x << ' ' << y << ' ' << z << endl;
    else cout << -1 << endl;
    return 0;
}


活动打卡代码 AcWing 451. 摆花

Bobby
2个月前
#include <bits/stdc++.h>
using namespace std;

const int mod = 1000007;

int n, m, f[105];

int main()
{
    cin >> n >> m;
    f[0] = 1;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        for (int j = m; j >= 0; j--)
            for (int k = 1; k <= j && k <= a; k++)
                f[j] = (f[j] + f[j - k]) % mod;
    }
    cout << f[m] << endl;
    return 0;
}


活动打卡代码 AcWing 434. 排座椅

Bobby
3个月前
#include <bits/stdc++.h>
using namespace std;

const int N = 2005;
pair < int, int > w[N], v[N];
int ans[N];

int main()
{
    int m, n, k, l, d, x1, x2, y1, y2, cnt;
    cin >> m >> n >> k >> l >> d;
    for (int i = 1; i <= m; i++)
        w[i].second = i;
    for (int i = 1; i <= n; i++)
        v[i].second = i;
    for (int i = 1; i <= d; ++i)
    {
        cin >> x1 >> y1 >> x2 >> y2;
        if (abs(x1 - x2) == 1) w[min(x1, x2)].first++;
        if (abs(y1 - y2) == 1) v[min(y1, y2)].first++;
    }
    sort(w + 1, w + m + 1);
    sort(v + 1, v + n + 1);
    cnt = 0;
    for (int i = m; i > m - k; i--)
        ans[cnt++] = w[i].second;
    sort(ans, ans + cnt);
    for (int i = 0; i < cnt; i++)
    {
        cout << ans[i];
        if (i < cnt - 1) putchar(' ');
    }
    putchar('\n');
    cnt = 0;
    for (int i = n; i > n - l; i--)
        ans[cnt++] = v[i].second;
    sort(ans, ans + cnt);
    for (int i = 0; i < cnt; i++)
    {
        cout << ans[i];
        if (i < cnt - 1) putchar(' ');
    }
    return 0;
}


活动打卡代码 AcWing 443. 导弹拦截

Bobby
3个月前
#include<bits/stdc++.h>
using namespace std;

int x1, yl, x2, y2, n, ans, r1, r2;

struct node
{
    int x, y, d1;
}a[100005];

int work(int x,int y,int a,int b)
{
    return (x - a) * (x - a) + (y - b) * (y - b);
}

bool cmp(node a,node b)
{
    return a.d1 > b.d1;
}

void init()
{
    int x, y;
    cin >> x1 >> yl >> x2 >> y2 >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> x >> y;
        a[i].x = x;
        a[i].y = y;
        a[i].d1 = work(x1, yl, a[i].x, a[i].y);
    }
    sort(a + 1, a + n + 1, cmp);
    r1 = a[1].d1;
    ans = r1;
}

void doawork()
{
    for(int i = 2; i <= n + 1; i++)
    {
        r1 = a[i].d1;
        r2 = max(r2, work(x2, y2, a[i - 1].x, a[i - 1].y));
        ans = min(ans,r1+r2);
    }
}

int main()

{
    init();
    doawork();
    cout << ans << endl;
    return 0;
}


活动打卡代码 AcWing 432. Hanoi双塔问题

Bobby
3个月前
#include <bits/stdc++.h>
using namespace std;

int n, c, a[22], m;

int main()
{
    cin >> n;
    a[1] = 2; 
    for(int i = 2; i <= n; i++) 
    {
        c = 0;
        for(int j = 1; j <= 20; j++) 
        {
            a[j] = a[j] * 2 + c; 
            if(j == 1) a[j] += 2;
            c = a[j] / 10000;
            a[j] %= 10000; 
        }
    }
    m = 20;
    while(m >1 && !a[m]) m--; 
    cout << a[m]; 
    while(--m)
       printf("%04d",a[m]);
    cout << endl;
    return 0;
}


活动打卡代码 AcWing 428. 数列

Bobby
3个月前
#include <bits/stdc++.h>
using namespace std;

long long find(int a, int b)
{
    long long ans = 1;
    while (b--) ans *= a;
    return ans;
}

int main()
{
    int n, k;
    cin >> k >> n;
    long long ans = 0;
    for (int i = 0; i < 20; i++)
        if (n >> i & 1)
            ans += find(k, i);
    cout << ans << endl;
    return 0;
}


活动打卡代码 AcWing 419. FBI树

Bobby
3个月前
#include <bits/stdc++.h>
using namespace std;

int n;

void dg(string s)
{
    if (s.size() > 1)
    {
        dg(s.substr(0, s.size() / 2));
        dg(s.substr(s.size() / 2));
    }
    int b = 0, a = 0;
    for (int i = 0; i <= s.size() - 1; i++)
        if (s[i] == '0') a++;
        else b++;
    if (a * b != 0) cout << 'F';
    else if (b) cout << 'I';
    else cout << 'B';
}

int main()
{
    int n;
    string s;
    cin >> n;
    cin >> s;
    n = s.size();
    dg(s);
    cout << endl;     
    return 0;
}



活动打卡代码 AcWing 418. 花生采摘

Bobby
3个月前
#include <bits/stdc++.h>
using namespace std;

int m, n, k, a[25][25], ans, fx, fy;

void init()
{
    cin >> m >> n >> k;
    for (int i = 1; i <= m; i++)
        for (int j = 1; j <= n; j++)
            cin >> a[i][j];
}

void find()
{
    int maxn = 0;
    for (int i = 1; i <= m; i++)
        for (int j = 1; j <= n; j++)
            if (a[i][j] > maxn)
            {
                maxn = a[i][j];
                fx = i;
                fy = j;
            }
}

int main()
{
    init();
    find();
    if (fx * 2 + 1 > k) 
    {
        cout << 0 << endl;
        return 0;
    }
    else
    {
        k -= (fx + 1);
        ans += a[fx][fy];
        a[fx][fy] = 0;
        int tx = fx, ty = fy;
        while(1)
        {
            find();
            if (abs(tx - fx) + abs(ty - fy) + 1 + fx <= k)
            {
                ans += a[fx][fy];
                a[fx][fy] = 0;
                k -= (abs(tx - fx) + abs(ty - fy) + 1);
                tx = fx, ty = fy;
            }
            else break;
        }
    }
    cout << ans << endl;
    return 0;
}



活动打卡代码 AcWing 1163. 纪念品

Bobby
3个月前
#include <bits/stdc++.h>
using namespace std;

const int N = 1005, M = 10005;
int t, n, m;
int f[M];
int w[N][N];

int main()
{
    cin >> t >> n >> m;
    for (int i = 1; i <= t; i++)
        for (int j = 1; j <= n; j++)
            cin >> w[i][j];
    for (int i = 1; i < t; i++)
    {
        memset(f, 0, sizeof(f));
        for (int j = 1; j <= n; j++)
            if (w[i + 1][j] > w[i][j])
                for (int k = w[i][j]; k <= m; k++)
                    f[k] = max(f[k], f[k - w[i][j]] + w[i + 1][j] - w[i][j]);
        m += f[m];
    }
    cout << m << endl;
    return 0;
}


活动打卡代码 AcWing 416. 麦森数

Bobby
3个月前
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;

int p, a[5005], b[5005], t[5005], ans[5005], x[505];

void mul(int a[], int b[], int ans[])
{
    memset(t, 0, sizeof(t));
    for (int i = 0; i < 500; i++)
        for (int j = 0; j < 500; j++)
            if (i + j < 500) t[i + j] += a[i] * b[j];
    int jw = 0;
    for (int i = 0; i < 500; i++)
    {
        t[i] += jw;
        jw = t[i] / 10;
        ans[i] = t[i] % 10;
    } 
 } 

void qsm()
{
    ans[0] = 1;
    x[0] = 2;
    while (p != 0)
    {
        if(p & 1 == 1) mul(ans, x, ans);
        mul(x, x, x);
        p >>= 1;
    }
    ans[0] -= 1; 
}

void myprint()
{
    int k = 0;
    for (int i = 499; i >= 0; i--)
    {
        k++;
        cout << ans[i];
        if (k % 50 == 0 ) cout << endl;
    }
}

int main()
{
    cin >> p;
    cout << int(p * log10(2)) + 1 << endl;
    qsm();
    myprint();
    return 0;
}