9.11考试总结

早过忘川 提交于 2019-12-26 05:31:58

# 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;
}

道路游戏

DP题目,又是在考试时候想出解法,但是剩余时间不多了没有继续深入思考。因为工厂价格以及机器人行走时间的原因需要o(\(n^3\)),(优先队列没有学)

#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, m, p;
int a[1010][1010];
int co[1010];
int f[1010];
ll ans;

IL int read();

int main()
{
//  open("game");
    n = read(); m = read(); p = read();
    for (int i=1; i<=n; ++i)
        for (int j=1; j<=m; ++j)
            a[i][j] = read();
    for (int i=1; i<=n; ++i)
        co[i] = read();
    for (int i=1; i<=m; ++i)
        f[i] = -1e9;
    int ans = 0, t;
    for (int i=1; i<=m; ++i)
    {
        for (int j=1; j<=n; ++j)
        {
            ans = f[i-1] - co[j];//枚举在哪个厂更新机器人
            for (int k=0; k<p && i+k<=m; ++k)//从当前点往后推
            {
                t = j+k > n ? ((j+k)%n) : j+k;//处理环
                ans += a[t][i+k];
                f[i+k] = f[i+k] > ans ? f[i+k] : ans;//更新
            }
        }
    }
    cout << f[m] << 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;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!