1. 程式人生 > >9.11考試總結

9.11考試總結

out 需要 mis 數學題 struct sum int 直接 輸入數據

# 9.11考試總結

細胞分裂

數學題目,因式分解後直接判斷輸入數據是否含有m1中分解出來的數,然後儲存需要時間最大值中的最小值

#include<bits/stdc++.h>
#define open(s) freopen(s".in", "r", stdin);// freopen(s".out", "w", stdout);
#define IL inline
#define ull unsigned long long
#define ll long long
using namespace std;

int n, m1, m2;
int a;
int maxb, lenb;
int b[30010];
struct date
{
    int su, add;
}d[30010];
int lend;

IL int read();
IL void cut(int);
IL void cutt(int);

int main()
{
    open("cell");
    n = read(); m1 = read(); m2 = read();
    cut(m1);
    if (m1 == 1)
    {
        cout << "0" << endl;
        return 0;
    }
    int ans = 999999999;
    for (int i=1; i<=n; ++i)
    {
        a = read();
        int temp = -1;
        for (int j=1; j<=lend; ++j)
        {
            if (a%d[j].add)
            {
                temp = -1;
                break;
            }
            int sum = 0;
            while (!(a%d[j].add))
            {
                sum++;
                a /= d[j].add;
            }
            sum = ceil(d[j].su*1.0/sum);
            temp = max(temp, sum);
        }
        if (temp != -1)
            ans = min(ans, temp);
    }
    if (ans == 999999999)
        cout << "-1";
    else cout << ans;
    cout << endl;
    return 0;
}

void cut(int x)
{
    lend = 0;
    for (int i=2; i*i<=x; ++i)
    {
        if (!(x%i))
        {
            lend++;
            d[lend].add = i;
            d[lend].su = 0;
            while (!(x%i))
            {
                d[lend].su++;
                x /= i;
            }
            d[lend].su *= m2;
        }
    }
    if (x != 1)
    {
        d[++lend].add = x;
        d[lend].su = m2;
    }
}

int read()
{
    int i = 1, j = 0;
    char x = getchar();
    while (x < '0' || '9' < x)
    {
        if ('-' == x) i = -1;
        x = getchar();
    }
    while ('0' <= x && x <= '9')
    {
        j = j * 10 + x - '0';
        x = getchar();
    }
    return i*j;
}

這道題在考試的時候沒有找到最優化的方法導致復雜度超高,然後re

導彈攔截

說是一道貪心題目,實際跟暴力枚舉沒有什麽區別。現將最開始的情況直接全部分配給第一個系統並且要從大到小排序,在逐步枚舉分配給第二個系統的截止位置。記錄最小答案即可

#include<bits/stdc++.h>
#define open(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout);
#define IL inline
#define ull unsigned long long
#define ll long long
using namespace std;

int ax, ay, bx, by;
int n, k = 1;
int xx[100010], yy[100010];
struct date
{
    int x, y;
}a[100010];

IL int read();
IL int max(int, int);
IL bool cmp(date, date);

int main()
{
//  open("missile");
    ax = read(); ay = read(); bx = read(); by = read();
    n = read();
    for (int i=1; i<=n; ++i)
    {
        int x, y;
        x = read(), y = read();
        a[i].x = (ax - x) * (ax - x) + (ay - y) * (ay - y);
        a[i].y = (bx - x) * (bx - x) + (by - y) * (by - y);
    }
    sort(a+1, a+1+n, cmp);
    int i=2,r1=a[1].x,r2=0;
    int minn = r1 + r2;
    while (i <= n)
    {
        r1 = a[i].x;
        r2 = max(r2, a[i-1].y);
        minn = min(minn, r1+r2);
        i++;
    }
    cout << minn << endl;
    return 0;
}

bool cmp(date x, date y)
{
    return x.x > y.x;
}

int max(int x, int y)
{
    return x > y ? x : y;
}

int read()
{
    int i = 1, j = 0;
    char x = getchar();
    while (x < '0' || '9' < x)
    {
        if ('-' == x) i = -1;
        x = getchar();
    }
    while ('0' <= x && x <= '9')
    {
        j = j * 10 + x - '0';
        x = getchar();
    }
    return i*j;
}

這個題目直接貪心好像有一定的問題存在。所以必須保證平方和最小,而不是單個系統的最值問題

三國遊戲

因為機器總是被動防守,所以總是選擇不到大的值,而最大值的另外的搭配總是先被機器選走。所以人只能拿到次大,就直接尋找每一組搭配的次大值就可以了

#include<bits/stdc++.h>
#define open(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout);
#define IL inline
#define ull unsigned long long
#define ll long long
using namespace std;

int n;
int a[510][510];

IL int read();
IL bool cmp(int x, int y)
{
    return x > y;
}

int main()
{
    //open("sanguo");
    int maxn = -1, addj;
    n = read();
    for (int i=1; i<=n; ++i)
        for (int j=i+1; j<=n; ++j)
            a[i][j] = a[j][i] = read();
    int ans = 0;
    for (int i=1; i<=n; ++i)
    {
        sort(a[i]+1, a[i]+n+1, cmp);
        maxn = max(maxn, a[i][2]);
    }
    cout << "1" << endl;
    cout << maxn << endl;
    return 0;
}

int read()
{
    int i = 1, j = 0;
    char x = getchar();
    while (x < '0' || '9' < x)
    {
        if ('-' == x) i = -1;
        x = getchar();
    }
    while ('0' <= x && x <= '9')
    {
        j = j * 10 + x - '0';
        x = getchar();
    }
    return i*j;
}

9.11考試總結