当前位置:网站首页>P1061 [NOIP2006 普及组] Jam 的计数法
P1061 [NOIP2006 普及组] Jam 的计数法
2022-06-22 05:23:00 【hhyy_d】


解题思路:对于每一个字符串,判断第n-1个位置能不能放,如果不能再去前面找,如果可以,就把从当前位置开始,所有的值都往后加一位。这里我用一个map维护数字与字符之间的映射,方便查找。发现规律:倒数第i位数的值不会超过t+1-i。
#include<bits/stdc++.h>
#define MAX 27
using namespace std;
int s,t,w;
vector<int> arr;//存储字符串对应的位置
map<int,char> mp;//维护数字到字符的映射
int cur_index = 0;//计数
void init()
{
for(int i=1;i<=26;i++)
{
mp[i]=char(i+96);
}
}
bool check()
{
//验证当前的序列是否是最大的序列
int size = arr.size();
int temp;//倒数第temp个
for(int i=size-1;i>=0;i--)
{
temp = size-i;
if(arr[i]<t+1-temp)
{
//不是最大的那一个
//cout<<arr[i]<<endl;
return false;
}
}
return true;
}
void find_next()
{
//找到下一个序列
int size = arr.size();
int temp;//倒数第temp个
for(int i=size-1;i>=0;i--)
{
temp = size-i;
if(arr[i]<t+1-temp)
{
//不是最大的那一个
arr[i]+=1;
//从当前位置开始,往后都比前一个大1
for(int j=i+1;j<size;j++)
{
arr[j]=arr[j-1]+1;
}
break;
}
}
}
void fun()
{
if(cur_index>=1)
{
for(int i=0;i<arr.size();i++)
{
cout<<mp[arr[i]];
}
cout<<"\n";
}
if(check()||cur_index>=5)
{
return;
}
find_next();
cur_index+=1;
fun();
}
int main()
{
cin>>s>>t>>w;
char c;
int temp;
for(int i=0;i<w;i++)
{
cin>>c;
temp = int(c)-int('a')+1;
arr.push_back(temp);
}
init();
fun();
return 0;
}
边栏推荐
- Rambbmitmq consumer
- 【云原生】2.2 kubeadm创建集群
- SQL classification, user properties
- Kubernetes - bare metal cluster environment
- In 2022, the third batch (principal) of Guangdong Provincial Safety Officer a certificate was found and analyzed, and the third batch (principal) of Guangdong Provincial Safety Officer a certificate w
- 《双内核实时系统下各个进程间通信方法的性能分析和测试》
- Rambbmitmq Push Party
- C语言概念知识扫盲(不定期补充更新)
- ActiveMQ knowledge summary of Message Oriented Middleware
- Topic selection system of college graduation design based on SSM
猜你喜欢

Rétroaction sur la remise des diplômes! Tous les contributeurs de la communauté Apache Doris sont ici pour recevoir des cadeaux!

Privatized lightweight continuous integration deployment scheme --05- continuous deployment service -drone (Part 1)

Pytest (12) -allure common features allure attach、allure. step、fixture、environment、categories

Understanding of service container, service provider and facade of laravel

JS regular expression to implement the thousands separator

毕业回馈!Apache Doris 社区所有贡献者来领礼品啦!

TIDB-performance overview面板

It's 2022. Don't you hurry to learn typescript?

Free questions for polymerization process and test papers for polymerization process in 2022

Accelerate the promotion of industrial Internet, and map out a new blueprint for development
随机推荐
DeformConv
long start = currentTimeMillis();
毕业回馈!Apache Doris 社区所有贡献者来领礼品啦!
Restframework read and non read sequence processing
89---狄拉克 delta 函数
Detailed explanation of OpenCV function usage 11~20, including code examples
《MATLAB 神经网络43个案例分析》:第29章 极限学习机在回归拟合及分类问题中的应用研究——对比实验
How to remove parentheses in PHP regular
新手开店货源怎么找,怎么找到优质货源?
Analysis of T elevator repair in 2022 and simulation test questions of T elevator repair
Jedispool tool class
MySQL day01 class notes
Pull all data of a branch of the code cloud to cover the local code
Kubernetes - deploy application to cluster
Monorepo Sliding methodology: Reference module Hot Update
The benefits of implementing the standard of intellectual property in Miyun District, Beijing, with a subsidy of 50000-100000 yuan
JS regular expression to implement the thousands separator
Flink deployment mode (II) - three deployment modes of yarn
Graduation season | a new start, no goodbye
JedisSentinel 工具类