AtCoder Beginner Contest 215

  • Post author:
  • Post category:其他



https://atcoder.jp/contests/abc215/tasks/abc215_b

求小于等于n的最大的2的倍数,n最大为1e18

有精度问题,不能直接用pow或者log2+floor函数,要用for循环模拟。

好吧,pow函数可以,但偷懒用log2+floor函数就会wa

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#define ll long long
#define ull unsigned long long
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--) 
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
inline ll read()
{	
	ll x=0,w=1; char ch=0;ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')w=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*w;
}
inline void print(ll x)
{
	if(x<0){x=-x;putchar('-');}
	if(x>9)print(x/10);
	putchar(x%10+48);
}		
ll n;
int main()
{
	ios
	cin>>n;
	for(int i=1;i<=63;i++)
	{
		ll tmp=1;
		for(int j=1;j<=i;j++)
		{
			tmp=tmp*2;
		}
		if(tmp>n)
		{
			cout<<i-1;
			break;
		}
	}
	return 0;
}


https://atcoder.jp/contests/abc215/tasks/abc215_c

给你一串字符串,字符串长度最多为8,求他字典序第k的组合。

有一个函数叫  next_permutation  可以求下一个组合

可以看这个

https://blog.csdn.net/yueloveme/article/details/47164529?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522162961111216780264060338%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=162961111216780264060338&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-1-47164529.pc_search_all_es&utm_term=next_permutation%E5%87%BD%E6%95%B0&spm=1018.2226.3001.4187

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#define ll long long
#define ull unsigned long long
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--) 
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
inline ll read()
{	
	ll x=0,w=1; char ch=0;ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')w=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*w;
}
inline void print(ll x)
{
	if(x<0){x=-x;putchar('-');}
	if(x>9)print(x/10);
	putchar(x%10+48);
}		
char str[1005]; int k;
int main()
{
	ios
	cin>>str;
	cin>>k;
	int len=strlen(str);
	sort(str,str+len);
	k--;
	rep(i,1,k)next_permutation(str,str+len);
	cout<<str;
	return 0;
}


https://atcoder.jp/contests/abc215/tasks/abc215_d

给你两个数n,m,n,m<1e5;

问你在1-m中,有多少个数满足对所有给定的n个数,都满足__gcd()=1;

我们可以先处理出每个数n所有的因数,用桶存储以去重,然后把每个数的在1到1e5的倍数的范围内的倍数筛掉,剩下的数就和给定的数n没有因数了。由于1是肯定和每个数都满足__gcd()=1的,所以我们可以直接输出1,同时令统计的cnt++即可。

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#define ll long long
#define ull unsigned long long
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--) 
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
inline ll read()
{	
	ll x=0,w=1; char ch=0;ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')w=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*w;
}
inline void print(ll x)
{
	if(x<0){x=-x;putchar('-');}
	if(x>9)print(x/10);
	putchar(x%10+48);
}	
bool ton[100005];	
int  n,m,a,num[100005];
bool ans[100005];
int main()
{
	ios
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		int pre[1005],top=0;
		for(int j=2;j*j<=a;j++)
		{
			while(a%j==0)
			{
				pre[++top]=j;
				a/=j;
			}
		}
		if(a)pre[++top]=a;
		for(int j=1;j<=top;j++)
		{
			ton[pre[j]]=1;
		}
	}
	int topt=0;
	for(int i=2;i<=100002;i++)
	{
		if(ton[i]==1)num[++topt]=i;
	}
	//rep(i,1,topt)cout<<num[i]<<' ';
	for(int i=1;i<=topt;i++)
	{
		for(int j=1;num[i]*j<=1e5+2;j++)
		{
			ans[num[i]*j]=1;
		}
	}
	int cntans=0;
	for(int i=2;i<=m;i++)
	{
		if(ans[i]==0)cntans++;
	}
	cout<<cntans+1<<endl;
	cout<<1<<endl;
	for(int i=2;i<=m;i++)
	{
		if(ans[i]==0)cout<<i<<endl;
	}
	return 0;
}



版权声明:本文为yzrcdw原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。