首页 > 其他分享 >2024.12.22 周日

2024.12.22 周日

时间:2024-12-23 11:53:02浏览次数:4  
标签:2024.12 monster 22 int res array 周日 monsters define

2024.12.22 周日


Q1. 1100

You are playing a computer game. The current level of this game can be modeled as a straight line. Your character is in point $0$ of this line. There are $n$ monsters trying to kill your character; the $i$-th monster has health equal to $a_i$ and is initially in the point $x_i$.

Every second, the following happens:

  • first, you fire up to $k$ bullets at monsters. Each bullet targets exactly one monster and decreases its health by $1$. For each bullet, you choose its target arbitrary (for example, you can fire all bullets at one monster, fire all bullets at different monsters, or choose any other combination). Any monster can be targeted by a bullet, regardless of its position and any other factors;
  • then, all alive monsters with health $0$ or less die;
  • then, all alive monsters move $1$ point closer to you (monsters to the left of you increase their coordinates by $1$, monsters to the right of you decrease their coordinates by $1$). If any monster reaches your character (moves to the point $0$), you lose.

Can you survive and kill all $n$ monsters without letting any of them reach your character?


Q2. 1100

Petya has an array $a_i$ of $n$ integers. His brother Vasya became envious and decided to make his own array of $n$ integers.

To do this, he found $m$ integers $b_i$ ($m\ge n$), and now he wants to choose some $n$ integers of them and arrange them in a certain order to obtain an array $c_i$ of length $n$.

Vasya wants to make his array as different as possible from Petya's array. Specifically, he wants the total difference $D = \sum_{i=1}^{n} |a_i - c_i|$ to be as large as possible.

Help Vasya find the maximum difference $D$ he can obtain.


------------------------独自思考分割线------------------------

  • 2道贪心

A1.

  1. 设定距离数组:距离为 $i$ 时怪物血量总和。检查每一个 $i*k<=pre[i]$。

A2.

  1. 一道有意思的贪心,想了很久,证明略难..

------------------------代码分割线------------------------

A1.

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(6);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n), x(n), pre(n + 1);
    for (int &x : a)
        cin >> x;
    for (int &x : x)
        cin >> x;
    for (int i = 0; i < n; i++)
        pre[abs(x[i])] += a[i];
    bool res = 1;
    for (int i = 1; i <= n; i++)
    {
        pre[i] += pre[i - 1];
        if (pre[i] > k * i)
            res = 0;
    }
    cout << (res ? "YES" : "NO") << endl;
}

A2.

#include <bits/stdc++.h>
#define int long long //
// #define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(6);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int n, m;
    cin >> n >> m;
    struct Node
    {
        /* data */
        int x, i;
    };

    vector<Node> a(n + 1);
    vector<int> b(m + 1), res(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i].x, a[i].i = i;
    for (int i = 1; i <= m; i++)
        cin >> b[i];
    sort(a.begin() + 1, a.end(), [](Node &a, Node &b)
         { return a.x < b.x; });
    sort(b.begin() + 1, b.end());
    int la = 1, ra = n, lb = 1, rb = m;
    while (la <= ra)
    {
        if (abs(a[la].x - b[rb]) > abs(a[ra].x - b[lb]))
            res[la] = b[rb], la++, rb--;
        else
            res[ra] = b[lb], ra--, lb++;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
        ans += abs(a[i].x - res[i]);
    // cout << res[i] << ' ';
    cout << ans << endl;
}

标签:2024.12,monster,22,int,res,array,周日,monsters,define
From: https://www.cnblogs.com/jkkk/p/18623670

相关文章

  • 上周热点回顾(12.16-12.22)
    热点随笔:· 33岁,从上海裸辞回西安创业 (龙卷风摧毁停车场!)· 好消息,在VisualStudio中可以免费使用GitHubCopilot了! (追逐时光者)· 2000Star,是时候为我的开源项目更新下功能了 (程序猿阿朗)· 他又又来了,c#开源sql解析引擎类库【SqlParser.Net1.0】正式发布 (三......
  • 11.22
    请假条管理系统1、项目需求:本项目所开发的学生请假条管理系统,完成个人请假信息的增删改查。2.系统要求与功能设计2.1页面要求(1)能够在Tomcat服务器中正确部署,并通过浏览器查看;(2)网站页面整体风格统一;(3)主页面包括要求新增请假申请、修改申请、删除申请、查询申请四个子菜单。......
  • INA226折腾笔记(一)
    其实也算不上折腾,这个模块很简单就一个简单的I2C模块。随便搞个单片机就能读写,之所以玩这个,主要还是对手上的USB表不满意(换句话说就是达不到我的需求)我手上有几个USB表左边那个高仿版FNB58,右边那个是科维斯的CC表型号为KWS-1902C,平时就是测测手机充电功率之类的,也够用,FNB58还带......
  • Diary - 2024.12.22
    吸取之前教训,今天早点写日记。看起来我还缺:Solution-LuoguP11394[JOIOpen2019]ウイルス実験Solution-LuoguP11398众数Solution-LuoguP11401[Code+#8初赛]普勒亚Solution-LuoguP11402[Code+#8初赛]图Solution-LuoguP11405[RMI2020]秘鲁/Per......
  • 12.22
    1、表单校验步骤(1)确定事件(submit事件),创建一个函数并和该事件绑定。(2)书写函数对输入的数据是否合法进行校验(需要设定ID并通过ID来获取用户输入的数据的值)。(3)输入的信息合法,可以正常提交;不合法的话,不能提交用户信息并给出提示信息。2、校验函数(1)非空校验:通过ID获取值,对是否为......
  • 2024.12.15-2024.12.22
    物理快期末了,真是狂拉进度,考试不重要的就没有细细学了主要学了振荡,然后学了一点波,振荡是波的基础算法补周赛题真是收益良多啊题解1.动态规划的转移顺序,也可以尝试逆序转移2.线段树的理解更深一层,怎么定义节点信息,push_down,父节点子节点的关系,最重要的怎么实现离散化思......
  • 变量、常量、作用域、关键字、修饰符、标识符、运算符20221222
    变量、常量、作用域20241222变量◆变量是什么:就是可以变化的量!◆Java是一种强类型语言,每个变量都必须声明其类型◆Java变量是程序中最基本的存储单元,其要素包括变量名,变量类型和作用域。◆使用逗号隔开在一行定义多个同类型变量,可以但是不推荐//intdata_04=1,data......
  • 2024.12.22
    系统上下文图(SystemContextDiagram,SCD)是一种高层次的建模工具,通常用于表示一个系统及其外部环境之间的交互关系。它通过图形化的方式描述系统的边界、与外部实体的交互以及输入和输出信息流。系统上下文图是系统分析和需求建模的重要工具,可以帮助项目团队和利益相关者理解系统......
  • 24.12.22
    四边形不等式/决策单调性真正用于优化的性质是决策单调性:对于任意决策点\(p\),如果\(i\)处从\(p\)转移都优于从\(p\)前转移,则任意大于\(i\)的位置\(i'\)从\(p\)转移都优于从\(p\)前转移。四边形不等式是常见的证明决策单调性的方法。虽然场上建议打表找规律直......
  • 2024.12.22
    数学归纳法常用公式\((a+b)^n\)\((a+b)^n\)的系数是杨辉三角的某一层,a升幂排列,b降幂排列同理可得\((a-b)^n\),可以看作(\(a+(-b))^2\),与上面相同。......