2018 Nowcoder Multi-University Training Contest 5

Practice Link

A. gpa

题意:
有\(n\)门课程,每门课程的学分为\(s_i\),绩点为\(c_i\),要求最多删除\(k\)门课程,使得gpa最高。
gpa计算方式如下:
\[
\begin{eqnarray*}
gpa = \frac{\sum s_ic_i}{\sum s_i}
\end{eqnarray*}
\]

思路:
首先删去的课程越多,gpa肯定不会变得更差。
所以我们肯定是删去\(k\)门课程。
考虑二分答案,check的时候要满足:
\[
\begin{eqnarray*}
gpa &\leq& \frac{\sum s_ic_i}{\sum s_i} \gpa \cdot \sum s_i &\leq& \sum s_ic_i \\sum s_i \cdot gpa &\leq& \sum s_ic_i \\sum s_i \cdot (gpa - c_i) &\leq& 0
\end{eqnarray*}
\]
那么check的时候贪心选取\(n - k\)个即可。

代码:

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define db double
#define N 100010
#define pii pair <int, int>
#define fi first
#define se second
const db eps = 1e-10;
int n, k; pii a[N];

bool ok(db x) {
    vector <db> vec;
    for (int i = 1; i <= n; ++i) {
        vec.push_back(a[i].fi * (x - a[i].se));
    }
    sort(vec.begin(), vec.end());
    db tot = 0;
    for (int i = 0; i < n - k; ++i) {
        tot += vec[i];
    }
    return tot <= 0 || fabs(tot - 0) < eps;
}

int main() {
    while (scanf("%d%d", &n, &k) != EOF) {
        for (int i = 1; i <= n; ++i) {
            scanf("%d", &a[i].fi);
        }
        for (int i = 1; i <= n; ++i) {
            scanf("%d", &a[i].se);
        }
        db l = 0, r = 1e3, res = 0;
        while (fabs(r - l) >= eps) {
            db mid = (l + r) / 2;
            if (ok(mid)) {
                l = mid;
                res = mid;
            } else {
                r = mid;
            }
        }
        printf("%.10f\n", res);
    }
    return 0;
}

G. max

题意:
给出\(c\)和\(n\),要求找到一对\((a, b)\)满足\(1 \leq a, b \leq n\)使得\(gcd(a, b) = c\)并且最大化\(a \cdot b\)

思路:

  • \(c > n\)时无解
  • \(c = n\)时选择\((n, n)\)
  • \(c < n\)时在\([1, \frac{n}{c}]\)中选取两个互质的数再分别乘上\(c\)

代码:

#include <bits/stdc++.h>
using namespace std;

#define ll long long
ll c, n;

int main() {
    while (scanf("%lld%lld", &c, &n) != EOF) {
        if (c > n) {
            puts("-1");
            continue;
        }
        ll x = n / c;
        ll res = c * c;
        if (x > 1) {
            res *= x * (x - 1);
        }
        printf("%lld\n", res);
    }
    return 0;
}

J. plan

题意:
有\(n\)个人去住宿,双人房的价格为\(p_2\), 三人房的价格为\(p_3\),要求将\(n\)个人全都安排好住宿的最小代价是多少,不一定恰好住满。

思路:
大范围直接除2, 除3, 小范围暴力dp一下。

代码:

#include <bits/stdc++.h>
using namespace std;

#define N 1000010
#define ll long long
#define ll long long
ll n, p2, p3;
ll f[N];

ll DFS(int x) {
    if (x <= 0) {
        return 0;
    }
    if (f[x] != -1) {
        return f[x];
    }
    return f[x] = min(p2 + DFS(x - 2), p3 + DFS(x - 3));
}

int main() {
    while (scanf("%lld%lld%lld", &n, &p2, &p3) != EOF) {
        memset(f, -1, sizeof f);
        if (n <= 1000000) {
            printf("%lld\n", DFS(n));
        } else {
            ll res = 1e18;
            ll m;
            for (int i = 0; i < 1000000; ++i) {
                m = n - i;
                res = min(res, p2 * (m / 2) + DFS(i + m % 2));
                res = min(res, p3 * (m / 3) + DFS(i + m % 3));
            }
            printf("%lld\n", res);
        }
    }
    return 0;
}

原文地址:https://www.cnblogs.com/Dup4/p/11108589.html

时间: 2024-11-05 21:54:12

2018 Nowcoder Multi-University Training Contest 5的相关文章

HDU 2018 Multi-University Training Contest 3 Problem A. Ascending Rating 【单调队列优化】

任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6319 Problem A. Ascending Rating Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 5943    Accepted Submission(s): 2004 Problem Description Before

杭电2018多校第一场(2018 Multi-University Training Contest 1) 1001.Maximum Multiple (HDU6298)-数学思维题(脑子是个好东西,可惜我没有)

暑假杭电多校第一场,这一场是贪心场,很多贪心的题目,但是自己太菜,姿势挫死了,把自己都写吐了... 2018 Multi-University Training Contest 1 HDU6298.Maximum Multiple 题目意思就是给你一个n,找出来三个数x,y,z, 使得n=x+y+z,而且x,y,z都是n的因数,并且x*y*z为最大值,让你输出来x*y*z的最大值.如果没有满足条件的情况就输出-1. 由1=1/2+1/3+1/6=1/3+1/3+1/3=1/2+1/4+1/4,所

2018 Multi-University Training Contest 4

Problem D. Nothing is Impossible Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 504    Accepted Submission(s): 302 Problem Description m students, including Kazari, will take an exam tomorrow

HDU 6396 Swordsman --------2018 Multi-University Training Contest 7 (模拟+读入挂)

原题地址: 打怪升级 一开始有N个怪物:主角有K个能力:只有K个能力都击败怪物才能斩杀怪物并获得K个能力的增值:问最多能杀几个怪物: 做法: 用优先队列把怪物能力装进去:能力小放前面: 最重要的是数据量要用读入挂才能过:(读入挂太神奇了!!) Swordsman Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2049    Acce

2018 Multi-University Training Contest 3

2018 Multi-University Training Contest 2 题解 A - Problem A. Ascending Rating 题目描述:给定一个序列,分别求出所有长度为\(m\)的区间的\(maxrating, count\),对于每个长度为\(m\)的区间,一开始\(maxrating=-1, count=0\),然后从左往右扫,扫到一个大于\(maxrating\)的值时,\(count+1, maxrating=\)那个数. solution 从左往右做,用单调队

2018 Multi-University Training Contest 1 Distinct Values 【贪心 + set】

任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6301 Distinct Values Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5312    Accepted Submission(s): 1823 Problem Description Chiaki has an array of

2018 Multi-University Training Contest 4 Problem L. Graph Theory Homework 【YY】

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6343 Problem L. Graph Theory Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1536    Accepted Submission(s): 830 Problem Description Ther

2018 Multi-University Training Contest 4 Problem K. Expression in Memories 【模拟】

任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6342 Problem K. Expression in Memories Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 2150    Accepted Submission(s): 772Special Judge Problem De

2018 Multi-University Training Contest 4 Problem J. Let Sudoku Rotate 【DFS+剪枝+矩阵旋转】

任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6341 Problem J. Let Sudoku Rotate Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1363    Accepted Submission(s): 717 Problem Description Sudoku i

HDU4888 Redraw Beautiful Drawings(2014 Multi-University Training Contest 3)

Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Alice and Bob are playing together. Alice is crazy about art and she has visited many museums around the world. She has