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";
}
}//这是官方题解我没想明白为什么对每个长度只取开头和结尾就可以等我想明白了了再回来补上