940C链接:http://codeforces.com/problemset/problem/940/C

C. Phone Numbers

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

And where the are the phone numbers?

You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of letters is a subset of the set of letters of s and s is lexicographically smaller than t.

It's guaranteed that the answer exists.

Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {a, b, d}.

String p is lexicographically smaller than string q, if p is a prefix of q, is not equal to q or there exists i, such that pi < qi and for all j < i it is satisfied that pj = qj. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a.

Input

The first line of input contains two space separated integers n and k (1 ≤ n, k ≤ 100 000) — the length of s and the required length of t.

The second line of input contains the string s consisting of n lowercase English letters.

Output

Output the string t conforming to the requirements above.

It's guaranteed that the answer exists.

input

3 3
abc

output

aca

input

3 2
abc

output

ac

input

3 3
ayy

output

yaa

input

2 3
ba

output

baa

Note

In the first example the list of strings t of length 3, such that the set of letters of t is a subset of letters of s is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca.

题意就是给你m长的字符串a,输出在给定字符基础上,输出长度为n且字典序恰好比a大的那个字符串。

似乎没坑,直接模拟!

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+;
char s[maxn];
bool vis[];
int main()
{
int m,n;
while(cin>>m>>n)
{
cin>>s;
memset(vis,false,sizeof(vis));
for(int i=; i<m; i++) vis[s[i]-'a']=true;
if(m<n)
{
for(int i=m; i<n; i++)
{
int f=;
for(int j=; j<=&&f; j++)
{
if(vis[j])
f=,s[i]=j+'a';
}
}
}
else
{
int f=;
for(int i=n-; i>=&&!f; i--)
{
int pos=s[i]-'a';
for(int j=pos+; j<=; j++)
{
if(vis[j])
{
f=;
s[i]=j+'a';
break;
}
}
if(!f)
{
int ff=;
for(int j=; j<=&&ff; j++)
{
if(vis[j])
ff=,s[i]=j+'a';
}
}
}
}
for(int i=;i<n;i++) cout<<s[i];
cout<<endl;
}
return ;
}

932B链接:http://codeforces.com/problemset/problem/932/B

B. Recursive Queries
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Let us define two functions f and g on positive integer numbers.

You need to process Q queries. In each query, you will be given three integers lr and k. You need to print the number of integers x between l and r inclusive, such that g(x) = k.

Input

The first line of the input contains an integer Q (1 ≤ Q ≤ 2 × 105) representing the number of queries.

Q lines follow, each of which contains 3 integers lr and k (1 ≤ l ≤ r ≤ 106, 1 ≤ k ≤ 9).

Output

For each query, print a single line containing the answer for that query.

Examples
input

Copy
4
22 73 9
45 64 6
47 55 7
2 62 4
output

Copy
1
4
0
8
input

Copy
4
82 94 6
56 67 4
28 59 9
39 74 4
output

Copy
3
1
1
5
Note

In the first example:

  • g(33) = 9 as g(33) = g(3 × 3) = g(9) = 9
  • g(47) = g(48) = g(60) = g(61) = 6
  • There are no such integers between 47 and 55.
  • g(4) = g(14) = g(22) = g(27) = g(39) = g(40) = g(41) = g(58) = 4

g(x)函数满足以下性质:  1. g(x)=x  x<=9

           2.g(x)=f(x),  x>9

其中,f(x)函数表示的是,将x数位分离,非零的各个位上的数字相乘.

解题思路:

  第一反应求g(x)时候,记忆化+打表。

  然后看了下查询区间和查询次数的数据范围,打表时候还是把每个数对应的1--9的个数都求出来,每次查询时候直接一次O(1)的访问就差不多了。

 

1A代码:

#include<cstdio>
#include<iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include<cmath>
#define ll long long
using namespace std;
const int maxn=1e6+;
int a[maxn][];
int num[maxn];
int get(int x)
{
if(num[x]!=-) return num[x];
else if(x<=) return x;
else
{
int ans=;
while(x)
{
if(x%!=) ans*=(x%);
x/=;
}
return get(ans);
}
}
void pre()
{
memset(num,-,sizeof(num));
for(int i=;i<=maxn;i++)
num[i]=get(i);
//for(int i=20;i<=30;i++) printf("%d ",num[i]);
for(int i=;i<=;i++) a[][i]=;
a[][]=;
for(int i=;i<=maxn;i++)
{
for(int j=;j<=;j++)
{
a[i][j]=a[i-][j];
}
int cnt=num[i];
a[i][cnt]++;
}
return ;
}
int main()
{
int n,x,l,r;
pre();
while(~scanf("%d",&n))
{
while(n--)
{
scanf("%d%d%d",&l,&r,&x);
if(num[l]==x)
cout<<a[r][x]-a[l][x]+<<endl;
else
cout<<a[r][x]-a[l][x]<<endl;
}
}
return ;
}

CodeForces - 940C + CodeForces - 932B (两道比较好的模拟题)的更多相关文章

  1. Codeforces Round #304 (Div. 2) C. Soldier and Cards —— 模拟题,队列

    题目链接:http://codeforces.com/problemset/problem/546/C 题解: 用两个队列模拟过程就可以了. 特殊的地方是:1.如果等大,那么两张牌都丢弃 : 2.如果 ...

  2. Codeforces Gym 100269B Ballot Analyzing Device 模拟题

    Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election comm ...

  3. Educational Codeforces Round 53 (Rated for Div. 2) (前五题题解)

    这场比赛没有打,后来补了一下,第五题数位dp好不容易才搞出来(我太菜啊). 比赛传送门:http://codeforces.com/contest/1073 A. Diverse Substring ...

  4. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  5. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

  6. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  7. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  8. Codeforces 767B. The Queue 模拟题

    B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  9. Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题

    除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...

随机推荐

  1. Java的GUI设计中如何跨界面传值

    在Java设计中我们会遇到登录界面的信息,在后面的某个情况也需要使用. 比如这是笔者的一个登录界面 可以看到获取密码和账号 在这个时候的功能的完成需要密码和账号 // 登录信息的获取 public S ...

  2. vue+mui轮播图

    mui的轮播图,如果图片是请求来的,直接在html中循环是不会动的. 需要请求完图片之后,在setTimeout方法里,使用slider()方法,这样才会动 而且mui的轮播图,有点坑的,需要重复最后 ...

  3. keepalive主从上同时出现VIP,且均无法消失

    低版本bug 双主架构中,keepalived日志出现: more /var/log/messageOct 9 03:16:22 mysql-dzg-60-148 Keepalived_vrrp[85 ...

  4. Effective C++ 随笔(2)

    条款5 了解c++默默编写并调用哪些函数 编译器自动生成的copy 构造函数,copy赋值操作符,析构函数,构造函数,这些都是public和inline的,此处inline的意思是他们的定义都是在头文 ...

  5. UML(一)下载与安装

    三步 Step1 下载绿色版: http://www.pc6.com/softview/SoftView_64080.html Step2 下载汉化包,(提供一个地址): http://downloa ...

  6. sql_id VS hash_value

    有没有发现,v$session,v$sql,v$sqlarea,v$sqltext,v$sql_shared_cursor等试图连接的时候经常会用到hash_value,sql_id,但是他们2个之间 ...

  7. (转)如何最佳地使用memcached?

    转自:http://os.51cto.com/art/201205/335034_all.htm Memcached是由DangaInteractive开发的,高性能的,分布式的内存对象缓存系统,如何 ...

  8. 20145232 韩文浩 《Java程序设计》第6周学习总结

    教材学习内容总结 Java是以串流(Stream)的方式来处理输入与输出. 串流是一种抽象观念,从键盘输入资料,将处理结果输入档案,以及读取档案的内容等动作皆视为串流的处理. 输入串流代表对象为jav ...

  9. 堆操作,malloc

    PS:堆空间缺省值都是cd,栈空间缺省值都是cc 内存有四区:栈.全局(静态).常量.除此以外的空间暂时不能随意使用,但是通过malloc函数申请就可以使用了. 利用malloc申请一个int变量,注 ...

  10. Hdu1083 Courses

    Courses Problem Description Consider a group of N students and P courses. Each student visits zero, ...