I.找数字个数
链接:https://www.nowcoder.com/acm/contest/67/I
来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
题目描述
lulu喜欢小于等于1000的正整数,但是如果某个数是a或b的倍数,lulu会讨厌这个数。如果某个数里包含了a和b两个数里包含的数,lulu也会讨厌。(例如a=14,b=23,如果数字中包含1、2、3、4这四个数中的任意一个数,lulu就会讨厌这个数)。现在告诉你a,b,你能说出lulu喜欢的数有多少个么。
输入描述:
第一行是样例数T
第2到2+T-1行每行有2个整数a b。
输出描述:
输出lulu喜欢的数的个数
示例1
输入
3
2 3
14 23
1234 5678
输出
171
190
7
说明
a=1234 b=5678的时候,只考虑含有数字9,0的数,只有7个,分别是9,99,999,90,990,909,900
备注:
对于100%的数据,
0 < T <= 20;
0 <= a <= 99999;
0 <= b <= 99999。
emm,做个预处理就直接暴力吧。
#include<bits/stdc++.h>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PI 3.1415926
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
bool num[10];
void find(int a){
while(a){
num[a%10] = false;
a/=10;
}
return ;
}
bool fun(int a){
while(a){
if(!num[a%10]) return false;
a/=10;
}
return true;
}
int main(){
int a,b,t;
cin >>t;
while(t--){
cin>>a>>b;
memset(num,true,sizeof(num));
find(a);
find(b);
ll ans = 0;
for(int i = 1 ; i <= 1000 ; i++)
if(fun(i))
if(i%a!=0 && i%b!=0) ans++;
cout<<ans<<endl;
}
return 0;
}
J.闯关的lulu
链接:https://www.nowcoder.com/acm/contest/67/J
来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
题目描述
勇者lulu某天进入了一个高度10,000,000层的闯关塔,在塔里每到一层楼,他都会获得对应数量的0 1(看情况获得),然后塔里有一个法则,当你身上某个数字达到一个特定的数量时,它们会合成为下一个数字,现在问题来了,当lulu从1层到达第n层的时候,他身上的数字是多少。
第1层 0
第2层 11
第3层 110
第4层 21
第5层 210
第6层 22
第7层 220
第8层 2211
第9层 22110
第10层 2221
第11层 22210
第12层 3
输入描述:
第一行是样例数T(T<100)
第2到2+T-1行每行有一个整数n(0
#include<bits/stdc++.h>
#define PI 3.1415926
#define INF 1e18
#define inf 1e9
#define min(a,b) a<b?a:b
#define max(a,b) a>b?a:b
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
const ll _max = 1e6;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin>>T;
while(T--){
int n;
cin>>n;
ll sum = n+n/2*2;
int i = 0 ;
int t = 2 ;
string s = "";
while(sum >= t){
int ch =sum%t;
for(int k = 1 ; k <= ch ;k++)
s+= ('0'+i);
sum /= t;
i++;
t++;
}
for(int k = 1 ; k <= sum ; k++)
s += ('0'+i);
reverse(s.begin(),s.end());
cout<<s<<endl;
}
return 0;
}