首页 > 其他分享 >freee Programming Contest 2023(AtCoder Beginner Contest 310)

freee Programming Contest 2023(AtCoder Beginner Contest 310)

时间:2023-07-16 17:00:46浏览次数:50  
标签:std AtCoder Beginner Contest int cin long ++ define

freee Programming Contest 2023(AtCoder Beginner Contest 310) - AtCoder

A - Order Something Else (atcoder.jp)

题意是在买一道菜的情况下可以将原为\(P\)元的饮料优惠\(Q\)元,否则就按原价买

#include<bits/stdc++.h>

#define int long long

using namespace std;

signed main(){
    int n,p,q;
    cin >> n >> p >> q;
    
    vector<int> a(n);
    for(auto &i : a)
        cin >> i;
 
    int ans = p;
    for(auto i : a){
        if(q + i < ans)
            ans = q + i;
    }
 
    cout << ans << endl;
    
    return 0;
}

B - Strictly Superior (atcoder.jp)

题意是有\(N\)种产品,每种产品有最多有\(M\)\((1 < C_i < M)\)种功能,定义第\(i\)种产品的第\(C_i\)种功能为\(F_{i,C_i}\),现满足以下条件则说明存在有一种商品严格大于另一种商品:

  • \(P_i \geq P_j\)

  • 第\(j\)种商品包含第\(i\)种商品的全部功能

  • $P_i > P_j $ 或者 第\(j\)种商品的功能比第\(i\)种更多

纯模拟,注意对条件的判断.

繁杂版(bushi

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long
#define all(a) (a).begin(),(a).end()

using namespace std;

typedef pair<int,int> PII;

int n,m;
void solve() {
    cin >> n >> m;
    multimap<int,vector<int>> prj;
    for(int i = 0;i < n;i ++){
        int p,k;
        cin >> p >> k;
        vector<int> o;
        for(int j = 0;j < k ;j ++){
            int y;
            cin >> y;
            o.push_back(y);
        }
        prj.insert({p,o});
    }

    bool f = false;
    for(auto i : prj){
        for(auto j : prj){
            if(i == j) continue;
            if(j.first <= i.first && j.second.size() >= i.second.size()){
                for(int k = 0;k < i.second.size() ;k++){
                    if(std::find(j.second.begin(), j.second.end(),i.second[k]) == j.second.end())
                        break;
                    if (k == i.second.size() - 1){
                        if(j.first < i.first  ||  j.second.size() > i.second.size())
                            f = true;
                    }
                }
            }
        }
    }
    cout << (f ? "Yes" : "No") << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int Ke_scholar = 1;
//    cin >> Ke_scholar;
    while(Ke_scholar--)
        solve();
    return 0;
}

简洁版(\(jiangly\)的

#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N, M;
    std::cin >> N >> M;
    
    std::vector<int> P(N);
    std::vector<std::bitset<100>> F(N);
    for (int i = 0; i < N; i++) {
        std::cin >> P[i];
        int C;
        std::cin >> C;
        while (C--) {
            int x;
            std::cin >> x;
            F[i][x - 1] = 1;
        }
    }
    
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (P[i] <= P[j] && (F[i] & F[j]) == F[j] && (P[i] < P[j] || F[i] != F[j])) {
                std::cout << "Yes\n";
                return 0;
            }
        }
    }
    std::cout << "No\n";
    
    return 0;
}

C - Reversible (atcoder.jp)

题意就是相同或相反的字符串算一个球棒,输出一共有多少球棒

每次判断一下就行

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long

using namespace std;

int n,m;

void solve() {
   cin >> n;
   set<string> a;
   map<string,int> mps;
   for(int i = 0;i < n;i ++){
       string s,ss;
       cin >> s;
       ss = s;
       std::reverse(s.begin(), s.end());
       if(mps.count(s))
           continue;
       mps[ss]++;
       a.insert(ss);
   }
   cout << a.size() << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int Ke_scholar = 1;
//    cin >> Ke_scholar;
    while(Ke_scholar--)
        solve();
    return 0;
}

放份\(jiangly\)的学习下(

#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N;
    std::cin >> N;
    
    std::vector<std::string> S(N);
    for (int i = 0; i < N; i++) {
        std::cin >> S[i];
        auto T = std::string(S[i].rbegin(), S[i].rend());
        if (T < S[i]) {
            S[i] = T;
        }
    }
    
    auto ans = (std::set(S.begin(), S.end()).size());
    std::cout << ans << "\n";
    
    return 0;
}

D - Peaceful Teams (atcoder.jp)

后面没做出来了,不过看了\(jiangly\)的也算有了思路(bushi

题意就是有\(M\)对有矛盾的队员不能放一个队里,问最多能组成多少不同的队

因为数据范围较小所以可以直接搜就完了

\(c(x)\)代表的是第\(x\)个人被分配到哪一队了,\(max(y,i+ 1)\)是带入当前已经有人被分配的最大队伍数

#include  <bits/stdc++.h>
#define endl '\n'
#define int long long
#define  inf 0x3f3f3f3f

using namespace std;

void solve(){

    int t;
    cin >> n >> t >> m;
    vector<int> a(m),b(m);
    for(int i = 0;i < m;i ++){
        cin >> a[i] >> b[i];
        a[i] --,b[i] --;
    }

    vector<int> c(n);
    int ans = 0;

    auto dfs = [&](auto self, int x,int y){
        if(x == n){
            if(y != t){
                return ;
            }
            bool ok = true;
            for(int i = 0;i < m;i ++){
                if(c[a[i]] == c[b[i]])
                    ok = false;
            }
            ans += ok;
            return ;
        }
        for(int i = 0;i <= y;i ++){
            c[x] = i;
            self(self, x + 1, max(y,i + 1));
        }
    };

    dfs(dfs,0,0);
    cout << ans << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int Ke_scholar = 1;
//    cin >> ie_scholar;
    while(Ke_scholar--)
        solve();
    return 0;
}

就不放\(jiangly\)的了,因为跟他一样(

标签:std,AtCoder,Beginner,Contest,int,cin,long,++,define
From: https://www.cnblogs.com/Kescholar/p/17558122.html

相关文章

  • AtCoder Beginner Contest 310
    (AtCoderBeginnerContest310) A-OrderSomethingElse思路:比较下打折和不打折的情况#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongtypedefpair<int,int>PII;typedefpair<string,int>PSI;typedefpair<string,string>PSS;c......
  • 近期 AtCoder Beginner Contest 题目选做
    AtCoderBeginnerContest310Ehttps://atcoder.jp/contests/abc310/tasks/abc310_e我们要求所有区间的NAND之和,发现NAND最后只可能是\(0\)或\(1\),所以我们只需要计数区间NAND为\(1\)的即可。考虑dp,设\(f_{i,0/1}\)表示以\(i\)结尾的区间最后NAND和为\(0/......
  • freee Programming Contest 2023(AtCoder Beginner Contest 310)题解
    点我看题A-OrderSomethingElse直接比较\(P\)和\(Q+min(D_i)\),输出较小值即可。点击查看代码#include<bits/stdc++.h>#definerep(i,n)for(inti=0;i<n;++i)#definerepn(i,n)for(inti=1;i<=n;++i)#defineLLlonglong#definefifirst#definesesecond#defi......
  • AtCoder Beginner Contest 310
    目录题目传送门:abc310比赛摘记:B题没读懂题意。。。如此简单题卡了好久继续加油哈......
  • Atcoder Regular Contest 118 F - Growth Rate
    想到插值其实就挺套路的了吧……设\(dp_{i,j}\)表示有多少种方法确定\(a_i\sima_n\)使得\(a_i=j\)。那么有\(dp_{i,j}=\sum\limits_{k\geja_i}dp_{i+1,k}\)。边界条件是\(dp_{n+1,1\simm}=1\)。不难发现复杂度与值域有关,一眼过不去的样子。考虑优化,记\(lim_i\)满足......
  • Atcoder AGC062C Mex of Subset Sum
    对\(a_i\)从小到大进行排序,因为想到若\(<a_{i-1}\)的不能取到的数因为\(a_i>a_{i-1}\)肯定是能保证取不到的。对排完序的\(a_i\)做一个前缀和\(s_i=\sum\limits_{j=1}^n\),令\(A_i\)为\(a_{1\simi}\)中无法表示为子序列之和且\(<s_i\)的正整数的集合......
  • SMU Summer 2023 Contest Round 3
    SMUSummer2023ContestRound3A-CurriculumVitae思路:要求0后不能有1,当某个数都不删时,值为前面所有的0的个数加后面所有1的个数,求出最大即可#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongtypedefpair<int,int>PII;typedefpair<string,int>......
  • SMU Summer 2023 Contest Round 2
    SMUSummer2023ContestRound2A-TreasureHunt思路:判断Δx和Δy能否分别整除x和y,求出需要的步数,两者的步数须同奇或同偶#include<bits/stdc++.h>usingnamespacestd;//#defineintlonglongtypedefpair<int,int>PII;typedefpair<string,int>PSI;type......
  • SMU Summer 2023 Contest Round 1
    SMUSummer2023ContestRound1A-TheContest思路:求出最短解决问题总时间,在所有区间找出大于等于总时间的最短时刻。#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongtypedefpair<int,int>PII;typedefpair<string,int>PSI;typedefpair<strin......
  • SMU Summer 2023 Contest Round 3
    A.CurriculumVitae题意:给出一串01序列,可以删除任意个元素,使得1后面没有0思路:枚举01分界点,使得统计前面0的个数和后面1的个数,取最大值。点击查看代码#include<bits/stdc++.h>usingnamespacestd;inta[110];intmain(){ios::sync_with_stdio(0),cin.tie(0),co......