首页 > 其他分享 >Educational Codeforces Round 24

Educational Codeforces Round 24

时间:2023-02-26 14:47:43浏览次数:66  
标签:24 Educational int ll Codeforces long using mul include

Educational Codeforces Round 24

https://codeforces.com/contest/818
有些题就是从某个角度想好复杂,不好实现,但是换一种思考方式,从另一个角度想就会豁然开朗,也很好写。这么讲很抽象,但是做题的时候会发现,自己是在一方向上耗死了,结果一看题解就觉得,哇塞tql

A. Diplomas and Certificates

#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main () {
    ll n, m, k;
    cin >> n >> k;
    m = n;
    n /= 2;
    ll x = n / (k + 1);
    if ((k + 1) * x > n)    x = 0;
    cout << x << ' ' << k * x << ' ' << m - (k + 1) * x;
}

B. Permutation Game

差分构造

#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int N = 105;
int a[N], b[N], n, m;

int main () {
    cin >> n >> m;
    for (int i = 1; i <= m; i++)    cin >> b[i];
    set<int> s; //未放的数字
    for (int i = 1; i <= n; i++)    s.insert (i);
    for (int i = 1; i < m; i++) {
        int idx = b[i], dx = (b[i+1] - b[i] + n) % n;
        if (dx == 0)    dx = n;
        if ((a[idx] && a[idx] != dx) || (!a[idx] && !s.count (dx))) {
            cout << -1;
            return 0;
        }
        s.erase (dx), a[idx] = dx;
        //cout << idx << ' ' << dx << endl;
    }
    for (int i = 1; i <= n; i++) {
        if (a[i] == 0)  a[i] = *s.begin (), s.erase (s.begin ());
        cout << a[i] << ' ';
    }
}

C. Sofa Thief

D. Multicolored Cars

这个就是要换一个角度去想,记录不可能来check

#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int N = 1e5 + 5;
int a[N], n, A;

int main () {
    scanf ("%d%d", &n, &A);
    for (int i = 1; i <= n; i++)    scanf ("%d", &a[i]);
    map<int, int> mp;
    set<int> s;
    for (int i = 1; i <= 1e6; i++)  s.insert (i);
    s.erase (A);
    for (int i = 1; i <= n; i++) {
        mp[a[i]] ++;
        if (a[i] != A) {
            if (mp[a[i]] <= mp[A])  s.erase (a[i]);
        }
    }
    for (auto i : s) {
        if (mp[i] >= mp[A]) {
            printf ("%d", i);
            return 0;
        }
    }
    printf ("-1");
}

//每个阶段可能的答案取个交集

E. Card Game Again

半暴力优化查找
再已知确实有答案(前/后缀乘积)的情况下,找到最小区间
记录上一个位置防止重复查找
特别关注循环边界的退出条件!!

#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int N = 1e5 + 5;
ll a[N], n, k;

int main () {
    cin >> n >> k;
    ll ans = 0, lst = n, mul = 1;
    for (int i = 1; i <= n; i++)    cin >> a[i];
    for (int i = n, j; i >= 1; i--) {
        mul = mul * a[i] % k;
        if (mul)    continue;
        mul = 1;
        for (j = i; mul * a[j] % k; ) {
            mul = mul * a[j++] % k;
            if (mul * a[j] % k == 0) { //最小区间[i,j]
                break;
            }
        }
        ans += i * (lst - j + 1);
        lst = j - 1;
    }
    cout << ans << endl;
}

//半暴力优化查找
//再已知确实有答案(前/后缀乘积)的情况下,找到最小区间
//记录上一个位置防止重复查找

F. Level Generation

G. Four Melodies

标签:24,Educational,int,ll,Codeforces,long,using,mul,include
From: https://www.cnblogs.com/CTing/p/17156644.html

相关文章

  • Codeforces Round #853 (Div. 2) 题解
    CodeforcesRound#853(Div.2)题解ABCDCodeforcesRound#853(Div.2)|萌新实况被吊打|ABCD题解E.ServalandMusicGame分两种情况讨论:\(\lfloor\frac{s_......
  • 2023.2.24AcWing蓝桥杯集训·每日一题
    今日复习的知识点为递归。递归对于笔者而言是个比较难以理解的知识点,后续会多进行递归题目的练习。AcWing1497.树的遍历题目描述一个二叉树,树中每个节点的权值互不相同......
  • Educational Codeforces Round 23
    EducationalCodeforcesRound23https://codeforces.com/contest/817数据结构专场。A.TreasureHunt#include<bits/stdc++.h>usingnamespacestd;intmain()......
  • 代码随想录算法训练营Day24 回溯算法|216.组合总和III 17.电话号码的字母组合
    代码随想录算法训练营216.组合总和III题目链接:216.组合总和III找出所有相加之和为 n的 k 个数的组合。组合中只允许含有1- 9的正整数,并且每种组合中不存在重复......
  • Codeforces Edu 143 补题笔记
    [A.TwoTowers](Problem-A-Codeforces)Def给出长为n,m的两个01栈,可以将栈顶的元素移往另一个栈顶,问是否可以使得两个栈中元素均为01交替Sol因为是栈顶,可以知道......
  • LQB10,AT24C02的使用
    1、单片机用P20和P21和AT24C02通信;2、比赛提供的开发包里面的代码。头文件c文件提供的代码解读以及修改合适自己使用。#ifndef_IIC_H#define_IIC_HvoidIIC_Start(vo......
  • vue.js代码024
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>事件绑定</title><scripttype="text/javascript"src="../js/vue.js"></script></head>......
  • Day 24 24.1:逆向分析1 - Steam案例
    STEAM逆向分析url:https://store.steampowered.com/login/?redir=&redir_ssl=1分析思路:输入用户名和密码后,点击登录按钮,通过抓包工具捕获点击登录按钮后发起请求对......
  • 题解 Codeforces 1746F Kazaee
    题意给定长度为\(n\)的数组\(a\),和\(q\)次操作,支持:给定\(i,x\),修改\(a_i\)为\(x\)给定\(l,r,k\),查询\([l,r]\)中是否每个数的出现次数都是\(k\)的倍数......
  • [LeetCode] 1247. Minimum Swaps to Make Strings Equal
    Youaregiventwostrings s1 and s2 ofequallengthconsistingofletters "x" and "y" only.Yourtaskistomakethesetwostringsequaltoeachother.......