1.1200000有多少个约数(只计算正约数)。
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include <set>
#include <queue>
using namespace std;
int main()
{
int ans=0;
int i;
for( i=1;i<sqrt(1200000);i++)
{
if(1200000%i==0)
ans+=2;
}
if(i*i==1200000) ans+=1;
cout<<ans;
return 0;
}
2.在1至2019中,有多少个数的数位中包含数字9?
注意,有的数中的数位中包含多个9,这个数只算一次。例如,1999这个数包含数字9,在计算时只是算一个数。
3.将LANQIAO中的字母重新排列,可以得到不同的单词,如LANQIAO、AAILNOQ等,注意这7个字母都要被用上,单词不一定有具体的英文意义。
请问,总共能排列如多少个不同的单词。
一道全排列的题,先赋给每个字母不同的数字,再用全排列做。
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include <set>
#include <queue>
using namespace std;
int main()
{
string s="1234526";
int ans=0;
sort(s.begin(),s.end());
do{
ans++;
}while(next_permutation(s.begin(),s.end()));
cout<<ans;
}
4.一个包含有2019个结点的无向连通图,最少包含多少条边? 2018
5.一个正整数如果任何一个数位不大于右边相邻的数位,则称为一个数位递增的数,例如1135是一个数位递增的数,而1024不是一个数位递增的数。
给定正整数 n,请问在整数 1 至 n 中有多少个数位递增的数?
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include <set>
#include <queue>
using namespace std;
int check(int x)
{
int a=0;
int last=10;
while(x)
{
if(x%10>last) return a;
else last=x%10;
x=x/10;
}
a=1;
return a;
}
int main()
{
int n;
cin>>n;
int ans=0;
for(int i=1;i<=n;i++)
{
if(check(i)) ans++;
}
cout<<ans;
return 0;
}
就先写到这吧,下次继续补充~~