2024/3/28 DIV4(A-E)

A:

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		if(a<b&&b<c) cout<<"STAIR"<<"\n";
		else if(a<b&&b>c) cout<<"PEAK"<<"\n";
		else cout<<"NONE"<<"\n";
	}
}

B:

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				if((i+j)%2==0) cout<<"##";
				else cout<<"..";
			}
			cout<<"\n";
			for(int j=1;j<=n;j++)
			{
				if((i+j)%2==0) cout<<"##";
				else cout<<"..";
			}
			cout<<"\n";
		}
	}
}

C:

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int a,b;
		scanf("%02d:%02d",&a,&b);
		if(a==0) printf("12:%02d AM\n",b);
		else if(a&&a<12) printf("%02d:%02d AM\n",a,b);
		else if(a==12) printf("%02d:%02d PM\n",a,b);
		else printf("%02d:%02d PM\n",a-12,b);
	}
}

D:

第一次思路理解错题意了

#include<bits/stdc++.h>
using namespace std;
int cnt[100009];
bool check(int x)
{
	while(x)
	{
		int t=x%10;
		if(t>1) return false; 
		x=x/10;
	}
	return true;
}
int main()
{
	for(int i=1;i<=100000;i++)
	{
		if(check(i))
		{
			
			for(int j=i;j*i<=199999;j++)
			{
				if(check(j))
				{
				
					cnt[i*j]++;	
				}	
			}	
		}	
	}
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		if(cnt[n]) cout<<"YES"<<"\n";
		else cout<<"NO"<<"\n";
	}
}

暴力超时了

#include<bits/stdc++.h>
using namespace std; 
int a[32]={1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, 10000, 10001, 10010, 10011, 10100, 10101, 10110, 10111, 11000, 11001, 11010, 11011, 11100, 11101, 11110, 11111, 100000};
bool st[100009];
void bfs()
{
	queue<int>q;
	q.push(1);
	st[1]=1;
	while(q.size())
	{
		auto t=q.front();
		for(int i=0;i<31;i++)
		{
			int x=t+a[i];
			if(x>100000) continue;
			if(st[x]) continue;
			st[x]=1;
		}
	}
}
int main()
{
	bfs();
	int t;
	cin>>t;
	while(t--)
	{
		int x;
		cin>>x;
		if(st[x]) cout<<"YES"<<"\n";
		else cout<<"NO"<<"\n";
	}
}
#include<bits/stdc++.h>
using namespace std; 
int a[32]={1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, 10000, 10001, 10010, 10011, 10100, 10101, 10110, 10111, 11000, 11001, 11010, 11011, 11100, 11101, 11110, 11111, 100000};
bool st[100009];
//dp的优势在于只需要除一次剩下的前面会处理 
int main()
{
	for(int i=0;i<32;i++) st[a[i]]=1;
	for(int i=1;i<=100000;i++)
	{
		if(!st[i])
		{
			for(int j=0;j<32;j++)
			{
				if(i<a[j]) break;
				if(i%a[j]==0&&st[i/a[j]]==1) 
				{
					st[i]=1;
					break;
				}
			}
		}
	}
	int t;
	cin>>t;
	while(t--)
	{
		int x;
		cin>>x;
		if(st[x]) cout<<"YES\n";
		else cout<<"NO\n";
	}
}

E:

超时了

#include<bits/stdc++.h>
using namespace std;
int work(string s)
{
	for(int i=1;i<=s.size();i++)
	{
		if(s.size()%i==0)
		{
			for(int j=0;j<s.size();j+=i)
			{
				string t=s.substr(j,i);
				int cnt=0;
				for(int k=0,p=0;k<s.size();k++,p++)
				{
					p=p%i;	
					if(s[k]!=t[p]) cnt++;
				
				}
				if(cnt<=1)	return i;
			}
		}
	}
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		cout<<work(s)<<"\n";
	}
}
#include<bits/stdc++.h>
using namespace std;
int work(string s)
{
	for(int i=1;i<=s.size();i++)
	{
		if(s.size()%i==0)
		{
		
				int cnt=0;
				for(int p=0;p<i;p++)
				{
					for(int k=p+i;k<s.size();k+=i)
					if(s[k]!=s[p]) cnt++;
				}
				if(cnt<=1)	return i;
				cnt=0;
				for(int p=s.size()-i;p<s.size();p++)
				{
					for(int k=p-i;k>=0;k-=i)
						if(s[k]!=s[p]) cnt++;
				}
				if(cnt<=1)	return i;
		}
	}
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		cout<<work(s)<<"\n";
	}
}//这是官方题解我没想明白为什么对每个长度只取开头和结尾就可以等我想明白了了再回来补上

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<div class="scene-inner" style="--backgroundImage1920:url(https\:\/\/p\.ampmake\.com\/lilibrary\/20220916\/sync20220916\/28fd1387-0e31-48a7-9877-951b8f99a53b\.jpg\@d_progressive); --backgroundImage1024:url(https\:\/\/p\.ampmake\.com\/lilibrary\/892163417397753\/7b4fcb9c-7a9b-477d-abc2-9f7d667536ee\.jpg\@d_progressive); --backgroundImage768:url(https\:\/\/p\.ampmake\.com\/lilibrary\/892162356787600\/46a2e7fd-9735-4bb0-9926-3e861073b2c5\.jpg\@d_progressive); --backgroundImage720:url(https\:\/\/p\.ampmake\.com\/lilibrary\/20220916\/sync20220916\/99f01e42-a3d6-49bf-960b-431e90f222bc\.jpg\@d_progressive);"><div class="product-fadebox top-default active"><div class="product-fadebox-item"><div class="product-model">理想L9 </div></div><div class="product-fadebox-item"><div class="product-title">家庭智能旗舰SUV</div></div><div class="product-fadebox-item"><div class="product-model-image" style="--logo:url(https\:\/\/p\.ampmake\.com\/lilibrary\/650629529518819\/e16dc66a-65c2-4eda-90d0-23721d32d738\.png);"></div></div><div class="product-fadebox-item"><div class="product-buttonlist"><div class="product-button sub firstscreen-button-vr">VR看车</div><div class="product-button main firstscreen-button-buy">预约试驾</div><div class="product-button main firstscreen-button-buy">立即定购</div></div></div><div class="product-fadebox-item"><div class="product-buttonlist"></div></div></div><div class="scene-arrow"><i class="iconfont iconfont-arrowdown"></i></div></div> 是什么意思
07-08

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值