首页 > 其他分享 >模拟赛记录2024.03

模拟赛记录2024.03

时间:2024-03-20 20:34:45浏览次数:30  
标签:2024.03 记录 int void cerr names template print 模拟

2024.03 模拟赛记录

2024.03.20

TheBrickTowerMediumDivOne

不考虑相同元素顺序,最优解的形式为,将原序列从小到大排序,从前往后依次放在当前答案的开头或者结尾

考虑相同元素的影响,发现在贪心的同时记录当前放在首尾的同样元素的编号

然后贪心的把小的编号靠前即可

code
// Author: xiaruize
#ifndef ONLINE_JUDGE
bool start_of_memory_use;
#else
#define debug(x)
#endif
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
clock_t start_clock = clock();
#endif
namespace __DEBUG_UTIL__
{
    using namespace std;
    /* Primitive Datatypes Print */
    void print(const char *x) { cerr << x; }
    void print(bool x) { cerr << (x ? "T" : "F"); }
    void print(char x) { cerr << '\'' << x << '\''; }
    void print(signed short int x) { cerr << x; }
    void print(unsigned short int x) { cerr << x; }
    void print(signed int x) { cerr << x; }
    void print(unsigned int x) { cerr << x; }
    void print(signed long int x) { cerr << x; }
    void print(unsigned long int x) { cerr << x; }
    void print(signed long long int x) { cerr << x; }
    void print(unsigned long long int x) { cerr << x; }
    void print(float x) { cerr << x; }
    void print(double x) { cerr << x; }
    void print(long double x) { cerr << x; }
    void print(string x) { cerr << '\"' << x << '\"'; }
    template <size_t N>
    void print(bitset<N> x) { cerr << x; }
    void print(vector<bool> v)
    { /* Overloaded this because stl optimizes vector<bool> by using
        _Bit_reference instead of bool to conserve space. */
        int f = 0;
        cerr << '{';
        for (auto &&i : v)
            cerr << (f++ ? "," : "") << (i ? "T" : "F");
        cerr << "}";
    }
    /* Templates Declarations to support nested datatypes */
    template <typename T>
    void print(T &&x);
    template <typename T>
    void print(vector<vector<T>> mat);
    template <typename T, size_t N, size_t M>
    void print(T (&mat)[N][M]);
    template <typename F, typename S>
    void print(pair<F, S> x);
    template <typename T, size_t N>
    struct Tuple;
    template <typename T>
    struct Tuple<T, 1>;
    template <typename... Args>
    void print(tuple<Args...> t);
    template <typename... T>
    void print(priority_queue<T...> pq);
    template <typename T>
    void print(stack<T> st);
    template <typename T>
    void print(queue<T> q);
    /* Template Datatypes Definitions */
    template <typename T>
    void print(T &&x)
    {
        /*  This works for every container that supports range-based loop
            i.e. vector, set, map, oset, omap, dequeue */
        int f = 0;
        cerr << '{';
        for (auto &&i : x)
            cerr << (f++ ? "," : ""), print(i);
        cerr << "}";
    }
    template <typename T>
    void print(vector<vector<T>> mat)
    {
        int f = 0;
        cerr << "\n~~~~~\n";
        for (auto &&i : mat)
        {
            cerr << setw(2) << left << f++, print(i), cerr << "\n";
        }
        cerr << "~~~~~\n";
    }
    template <typename T, size_t N, size_t M>
    void print(T (&mat)[N][M])
    {
        int f = 0;
        cerr << "\n~~~~~\n";
        for (auto &&i : mat)
        {
            cerr << setw(2) << left << f++, print(i), cerr << "\n";
        }
        cerr << "~~~~~\n";
    }
    template <typename F, typename S>
    void print(pair<F, S> x)
    {
        cerr << '(';
        print(x.first);
        cerr << ',';
        print(x.second);
        cerr << ')';
    }
    template <typename T, size_t N>
    struct Tuple
    {
        static void printTuple(T t)
        {
            Tuple<T, N - 1>::printTuple(t);
            cerr << ",", print(get<N - 1>(t));
        }
    };
    template <typename T>
    struct Tuple<T, 1>
    {
        static void printTuple(T t) { print(get<0>(t)); }
    };
    template <typename... Args>
    void print(tuple<Args...> t)
    {
        cerr << "(";
        Tuple<decltype(t), sizeof...(Args)>::printTuple(t);
        cerr << ")";
    }
    template <typename... T>
    void print(priority_queue<T...> pq)
    {
        int f = 0;
        cerr << '{';
        while (!pq.empty())
            cerr << (f++ ? "," : ""), print(pq.top()), pq.pop();
        cerr << "}";
    }
    template <typename T>
    void print(stack<T> st)
    {
        int f = 0;
        cerr << '{';
        while (!st.empty())
            cerr << (f++ ? "," : ""), print(st.top()), st.pop();
        cerr << "}";
    }
    template <typename T>
    void print(queue<T> q)
    {
        int f = 0;
        cerr << '{';
        while (!q.empty())
            cerr << (f++ ? "," : ""), print(q.front()), q.pop();
        cerr << "}";
    }
    /* Printer functions */
    void printer(const char *) {} /* Base Recursive */
    template <typename T, typename... V>
    void printer(const char *names, T &&head, V &&...tail)
    {
        /* Using && to capture both lvalues and rvalues */
        int i = 0;
        for (size_t bracket = 0; names[i] != '\0' and (names[i] != ',' or bracket != 0); i++)
            if (names[i] == '(' or names[i] == '<' or names[i] == '{')
                bracket++;
            else if (names[i] == ')' or names[i] == '>' or names[i] == '}')
                bracket--;
        cerr.write(names, i) << " = ";
        print(head);
        if (sizeof...(tail))
            cerr << " ||", printer(names + i + 1, tail...);
        else
            cerr << "]\n";
    }
    /* PrinterArr */
    void printerArr(const char *) {} /* Base Recursive */
    template <typename T, typename... V>
    void printerArr(const char *names, T arr[], size_t N, V... tail)
    {
        size_t ind = 0;
        for (; names[ind] and names[ind] != ','; ind++)
            cerr << names[ind];
        for (ind++; names[ind] and names[ind] != ','; ind++)
            ;
        cerr << " = {";
        for (size_t i = 0; i < N; i++)
            cerr << (i ? "," : ""), print(arr[i]);
        cerr << "}";
        if (sizeof...(tail))
            cerr << " ||", printerArr(names + ind + 1, tail...);
        else
            cerr << "]\n";
    }
}
#ifndef ONLINE_JUDGE
#define debug(...) std::cerr << __LINE__ << ": [", __DEBUG_UTIL__::printer(#__VA_ARGS__, __VA_ARGS__)
#define debugArr(...) std::cerr << __LINE__ << ": [", __DEBUG_UTIL__::printerArr(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...)
#define debugArr(...)
#endif
#define int long long
#define ull unsigned long long
#define ALL(a) (a).begin(), (a).end()
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define pis pair<int, string>
#define sec second
#define fir first
#define sz(a) int((a).size())
#define Yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl
#define mms(arr, n) memset(arr, n, sizeof(arr))
#define rep(i, a, n) for (int i = (a); i <= (n); ++i)
#define per(i, n, a) for (int i = (n); i >= (a); --i)
int max(int a, int b)
{
    if (a > b)
        return a;
    return b;
}
int min(int a, int b)
{
    if (a < b)
        return a;
    return b;
}
const int INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1000000007;
const int N = 47 + 10;

int n;
pii a[N];
vector<pii> vec[N];
deque<int> res;

void solve()
{
    cin >> n;
    rep(i, 1, n)
    {
        cin >> a[i].first;
        a[i].second = i - 1;
        vec[a[i].first].push_back(a[i]);
    }
    rep(i, 1, 50)
    {
        if (res.empty() && vec[i].size())
        {
            sort(ALL(vec[i]));
            for (auto v : vec[i])
                res.push_back(v.second);
            continue;
        }
        vector<int> ls, rs;
        for (auto v : vec[i])
        {
            if (v.second < res.front())
                ls.push_back(v.second);
            else
                rs.push_back(v.second);
        }
        sort(ALL(ls));
        reverse(ALL(ls));
        for (auto v : ls)
            res.push_front(v);
        sort(ALL(rs));
        for (auto v : rs)
            res.push_back(v);
    }
    for (auto v : res)
        cout << v << ' ';
}

#ifndef ONLINE_JUDGE
bool end_of_memory_use;
#endif

signed main()
{
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int testcase = 1;
    // cin >> testcase;
    while (testcase--)
        solve();
#ifndef ONLINE_JUDGE
    cerr << "Memory use:" << (&end_of_memory_use - &start_of_memory_use) / 1024.0 / 1024.0 << "MiB" << endl;
    cerr << "Time use:" << (double)clock() / CLOCKS_PER_SEC * 1000.0 << "ms" << endl;
#endif
    return 0;
}

标签:2024.03,记录,int,void,cerr,names,template,print,模拟
From: https://www.cnblogs.com/xiaruize/p/18086001

相关文章

  • LeetCode刷题记录——day2
    https://leetcode.cn/problems/product-of-array-except-self/description/?envType=study-plan-v2&envId=top-interview-150问题在于不使用除法并且空间复杂度为O(1),当第一次从头开始遍历时由于不知道后续数组元素是什么,所以无法得到答案,而如果当知道一个后续数组元素后,又回去更......
  • leetcode代码记录(长度最小的子数组
    目录1.题目:2.我的代码:小结:1.题目:给定一个含有n个正整数的数组和一个正整数target。找出该数组中满足其总和大于等于target的长度最小的连续子数组[numsl,numsl+1,…,numsr-1,numsr],并返回其长度。如果不存在符合条件的子数组,返回0。示例1:输......
  • 操作系统综合题之“用记录型信号量机制的wait和signal操作来保证文件的正确打印,并写出
    1.问题:有两个进程pA和pB合作解决文件打印的问题:pA将文件记录从磁盘读入住库存的缓冲区,每次执行一次读一个记录;pB将缓冲区的内容打印出来,每次执行一次打印一个记录。缓冲区的大小等于一个记录大小请用记录型信号量机制的wait(S)和signal(S)操作来保证文件的正确打印,并写出同步代码2.......
  • Blazor学习记录三
    11.自定义组件与消费端变量之间实现双向绑定这也实现了从子组件到父组件的状态传递。1.定义一个数据类型为T的参数。2.再定义一个参数名+[Changed]为名称,EventCallback结构类型的参数。注意T类型要和第一步中的参数数据类型T相同。3.定义一个被用于元素中的C#事件触发的事件......
  • 操作系统综合题之“采用记录型信号量机制实现进程INPUT、PROCESS和OUTPUT的同步算法(
    1.问题:系统中有有三个进程INPUT、PROCESS和OUTPUT,共用两个缓冲区BUF1和BUF2。假期设BUF1中最多可放10个数据,现已放入了2个数据;BUF2最多可放5个数据。INPUT进程负责不断将输入的原始数据推送入BUF1,PROCESS进程负责从BUF1中取出原始数据进行处理,并将处理后的结果数据送入到BUF2中,OUT......
  • C语言游戏实战(4):人生重开模拟器
     前言:人生重开模拟器是前段时间非常火的一个小游戏,接下来我们将一起学习使用c语言写一个简易版的人生重开模拟器。 网页版游戏:人生重开模拟器(ytecn.com)1.实现一个简化版的人生重开模拟器(1)游戏开始的时候,设定初始属性:颜值,体质,智力,家境(2)开始游戏,随机生成性别和出生......
  • w10下安装mysql8.0及dbeaver24记录
    1、首先到官网或者下载网站,下载mysql8.0的安装包,本次是从第三方下载网站下载的msi安装包,直接点开安装就行2、安装完后,参考https://blog.csdn.net/Javachichi/article/details/1327585513、然后下载安装dbeaver,安装好后配置连接mysql,其中自动下载mysql驱动时可能会报错,提示maven......
  • 蓝桥杯- 第14届模拟题第二套
     老规矩,先看外设要求......ADC,LED,LCD,KEY,EEPROM。除了EEPROM之外其它没什么新意,所以我们来看看EEPROM就可以了(其它可以在第一套模拟题中看到) /*****************************************************************************************************************/EE......
  • 使用AOP记录feign调用日志
    文章目录业务场景使用DemoClientFeignDemlFeignFallBack主要代码DockLogAspectDockLogDockLogServiceDockLogAddDTOJacksonUtils业务场景记录请求第三方接口的情况。@DockLog可以用在类上也可以用在方法上使用DemoClientFeignimportorg.springframework.cloud......
  • Centos 7.5基于MySQL 5.7的 InnoDB Cluster 多节点高可用集群环境部署记录【转】
    前面给大家介绍过:MySQL高可用方案选型解析,今天我将详细的为大家介绍Centos7.5基于MySQL5.7的InnoDBCluster多节点高可用集群环境部署的相关知识,希望大家能够从中收获多多!如有帮助,请点在看、转发支持一波!!!MySQLInnoDBCluster介绍MySQL的高可用架构无论是社区还是官方,一......