首页 > 其他分享 >2025.1.14——1200

2025.1.14——1200

时间:2025-01-15 21:10:08浏览次数:1  
标签:cnt le 2025.1 14 int max 1200 res define

2025.1.14——1200


Q1. 1200

You have \(n\) sticks, numbered from \(1\) to \(n\). The length of the \(i\)-th stick is \(2^{a_i}\).

You want to choose exactly \(3\) sticks out of the given \(n\) sticks, and form a non-degenerate triangle out of them, using the sticks as the sides of the triangle. A triangle is called non-degenerate if its area is strictly greater than \(0\).

You have to calculate the number of ways to choose exactly \(3\) sticks so that a triangle can be formed out of them. Note that the order of choosing sticks does not matter (for example, choosing the \(1\)-st, \(2\)-nd and \(4\)-th stick is the same as choosing the \(2\)-nd, \(4\)-th and \(1\)-st stick).
Input

  • the first line contains one integer \(n\) (\(1 \le n \le 3 \cdot 10^5\));
  • the second line contains \(n\) integers \(a_1, a_2, \dots, a_n\) (\(0 \le a_i \le n\)).

Q2. 1200

Masha and Olya have an important team olympiad coming up soon. In honor of this, Masha, for warm-up, suggested playing a game with Olya:

There is an array \(a\) of size \(n\). Masha goes first, and the players take turns. Each move is described by the following sequence of actions:

\(\bullet\) If the size of the array is \(1\), the game ends.

\(\bullet\) The player who is currently playing chooses two different indices \(i\), \(j\) (\(1 \le i, j \le |a|\)), and performs the following operation — removes \(a_i\) and \(a_j\) from the array and adds to the array a number equal to \(\lfloor \frac{a_i + a_j}{2} \rfloor \cdot 2\). In other words, first divides the sum of the numbers \(a_i\), \(a_j\) by \(2\) rounding down, and then multiplies the result by \(2\).

Masha aims to maximize the final number, while Olya aims to minimize it.

Masha and Olya decided to play on each non-empty prefix of the initial array \(a\), and asked for your help.

For each \(k = 1, 2, \ldots, n\), answer the following question. Let only the first \(k\) elements of the array \(a\) be present in the game, with indices \(1, 2, \ldots, k\) respectively. What number will remain at the end with optimal play by both players?
Input

The first line of each test case contains a single integer \(n\) (\(1 \le n \le 10^5\)) — the size of the array.

The second line contains \(n\) integers \(a_1,a_2, \ldots,a_n\) (\(1 \leq a_i \leq 10^9\)) — the array on which Masha and Olya play.


Q3. 1200

Vlad found a string \(s\) consisting of \(n\) lowercase Latin letters, and he wants to make it as short as possible.

To do this, he can remove any pair of adjacent characters from \(s\) any number of times, provided they are different. For example, if \(s\)=racoon, then by removing one pair of characters he can obtain the strings coon, roon, raon, and raco, but he cannot obtain racn (because the removed letters were the same) or rcon (because the removed letters were not adjacent).

What is the minimum length Vlad can achieve by applying any number of deletions?
Input

The first line of each test case contains a single integer \(n\) (\(1 \le n \le 2 \cdot 10^5\)) — the length of the string \(s\).

The second line of each test case contains the string \(s\) consisting of \(n\) lowercase Latin letters.


Q4. 1200

Monocarp tries to get home from work. He is currently at the point \(O = (0, 0)\) of a two-dimensional plane; his house is at the point \(P = (P_x, P_y)\).

Unfortunately, it is late in the evening, so it is very dark. Monocarp is afraid of the darkness. He would like to go home along a path illuminated by something.

Thankfully, there are two lanterns, located in the points \(A = (A_x, A_y)\) and \(B = (B_x, B_y)\). You can choose any non-negative number \(w\) and set the power of both lanterns to \(w\). If a lantern's power is set to \(w\), it illuminates a circle of radius \(w\) centered at the lantern location (including the borders of the circle).

You have to choose the minimum non-negative value \(w\) for the power of the lanterns in such a way that there is a path from the point \(O\) to the point \(P\) which is completely illuminated. You may assume that the lanterns don't interfere with Monocarp's movement.

The picture for the first two test cases


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

  • 结论+博弈+结论+结论


A1.

  1. 发现贡献可以缩小选择范围:只有等腰或等边三角形。
  2. 组合一下计算方案数。

A2.

  1. 本质就是发现损失的原因和决策。
  2. 根据奇偶性博弈一下发现损失和奇数的个数有一定关系。

A3.

  1. 思考最后答案的形态是同一个字母。
  2. 充分性策略:考虑最多的那个字母,尽量去消去它,而且在其他字母存在的时候一定可以消去它。
  3. 未消完剩下的就是最优答案,消完再讨论下奇偶决定答案0/1。

A4.

  1. 必要性:\(O\) 点与 \(P\) 点一定需要被照亮。
  2. 充分性:两点被同一灯照亮/两灯都有参与并且两灯有连接。
  3. 数学一下:两种情况两灯互换一下 四种结果取最小值。

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

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;
    cin >> n;
    map<int, int> cnt;
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        cnt[x]++;
    }
    int res = 0;
    auto cal = [](int n)
    {
        return n * (n - 1) * (n - 2) / 6;
    };
    int has = 0;
    for (auto [x, k] : cnt)
    {
        if (k >= 2)
            res += has * k * (k - 1) / 2;
        if (k >= 3)
            res += cal(k);
        has += k;
    }
    cout << res << 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;
    cin >> n;
    int sum = 0;
    int odd = 0;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        sum += x;
        odd += x & 1 != 0;
        int k = 0;
        if (i)
        {
            k = (odd + 2) / 3;
            if (odd % 3 == 2)
                k--;
        }
        cout << sum - k << ' ';
    }
    cout << endl;
}

A3.

#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;
    cin >> n;
    map<char, int> cnt;
    int max_cnt = 0;
    string s;
    cin >> s;
    for (auto v : s)
    {
        cnt[v]++;
        max_cnt = max(max_cnt, cnt[v]);
    }
    int res = max(0ll, max_cnt - (n - max_cnt));
    if (n & 1)
        res = max(1ll, res);
    cout << res << endl;
}

A4.

#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(10);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

#define x first
#define y second
void _()
{
    pair<int, int> o, p, a, b;
    o.x = o.y = 0;
    cin >> p.x >> p.y >> a.x >> a.y >> b.x >> b.y;
    auto d = [](pair<int, int> a, pair<int, int> b)
    {
        return sqrt(1.0 * (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
    };
    double res = min(max(d(a, o), d(a, p)), max(d(b, o), d(b, p)));
    res = min(res, max(d(a, b) / 2, min(max(d(a, o), d(b, p)), max(d(b, o), d(a, p)))));
    cout << res << endl;
}

标签:cnt,le,2025.1,14,int,max,1200,res,define
From: https://www.cnblogs.com/jkkk/p/18673711

相关文章

  • JSP龙陵县第一中学教学资源库系统i8414(程序+源码+数据库+调试部署+开发环境)
    本系统(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。系统程序文件列表技术要求:开发语言:JSP前端使用:HTML5,CSS,JSP动态网页技术后端使用SpringBoot,Spring技术主数据库使用MySQL开题报告内容一、课题背景随着信息技术的不断发展......
  • 30天开发操作系统 第 14 天 -- 高分辨率及键盘输入
    前言从着手“自制操作系统”到现在,不知不觉间已经过去2周了。有的读者朋友读到这里,可能已经花了更长的时间;也有的朋友,经过努力也可能只用了一周左右就读到了这里。开发个操作系统需要些必备知识,像编程语言的知识,相关算法和技巧等。到现在为止,这些知识的介绍就......
  • 【网络云SRE运维开发】2025第3周-每日【2025/01/15】小测-【第14章ospf高级配置】理论
    文章目录【网络云SRE运维开发】2025第3周-每日【2025/01/15】小测-【第14章ospf高级配置】理论和实操14.1选择题在H3C设备上配置OSPF时,以下哪个命令用于启动OSPF进程?A.[H3C]ospfenableB.[H3C]ospf1C.[H3C]ospfstartD.[H3C]ospfprocessOSPF区域0......
  • 【网络云SRE运维开发】2025第3周-每日【2025/01/15】小测-【第14章ospf高级配置】理论
    文章目录14.1选择题解题思路和参考答案14.2理论题解题思路和参考答案14.3实操题解题思路和参考答案思科(Cisco)设备华为(Huawei)设备小米/锐捷(或其他支持标准CLI命令的设备)通过网络管理工具注意事项【网络云SRE运维开发】2025第3周-每日【2025/01/15】小测-【第14章o......
  • 1月14
    1月14日构造题训练Problem-B-CodeforcesProblem-D-Codeforces二分Problem-C-Codeforces优先队列下午小希的迷宫-HDU1272-VirtualJudge并查集判环典题,但是有细节,n=0&&m=0输出yes(唐)。#include<bits/stdc++.h>#defineintlonglong#defineendl'\n'......
  • 2025.1.14初学欧拉函数记
    显然,本文的一切都是关于它——\(\varphi\)。前提互质若有正整数\(a,b\)且满足\(\gcd(a,b)=1\),则称\(a,b\)互质。对于多种数的情况,我们把\(\gcd(a,b,c)=1\)的情况称为\(a,b,c\)互质。把\(\gcd(a,b)=\gcd(a,c)=\gcd(b,c)=1\)称为\(a,b,c\)两两互质。后者明显是一个......
  • 【研发笔记20251114】技术自信 &
    技术自信我们要拥有技术自信!我们许多同学,是缺乏技术自信的。我们习惯了代码有改动,就提测给测试组的同学来进行测试验证。虽说有测试组,但有些开发改动,我们开发者,凭借我们的专业能力(技术能力),可以自己确信没有问题,可以不用一律提测。例如:重命名一个底层工具类的publicstatic方......
  • 2025.1.15日志
    2025.1.141.实现了人物的待机,走路,跑步的动画以及其代码逻辑实现。其中,(待机/走路),(跑步)在动画机BlendTree中的参数用yVelocity,xVelocity表示,  privatevoidAnimatorController()  {    floatyVelocity=Vector3.Dot(moveDir.normalized,transform.f......
  • 十分钟写作Day2 1.14
    前言这是十分钟写作的第二天,也是假期的第二天。回应张老师的号召,今天的题目为《养起一团火》,表达我对\(2.5\)班美好友谊和青春的赞美。正文养一团火握在手心中,伤心的时候低头看看它,它能以微笑回应,给你无尽的前行力量。在春风暖暖中让它盘旋在我手心中,感受生命力量;在夏日炎......
  • linux编译protobuf-3.3.0 报错 automake-1.14 command not found 解决
    目录源码下载配置编译解决REFlinux编译protobuf-3.3.0报错automake-1.14:commandnotfound解决源码下载https://github.com/protocolbuffers/protobuf/releases配置编译配置完成后,编译出错./configuremakecd.&&/bin/bash/tmp/protobuf-3.3.0/miss......