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

链接:

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;
}

原文地址:https://www.cnblogs.com/YDDDD/p/10998734.html

时间: 2024-10-11 19:30:03

Codeforces Round #565 (Div. 3) C. Lose it!的相关文章

Codeforces Round #565 (Div. 3) B

B. Merge it! 题目链接:http://codeforces.com/contest/1176/problem/B 题目 You are given an array a consisting of n integers a1,a2,…,an In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not

Codeforces Round #565 (Div. 3) A

A. Divide it! 题目链接:http://codeforces.com/contest/1176/problem/A 题目 You are given an integer n You can perform any of the following operations with this number an arbitrary (possibly, zero) number of times: Replace n with n2 if n is divisible by 2;Rep

Codeforces Round #565 (Div. 3)

传送门 A. Divide it! •题意 给定一个数n, 每次可以进行下列一种操作 1.如果n可以被2整除,用n/2代替n 2.如果n可以被3整除,用2n/3代替n 3.如果n可以被5整除,用4n/5代替n 如果可以经过上述操作使得 n 变为 1,输出最小操作次数,反之,输出-1: •思路 n/2 < 2n/3 < 4n/5 要想操作次数最少,优先操作 1 > 2 > 3: •代码 #include<bits/stdc++.h> using namespace std

Codeforces Round #565 (Div. 3) E. Cover it!

题目:https://codeforces.com/contest/1176/problem/E 思路:奇偶染色 #include<bits/stdc++.h> using namespace std; #define DEBUG cout<<"DEBUG"<<endl typedef long long ll; typedef unsigned long long ull; typedef pair<int,int>pii; typed

Codeforces Round #315 (Div. 1)

A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and un

CodeForces 360E Levko and Game(Codeforces Round #210 (Div. 1))

题意:有一些无向边m条权值是给定的k条权值在[l,r]区间可以由你来定,一个点s1 出发一个从s2出发  问s1 出发的能不能先打到f 思路:最短路. 首先检测能不能赢 在更新的时候  如果对于一条边 a->b  如果dis1[a] <dis2[a]  那么选择这条边就选择   l  因为这条边对于s1有利 如果两个起点都选择了这条边  则说明s1 赢定了,所以要让他们尽量走这条,所以边权越小越好.跑完之后检测 如果  dis1[f]<dis2[f] 那么 就赢了. 接下来判断能不能平局

Codeforces Round #258 (Div. 2) A. Game With Sticks(数学题)

题目链接:http://codeforces.com/contest/451/problem/A ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943/ma

Codeforces Round #258 (Div. 2/A)/Codeforces451A_Game With Sticks

解题报告 http://blog.csdn.net/juncoder/article/details/38102263 n和m跟木棍相交,问一人取一交点(必须是交点,且取完后去掉交点的两根木棍),最后谁赢 思路: 取最大正方形,以对角线上的交点个数判断输赢. #include <iostream> #include <cstdio> using namespace std; int main() { int m,n; while(cin>>n>>m) { i

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i