首页 > 其他分享 >AtCoder Beginners Contest 274 Editoral

AtCoder Beginners Contest 274 Editoral

时间:2022-10-25 21:44:15浏览次数:64  
标签:AtCoder Code Sample Source int Beginners 题面 274 2i

AtCoder Beginners Contest 274 Editoral

目录

Task A - Batting Average

Problem Statement

There are integers \(A\) and \(B\), which satisfy \(1≤A≤10\) and \(0≤B≤A\).
Let S be the string obtained as follows.

Round off \(\dfrac AB\) to three decimal digits, then write the integer part (1 digit), . (the decimal point), and the decimal part (3 digits) in this order, with trailing zeros.
For example, if A=7 and B=4, then \(\dfrac AB=\dfrac74\) =0.571428… rounded off to three decimal digits is 0.571. Thus, S is 0.571.

You are given A and B as the input and asked to print S.

Sample Data

Sample Input 1

7 4

Sample Output 1

0.571

题面翻译

对\(\dfrac AB\)四舍五入到保留四个有效数字

Source Code

#include <bits/stdc++.h>
using namespace std;
int main()
{
    float a, b;
    cin >> a >> b;
    while (b / a > 1)
    {
        b -= a;
    }
    cout << fixed << setprecision(3) << b / a << endl;
}

解析

如果需要解析那你不适合学编程

Task B - Line Sensor

Problem Statement

There is a grid with H rows from top to bottom and W columns from left to right. Let (i,j) denote the square at the i-th row from the top and j-th column from the left.

The squares are described by characters \(C_{i, j}\) . If \(C_{i, j}\) is ., $ (i, j)$ is empty; if it is #, \((i, j)\) contains a box. For integers \(j\) satisfying \(1 \leq j \leq W\) , let the integer $ X_{j} $ defined as follows.

  • \(X_{j}\) is the number of boxes in the \(j\) -th column. In other words, \(X_{j}\) is the number of integers \(i\) such that \(C_{i, j}\) is #. Find all of $X_{1}, X_{2}, \ldots, X_{W} $

Sample Input 1

3 4
#..#
.#.#
.#.#

Sample Output 1

1 2 0 3

题面翻译

对于一个H行W列的表格,.表示空,#表示有内容,求每一列有多少个有内容的格子。

Source Code

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int h, w;
    // system("pause");
    bool square[1005][1005];
    int ans[1005] = {0};
    cin >> h >> w;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            char ch = getchar();
            if (ch == '\n')
                ch = getchar();
            if (ch == '#')
            {
                square[i][j] = 1;
                ans[j]++;
            }
            else
                square[i][j] = 0;
        }
    }
    for (int i = 0; i < w; i++)
    {
        cout << ans[i] << " ";
    }
}

解析

在每次读入的时候直接存储到对应的列去,但是注意在换行的时候要额外读入一个'\n'

Task C - Ameba (变形虫)

我不理解为什么会有这么恶心的题面

Problem Statement

You observed amoebae and kept some records.

Initially, there was one amoeba, numbered 1.

You made N records. According to the i-th record, the amoeba numbered \(A_i\) disappeared by dividing itself into two new amoebae, which were then numbered \(2i\) and \(2i+1\).
Here, amoeba \(A_i\)is said to be the parent of amoebae of \(2i\) and \(2i+1\).

For each \(k=1,…,2N+1\), how many generations away is amoeba k from amoeba \(1\)?

Sample Input 1

2
1 2

Sample Output 1

0
1
1
2
2

题面翻译

每一只虫子的孩子是这只虫子编号的两倍和两倍加一,标准的二叉树。

Source Code

// /*

// 编号i的变形虫,其两个孩子为2i,2i+1
// 对于i输出dist(i,1)+1两次
// dist(i,1)=dist(i-1,1)+1;

// */

// #include <bits/stdc++.h>
// using namespace std;
// int parent[2 * 10 ^ 5 + 1] = {0};

// int dist(int i, int org)
// {
//     cout << '\t' << parent[i] << " " << org << endl;
//     if (i == org)
//         return 0;

//     return (parent[i], org) + 1;
// }
// int main()
// {
//     parent[2] = 1;
//     parent[1] = 1;
//     parent[4] = 2;
//     cout << dist(1, 1) << endl;
//     cout << dist(2, 1);
//     int n;
//     cin >> n;
//     for (int i = 1; i <= n; i++)
//     {
//         int t;
//         cin >> t;
//         parent[2 * t] = parent[2 * t + 1] = dist(t, 1);
//         cout << i << " " << parent[2 * t] << " " << parent[2 * t + 1] << endl;
//     }
//     for (int i = 1; i <= 2 * n + 1; i++)
//     {
//         cout << dist(i, 1) << endl;
//     }
// }

#include <iostream>
using namespace std;
int n, g[400010];
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int v;
        cin >> v;
        g[2 * i | 1] = g[2 * i] = g[v] + 1;
    }
    for (int i = 1; i <= 2 * n + 1; i++)
        cout << g[i] << endl;
}

解析

求每个节点的深度

标签:AtCoder,Code,Sample,Source,int,Beginners,题面,274,2i
From: https://www.cnblogs.com/sweepy/p/abc-274.html

相关文章

  • BYSBZ 2748(音量调节-01背包)
    第一题:音量调节(changingsounds)时间限制:1秒空间限制:64MB输入:changingsounds.in输出:changingsounds.out问题描述一个吉他手准备参加一场演出。他不喜欢在演出时始终使......
  • LOJ #2274. 「JXOI2017」加法
    题目链接:​​传送门​​最小值最大化,首先是很明显的二分其次是很明显的贪心,因为我们要选择一定数量的区间进行操作二分最后的这个最大值在check函数中把数组中值小于二......
  • D - Longest X -- ATCODER
    D-LongestXhttps://atcoder.jp/contests/abc229/tasks/abc229_d参考:https://zhuanlan.zhihu.com/p/441875505 思路使用acc累计数组,统计每个位置之前的.的数目设......
  • [abc274F] Fishing 题解
    比较有趣的用点思维的题。在学校和DYS一起推出来的题,庆祝AT复活写个题解。感觉用无序列表列出自己思绪的过程很简洁扼要,但是行文节奏过快。介于我想重现自己今天上午......
  • Atcoder补题计划
    ◉ABC274F-Fishing//枚举作为左端点的鱼//每条鱼有一个在这个区间中的时间段//计算出与长度为a的区间有交集的时间的区间的权值的最大值//时间的区间(离散化......
  • D - Robot Arms 2 -- ATCODER
    D-RobotArms2题目:https://atcoder.jp/contests/abc274/tasks/abc274_d参考:https://zhuanlan.zhihu.com/p/576281206 分析dfs或者bfs最大复杂度2^1000,超时......
  • ABC274 题解
    A题目:给定\(A,B\)输出\({B}\over{A}\)保留\(3\)位小数。简答题,和A+Bproblem一样,除一除,保留一下小数。B题目:给定一个\(n\)行\(m\)列由'.'和'#'的方阵,求每列......
  • Atcoder ABC274 记录
    [ABC274A]BattingAverage略。[ABC274B]LineSensor略。[ABC274C]Ameba建树维护亲代关系即可。[ABC274D]RobotArms2按下标奇偶性分为两类,然后分别做一遍背包......
  • ABC274D题解
    这是一道较为简单的可行性DP。首先看到题目,很容易想到将横纵坐标一起进行处理,但显然时间会炸飞。所以我们将横纵坐标拆开分别处理,那么就有如下状态:\(dpa_{i,j}\)表示在......
  • ABC274G题解
    这是一个比较经典的网络流的建模。首先我们可以横着和竖着给原图编两遍号,能够一次照到的编号相同。以样例一为例:....#....先横着编号:1112#3444再......