Codeforces Round #565 (Div. 3) C. Lose it!

Stella981
• 阅读 798

链接:

https://codeforces.com/contest/1176/problem/C

题意:

You are given an array a consisting of n integers. Each ai is one of the six following numbers: 4,8,15,16,23,42.

Your task is to remove the minimum number of elements to make this array good.

An array of length k is called good if k is divisible by 6 and it is possible to split it into k6 subsequences 4,8,15,16,23,42.

Examples of good arrays:

[4,8,15,16,23,42] (the whole array is a required sequence); [4,8,4,15,16,8,23,15,16,42,23,42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); [] (the empty array is good). Examples of bad arrays:

[4,8,15,16,42,23] (the order of elements should be exactly 4,8,15,16,23,42); [4,8,15,16,23,42,4] (the length of the array is not divisible by 6); [4,8,15,16,23,42,4,8,15,16,23,23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence).

思路:

刚开始题目看错。。以为任意顺序的子序列。 map将值映射到1-6,然后每次遇到2-5中的x,从x-1的个数中移一个到x,最后看能移几个到6.

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t;

map<int, int> mp;

int main()
{
    cin >> n;
    mp[4] = 1;
    mp[8] = 2;
    mp[15] = 3;
    mp[16] = 4;
    mp[23] = 5;
    mp[42] = 6;
    int vis[10] = {0};
    int res = 0, temp = 0;
    int last = 1;
    int flag = 0;
    for (int i = 1;i <= n;i++)
    {
        int v;
        cin >> v;
        if (mp[v] == 1)
            vis[mp[v]]++;
        else if (vis[mp[v]-1]>0)
        {
            vis[mp[v]-1]--;
            vis[mp[v]]++;
        }
    }
    cout << n-6*vis[6] << endl;

    return 0;
}
点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
待兔 待兔
4个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Stella981 Stella981
3年前
Opencv中Mat矩阵相乘——点乘、dot、mul运算详解
Opencv中Mat矩阵相乘——点乘、dot、mul运算详解2016年09月02日00:00:36 \牧野(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fme.csdn.net%2Fdcrmg) 阅读数:59593
Stella981 Stella981
3年前
AndroidStudio封装SDK的那些事
<divclass"markdown\_views"<!flowchart箭头图标勿删<svgxmlns"http://www.w3.org/2000/svg"style"display:none;"<pathstrokelinecap"round"d"M5,00,2.55,5z"id"raphael
Stella981 Stella981
3年前
Comet OJ
题意https://www.cometoj.com/contest/52/problem/C?problem\_id2416(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fwww.cometoj.com%2Fcontest%2F52%2Fproblem%2FC%3Fprob
Stella981 Stella981
3年前
Codeforces Round #611 (Div. 3)
原题面:https://codeforces.com/contest/1283(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fcodeforces.com%2Fcontest%2F1283)A.MinutesBeforetheNewYear题目大意:给定时间,问距离零点
Stella981 Stella981
3年前
CF 833 B. The Bakery
B.TheBakeryhttp://codeforces.com/contest/833/problem/B(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fcodeforces.com%2Fcontest%2F833%2Fproblem%2FB)题
Stella981 Stella981
3年前
Google地球出现“无法连接到登录服务器(错误代码:c00a0194)”解决方法
Google地球出现“无法连接到登录服务器(错误代码:c00a0194)”解决方法参考文章:(1)Google地球出现“无法连接到登录服务器(错误代码:c00a0194)”解决方法(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fwww.codeprj.com%2Fblo
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
10个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这