CSP 202112-3 登机牌条码【求助为什么是80分】

题目链接:TUOJ 

#include<bits/stdc++.h>
#define endl "\n"
#define int long long
using namespace std;
#define N 300010
const int mod = 929;
int w, s;
int mo = 0, k;
int cnt = 0;
bool f = 0;
char t[3] = {'A', 'a', '0'};
int d[10000], g[10000][2];
int check(char t)
{
	if (t >= 'A' && t <= 'Z')return 0;
	if (t >= 'a' && t <= 'z')return 1;
	if (t >= '0' && t <= '9')return 2;
	return 2;
}
void doo(int k)
{
	if (f == 0)
	{
		d[cnt] = k;
		f = 1;
	}
	else
	{
		d[cnt] *= 30;
		d[cnt] += k;
		cnt++;
		f = 0;
	} 
}
void solve()
{
	cin >> w >> s; //有效数据区每行能容纳的码字数和校验级别
	string stri;
	k = pow(2, s + 1);
	if (s == -1)k = 0;
	cin >> stri;
	int len = stri.size();
	cnt = 1;
	for (int i = 0; i < len; i++)
	{
		int now_mo = check(stri[i]);
		if (mo == 1 && now_mo == 0) //两次
		{
			doo(28);
			doo(28);
			mo = now_mo;
		}
		else if (mo != now_mo) //一次
		{
			int k = 28;
			if (now_mo == 1)k = 27;
			doo(k);
			mo = now_mo;
		}
		//不换
		doo(stri[i] - t[mo]);

	}
	if (f == 1)
	{
		doo(29);
	}
	while ((cnt + k) % w != 0)
	{
		doo(30);
		doo(0);
	}
	int t = k;
	while (t--)
	{
		doo(0);
		doo(0);
	}
	d[0] = cnt - k;
	cnt--;
	for (int i = 0; i <= (cnt - 1) / 2; i++)
	{
		d[i] += d[cnt - i];
		d[cnt - i] = d[i] - d[cnt - i];
		d[i] = d[i] - d[cnt - i];
	}
	// 
	if (s == -1)
	{
		for (int i = cnt; i >= 0; i--)
		{
			cout << d[i] << endl;
		}
		return ;
	}
	//
	//cout<<k<<endl;
	int b = -3;
	g[1][1] = 1;
	g[0][1] = -3;
	for (int i = 2; i <= k; i++)//0-k
	{
		b *= 3;
		for (int j = 0; j <= i; j++)
		{
			g[j][0] = g[j][1] % mod;
			g[j][1] = 0;
		}
		for (int j = 0; j < i; j++)
		{
			g[j + 1][1] += g[j][0];
		}
		for (int j = 0; j <= i; j++)
		{
			g[j][1] += g[j][0] * b % mod;
		}
	}
	for (int i = cnt; i >= k; i--)
	{
		cout << d[i] << endl;
	}
	while (cnt >= k)
	{
		int bei = d[cnt] % mod;
		if (bei == 0)
		{
			cnt--;
			continue;
		}
		for (int j = k; j >= 0; j--)
		{
			d[cnt - k + j] -= bei * g[j][1] % mod;
			d[cnt - k + j] %= mod;
		}
		cnt--;
	}
	for (int i = cnt; i >= 0; i--)
	{
		cout << ((mod - d[i]) % mod + mod) % mod << endl;
	}
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	while (t--)
	{
		solve();
	}
	return 0;
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值