CodeForces - 940C + CodeForces - 932B (两道比较好的模拟题)
940C链接:http://codeforces.com/problemset/problem/940/C
C. Phone Numbers
2 seconds
256 megabytes
standard input
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
2 seconds
256 megabytes
standard input
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 l, r and k. You need to print the number of integers x between l and r inclusive, such that g(x) = k.
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 l, r and k (1 ≤ l ≤ r ≤ 106, 1 ≤ k ≤ 9).
For each query, print a single line containing the answer for that query.
4
22 73 9
45 64 6
47 55 7
2 62 4
1
4
0
8
4
82 94 6
56 67 4
28 59 9
39 74 4
3
1
1
5
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 (两道比较好的模拟题)的更多相关文章
- Codeforces Round #304 (Div. 2) C. Soldier and Cards —— 模拟题,队列
题目链接:http://codeforces.com/problemset/problem/546/C 题解: 用两个队列模拟过程就可以了. 特殊的地方是:1.如果等大,那么两张牌都丢弃 : 2.如果 ...
- Codeforces Gym 100269B Ballot Analyzing Device 模拟题
Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election comm ...
- Educational Codeforces Round 53 (Rated for Div. 2) (前五题题解)
这场比赛没有打,后来补了一下,第五题数位dp好不容易才搞出来(我太菜啊). 比赛传送门:http://codeforces.com/contest/1073 A. Diverse Substring ...
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- 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 ...
- 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 ...
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题
除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...
随机推荐
- How to turn on syntax highlighting in osx
put follow code in ~/.vimrc set ai " auto indenting set history=100 " keep 100 lines of hi ...
- flask框架基础
一 web的一些框架介绍 Flask:短小精悍,内部没有包含多少组件,但是第三方的组件是非常丰富的. Django:django是一个重武器,内部包含了非常多的组件:orm,form,modelFor ...
- 2018.10.24 NOIP模拟 小 C 的序列(链表+数论)
传送门 考虑到a[l],gcd(a[l],a[l+1]),gcd(a[l],a[l+1],a[l+2])....gcd(a[l]...a[r])a[l],gcd(a[l],a[l+1]),gcd(a[ ...
- 在平台中使用JNDI 数据源
有些情况下为了系统的安全性考虑,可以将数据源配置成JNDI,在程序中只需要使用 容器的JNDI路径就可以了. 配置方法 1.在容器中配置数据源 <Context path="/&quo ...
- (17)Questioning the universe
https://www.ted.com/talks/stephen_hawking_asks_big_questions_about_the_universe/transcript00:13There ...
- SpringMVC处理模型数据
目录结构 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi= ...
- canvas打字效果
运用fillText,写的打字效果. 唯一麻烦的地方是,换行问题, 我是把字符串转化为数组,数组一个单位完成,就换行,继续下一个单位. <!doctype html> <html&g ...
- 19-background
先来讲讲颜色表示法 一共有三种:单词.rgb表示法.十六进制表示法 rgb:红色 绿色 蓝色 三原色光学显示器,每个像素都是由三原色的发光原件组成的,靠明亮度不同调成不同的颜色的.用逗号隔开,r.g. ...
- maven之web工程的搭建
参考之前jave application的工程创建的步骤,我们只需要修改最后一步 这样就创建了个web maven工程 与java application应用程序的区别,还有别的区别这里不做多的阐述. ...
- java基础-day27
第04天 java基础加强 今日内容介绍 u Xml的综合案例 u 注解 u 类的加载 u 动态代理 第1章 注解 1.1 注解概述 l 什么是注解:Annotation注解,是一种代码级别的 ...