Codeforces #565 Div3 C. Lose it!

Codeforces #565 Div3 C. Lose it!

在这里插入图片描述

这道题是特别好玩的。
题意:保证这个顺序 4,8,15,16,23,42 ,删除其他多余的数据,计算要删除多少个数字,才能保证剩下的数字能组成n套这样的(n≥1);

题解:遍历序列,如果这个数为n,且这个数前面的数字为1,则b[n++],b[前面那个数字]–。
例子:
12
4 8 4 15 16 8 23 15 16 42 23 42
遍历这个序列:
第一个数字是4,则b[4++];
第二个数字是8,则b[8++],b[4–];因为顺序是规定的,所以有8,一定有4。
第三个数字是4,则b[4++];
第四个数字是15,则b[15++],b[8–];
第五个数字是16,则b[16++],b[15–];如果有16一定有15,所以可以用16代替前面的所有数字。
以此类推。(建议在纸上画一下就可以理解了。)

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
 
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define int ll
#define INF 0x3f3f3f3f
using namespace std;
int read()
{
	int w = 1, s = 0;
	char ch = getchar();
	while (ch < '0' || ch>'9') { if (ch == '-') w = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0';    ch = getchar(); }
	return s * w;
//最大公约数
}
int gcd(int x,int y) {
    if(x<y) swap(x,y);//很多人会遗忘,大数在前小数在后
    //递归终止条件千万不要漏了,辗转相除法
    return x % y ? gcd(y, x % y) : y;
}
int lcm(int x,int y)//计算x和y的最小公倍数
{
    return x * y / gcd(x, y);//使用公式
}
//------------------------ 以上是我常用模板与刷题几乎无关 ------------------------//
const int N = 500010;
int a[N], b[45];
signed main()
{
    IOS;
	int n = read();
	if (n < 6) {
	    printf("%lld\n", n % 6);
	    return 0;
	}
	memset(b, 0, sizeof(b));
	for (int i = 1;i <= n;i++) 
	    a[i] = read();
	int res;
	for (int i = 1;i <= n;i++){
	    if (a[i]==4) {
	        b[4]++;
	    }
	    else if (a[i]==8 && b[4]) {
	        b[4]--;
	        b[8]++;
	    }
	    else if (a[i]==15 && b[8]) {
	        b[8]--;
	        b[15]++;
	    }
	    else if (a[i]==16 && b[15]) {
	        b[15]--;
	        b[16]++;
	    }
	    else if (a[i]==23 && b[16]) {
	        b[16]--;
	        b[23]++;
	    }
	  
	    else if (a[i]==42 && b[23]) {
	        b[23]--;
	        b[42]++;
	    }
	}
	res = n - b[42] * 6;
    printf("%lld\n", res);
    return 0;
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值