首页 > 其他分享 >abc318

abc318

时间:2023-09-03 17:11:18浏览次数:39  
标签:atcoder abc318 int jp contests day

A - Full Moon

https://atcoder.jp/contests/abc318/tasks/abc318_a

Problem Statement

Takahashi likes full moons.

Let today be day

1. The first day on or after today on which he can see a full moon is day M. After that, he can see a full moon every P days, that is, on day M+P, day

M+2P, and so on.

Find the number of days between day

1 and day N, inclusive, on which he can see a full moon.

 

解析

从M点开始计数,每隔P天记一次满月, 直到超过结束日N

 

Code

https://atcoder.jp/contests/abc318/submissions/45139743

int n, m, p;

int main()
{
    cin >> n >> m >> p;

    int count = 0;
    while(true){
        if (m>n){
            break;
        }
        
        count++;
        m += p;
    }

    cout << count << '\n';

    return 0;
}

 

B - Overlapping sheets

https://atcoder.jp/contests/abc318/tasks/abc318_b

求三块矩形覆盖格子数

 

 

解析

有重叠区域, 对于重叠区域计数,需要保证只计算一次。

以每个格子的左下的点作为格子的计数点,

使用二维map计数,第一维度以x作为key,第二维度以y作为key

 

Code

https://atcoder.jp/contests/abc318/submissions/45156595

map<int, map<int, bool>> flags;
int n;

int main()
{
    cin >> n;

    for(int i=0; i<n; i++){
        int a, b, c, d;
        
        cin >> a >> b >> c >> d;
        
        for(int x=a; x<b; x++){
            for(int y=c; y<d; y++){
                flags[x][y] = true;
            }
        }
    }

    int count = 0;
    for(auto x : flags){
        map<int, bool>& ypoints = x.second;
        count += ypoints.size();
    }

    cout << count << "\n";

    return 0;
}

 

C - Blue Spring

https://atcoder.jp/contests/abc318/tasks/abc318_c

Sample Input 1

Copy
5 2 10
7 1 6 3 6

Sample Output 1

Copy
20

If he buys just one batch of one-day passes and uses them for the first and third days, the total cost will be

(10×1)+(0+1+0+3+6)=20, which is the minimum cost needed.
Thus, print 20.

 

解析

每天的费用为Fi元,

如果购买多天通行证,可以使用D天,总花费P元

该不该使用通行证, 需要进行判断? 将每天的费用最大的三个加起来, 跟P元比较,

如果比P元小,应该使用通行证, 否则使用每天的费用。

 

Code

https://atcoder.jp/contests/abc318/submissions/45188710

LL n, d, p;
vector<LL> f;

int main()
{
    cin >> n >> d >> p;
    for(LL i=0; i<n; i++){
        LL temp;
        cin >> temp;
        f.push_back(temp);
    }

    sort(f.begin(), f.end());
    reverse(f.begin(), f.end());
    
//    for(LL i=0; i<n; i++){
//        cout << f[i] << " ";
//    }
//    cout << "\n";

    LL batch_sum = 0;
    vector<LL> batches;
    for(LL i=0; i<n; i++){
        batch_sum += f[i];
        
        if (i+1 == n || (i+1)%d == 0){
            batches.push_back(batch_sum);
            
            batch_sum = 0;
        }
    }

    reverse(batches.begin(), batches.end());

//    for(LL i=0; i<batches.size(); i++){
//        cout << batches[i] << " ";
//    }
//    cout << "\n";

    LL uppos = upper_bound(batches.begin(), batches.end(), p) - batches.begin();
    LL sum = 0;
    for(LL i=0; i<uppos; i++){
        sum += batches[i];
    }

    if (uppos < batches.size()){
        sum += p * (batches.size() - uppos);
    }

    cout << sum << "\n";

    return 0;
}

 

标签:atcoder,abc318,int,jp,contests,day
From: https://www.cnblogs.com/lightsong/p/17675201.html

相关文章

  • [ABC318D] General Weighted Max Matching 题解
    [ABC318D]GeneralWeightedMaxMatching题解题意  给定无向有权完全图,求最大权匹配。思路分析  注意到\(n\le16\),我考虑状压DP。  设当前点集\(S\)中最大权匹配的答案是\(f_S\),我们考虑\(S\)中“最后”一个点\(p\)(这里的“最后”一个点是指,在状压表示状态......
  • [ABC318E] Sandwiches 题解
    题意给定一个长度为\(N\)的正整数列\(A=\left(A_1,A_2,\cdots,A_N\right)\),求满足以下条件的正整数三元组\(\left(i,j,k\right)\)的数量:\(1\lei<j<k\leN\);\(A_i=A_k\);\(A_i\neqA_j\)。数据范围:\(3\leN\le3\times10^5\);\(1\leA_i......
  • ABC318G Typical Path Problem
    给定无向连通图,问是否存在一条从\(A\)到\(C\)经过\(B\)的简单路径。\(n\le3\times10^5\)。怎么这个G这么简单我还没写完啊?怎么这个G这么简单我还没写完啊?怎么这个G这么简单我还没写完啊?怎么这个G这么简单我还没写完啊?怎么这个G这么简单我还没写完啊?怎么这......
  • AT_abc318_e 题解
    AT_abc318_eSandwiches题解Links洛谷AtCoderDescription给定一个长度为\(n\)的序列\(a\),找到满足以下条件的三元组\((a,b,c)\)的数量。\(i<j<k\);\(a_{i}=a_{k}\);\(a_{i}\neqa_{j}\)。数据范围:\(1\leqn\leq3\times10^{5}\),\(1\leqa_{i}\leqn......
  • ABC318
    T1:FullMoon模拟代码实现n,m,p=map(int,input().split())ans=0i=mwhilei<=n:ans+=1i+=pprint(ans)或者答案是\(\lfloor\frac{n+(p-m)}{p}\rfloor\)T2:Overlappingsheets模拟代码实现#include<bits/stdc++.h>#definerep(i,n)f......