2021中石油组队训练第八场记录(下)

简介: 题目描述Alice and Bob decide to share a chocolate bar, which is an n by m rectangular grid of chocolate cells. They decide that Alice should get a < n·m pieces and that Bob should get b = n·m − a pieces. To split the chocolate bar, they repeatedly take a single piece of chocolate and break it either

问题 C: Cocoa Coalition

时间限制: 1 Sec 内存限制: 128 MB


题目描述


Alice and Bob decide to share a chocolate bar, which is an n by m rectangular grid of chocolate cells. They decide that Alice should get a < n·m pieces and that Bob should get b = n·m − a pieces. To split the chocolate bar, they repeatedly take a single piece of chocolate and break it either horizontally or vertically, creating two smaller pieces of chocolate. See Figure C.1 for an

example.

What is the minimum number of splits that Alice and Bob need to perform in order to split the n-by-m chocolate bar into two piles consisting of a and b chocolate cells?

微信图片_20220531162949.png

Figure C.1: Illustration of a solution to Sample Input 2, showing the original 10-by-10 chocolate bar split three times into pieces of size 10-by-2, 10-by-5, 3-by-3 and 7-by-3. Giving Alice the 10-by-5 and 7-by-3 pieces, she gets a total of 50 + 21 = 71 chocolate cells.


输入


The input consists of a single line, containing the three integers n, m and a (1 ≤ n, m ≤ 106 ,1 ≤ a < n · m).


输出


Output the minimum number of splits needed to achieve the desired division of chocolate.


样例输入 Copy


3 10 9


样例输出 Copy


1


题目大意:


给出一个矩形的巧克力方块,每个小方块是1*1的,每次可以横着或者是竖着切一刀,问切出面积总共为 a 的一块最少需要操作几次


有一种情况是:

5 * 15 的方块,切出大小为31的一块,最少是两刀,不是三刀:

第一次切出45的一块来,然后右面剩下的事511的一块,然后正好还差 11小块,此时切一刀解决问题


Main_code:


  ll n, m, a; cin >> n >> m >> a;
    ll _a = a;
    if (2 * a > n * m) a = n * m - a;
    if (n > m) swap(n, m);
    if (a % n == 0 || a % m == 0) {
        cout << 1 << endl;
        return 0;
    }
    if (a >= 1 && a < m) {
        cout << 2 << endl;
        return 0;
    }
    for (ll i = 2; i * i <= _a; i++) {
        if (_a % i == 0) {
            ll j = _a / i;
            if (i <= n && j <= m) {
                cout << 2 << endl;
                return 0;
            }
        }
    }
    for (ll t = 1; t <= m; t++) {
        ll u = n * t, v = _a - u;
        ll mi = m - t, mx = n;
        if (mi > 0 && v > 0) {
            if (v % mi == 0 || v % mx == 0) {
                cout << 2 << endl;
                return 0;
            }
        }
        else break;
    }
    for (ll t = 1; t <= n; t++) {
        ll u = m * t, v = _a - u;
        ll mi = n - t, mx = m;
        if (mi > 0 && v > 0) {
            if (v % mi == 0 || v % mx == 0) {
                cout << 2 << endl;
                return 0;
            }
        }
        else break;
    }
    cout << 3 << endl;
    return 0;


问题 G: Hot Hike

时间限制: 1 Sec 内存限制: 128 MB


题目描述


In order to pass time during your vacation, you decided to go on a hike to visit a scenic lake up in the mountains. Hiking to the lake will take you a full day, then you will stay there for a day to rest and enjoy the scenery, and then spend another day hiking home, for a total of three days. However, the accursed weather this summer is ridiculously warm and sunny, and since severe dehydration is not at the top of your priority list you want to schedule the three-day trip during some days where the two hiking days are the least warm. In particular you want to minimize the maximum temperature during the two hiking days.

Given the current forecast of daily maximum temperatures during your vacation, what are the best days for your trip?


输入


The first line of input contains an integer n (3 ≤ n ≤ 50), the length of your vacation in days. Then follows a line containing n integers t1 , t2 , . . . , tn (−20 ≤ t i ≤ 40), where ti is the temperature forecast for the i’th day of your vacation.


输出


Output two integers d and t, where d is the best day to start your trip, and t is the resulting maximum temperature during the two hiking days. If there are many choices of d that minimize the value of t, then output the smallest such d.


样例输入 Copy


5
23 27 31 28 30


样例输出 Copy


2 28


不再赘述

int minn=inf,tag=-1;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<n-1;i++)
    {
        if(minn>max(a[i],a[i+2]))
        {
            tag=i;
            minn=max(a[i],a[i+2]);
        }
    }
    cout<<tag<<" "<<minn<<endl;


问题 F: Game of Gnomes

时间限制: 1 Sec 内存限制: 128 MB


题目描述


The enemy and their massive army is approaching your fortress, and all you have to defend it is a legion of guardian gnomes. There is no hope of winning the battle, so your focus will instead be on causing as much damage as possible to the enemy.

You have n gnomes at your disposal. Before the battle, they must be divided into at most m non-empty groups. The battle will then proceed in turns. Each turn, your gnomes will attack the enemy, causing one unit of damage for each living gnome. Then the enemy will attack by throwing a lightning bolt at one of the m groups. The lightning bolt kills k of the gnomes in that group, or all of them if the number of living gnomes in the group is less than k. The battle ends when all gnomes are dead. The enemy will always throw the lightning bolts in an optimal way such that the total damage caused by the gnomes is minimized.

Now you wonder, what is the maximum amount of damage you can cause to the enemy if you divide the gnomes into groups in an optimal way?

For example, if as in Sample Input 1 you have n = 10 gnomes that are to be divided into m = 4 groups, and the lightning bolt does at most k = 3 damage, then an optimal solution would be to create one large group of size 7 and three small groups of size 1. In the first round, you cause 10 damage and the lightning bolt reduces the large group by 3. In the next round, you cause 7 damage and the large group is reduced down to size 1. In the remaining four rounds you do 4, 3, 2, and 1 damage respectively and the lightning bolt removes one group each round. In total you do 10 + 7 + 4 + 3 + 2 + 1 = 27 damage.


输入


The input consists of a single line containing the three integers n, m, and k (1 ≤ n ≤ 109 ,1 ≤ m, k ≤ 107 ), with meanings as described above.


输出


Output the maximum amount of damage you can cause to the enemy.


样例输入 Copy


10 4 3


样例输出 Copy


27


这是一道比较不错的涉及数学的贪心构造思维题;

学长的博客讲解很详细

  ll n, m, k;
  cin >> n >> m >> k;
  ll i = (n / k - m) - 10;
  if (i < 0) i = 0;
  for (; i <= n / k; i++) {
    if (n - i * k >= m * k) continue;
    ll t1 = n - (i - 1) * k;
    ll max1 = (n + t1) * i / 2;
    ll rem = n - i * k;/// 剩余的
    ll tot = rem / m;/// 
    ll modd = rem % m;
    ll temp1 = (rem + (m - modd) * tot + tot + 1) * modd / 2;
    ll temp2 = (tot + (m - modd) * tot) * (m - modd) / 2;
    ll ans = max1 + temp1 + temp2;
    res = max(res, ans);
  }
  cout << res << endl;

更新中。。。。。。


目录
相关文章
|
人工智能 算法 BI
第320场周赛赛后分析总结(前三题)
前言 几个星期没打周赛,手感生疏了好多,果然算法题还是得勤加练习,多找适应比赛的感觉。 同时,第二、三题都是图和树相关的内容,像我这种对这个专题还不熟的也可以借此机会巩固一下。
98 0
基于夜间灯光遥感数据的中原城市群城镇空间格局研究
基于夜间灯光提取城市建成区的范围,从而进行区域城镇化空间格局分析。
基于夜间灯光遥感数据的中原城市群城镇空间格局研究
|
Go
2020中石油组队训练第八场记录(上)
问题 D: Eeny Meeny 时间限制: 2 Sec 内存限制: 128 MB 题目描述 “Eeny meeny miny moe” is a well-known nursery rhyme in English, used (among other things) by kids to “randomly” select members of a team. It exists in many variations, one of which goes like this: Eeny, meeny, miny, moe, Catch a tiger by the toe.
62 0
2020中石油组队训练第八场记录(上)
|
程序员
lduoj_2021年初寒假训练第42场(下)
目录 2021年初寒假训练第41场 A. 复制-粘贴 B. 足球联赛 C. 捕食关系 D. 幻方 E. 求和 F. 猜歌名
195 0
lduoj_2021年初寒假训练第42场(下)
|
机器学习/深度学习 程序员
lduoj_2021年初寒假训练第41场(上)
2021年初寒假训练第41场 A. 复制-粘贴 B. 足球联赛 C. 捕食关系 D. 幻方 E. 求和 F. 猜歌名
166 0
「镁客早报」NASA公布“门户计划”,未来将在月球轨道建立空间站;特斯拉裁掉Model3交付部门一半以上
全球最大资产管理公司贝莱德再次增持三星股票;IBM与纽约州立大学理工学院设AI硬件实验室。
476 0
|
Web App开发 机器学习/深度学习 机器人
UC伯克利研发史上最灵巧机器人,物品分拣每小时达300次
加州大学伯克利分校的研究人员最近研发了一款新的机器人,由一个高分辨率3D传感器和两个高度灵活的机械臂组成,在分拣物体任务中每小时平均次数达到200~300次,接近人类水平。研究者称,这是有史以来世界上最灵巧的机器人。
10568 0