2025PTA游记
13:30开始的比赛,原计划是16:30结束的, 结果因为前一个小时的服务器问题比赛延长了一个小时。赛前就知道比赛期间不能上厕所,但是对我这种人就是,一般4个小时左右的比赛不上厕所我还是做得到的,但是如果提前告诉我不能上厕所我可能连2个小时都坚持不下来(英语四六级就是最好的例子......)所以从昨天开始就没怎么吃东西,从昨天晚上开始就没喝水,但是我还是好焦虑......
l1-1没啥好说的用python秒了,l1-2一个简单的语法题,l1-3说实话看题目看了半天,一步步模拟写出来了,PTA就喜欢这种莫名其妙的题目,l1-4位运算,l1-5计数遍历一遍即可,l1-6应该算是一个比较麻烦但是不难的大模拟,但是一开始的想法听信了题目的鬼话没当成字符串做,后来发现用字符串可以避免kmp直接调用string的find方法就改用string了,不过这题好像用python更简单(啊啊可惜我对python不熟),l1-7快速幂,l1-8不知道为什么有1个点死活过不去,比赛快结束一直在找bug,因为别的题都不会写了。
l2-1,和栈有关的板子题,不会背。l2-2双指针+二分,但是不知道为什么有一个点过不去。l2-3转换成秒去做,一个简单的前缀和,不需要动态维护的RMQ,l2-4打暴力,过了15/30,不暴力我真不知道咋做了。
赛前一直在做l3,以为自己能ak l1、l2,看来还是低估了PTA难度了。l3-1不会,好像是Floyd板子题。l3-2本来想打表,但是发现打表也很麻烦,不会。l3-3不会。
PTA给我最大的感受就是IO有点神经病,其他的算竞一般都是允许行末空格和末尾换行的,有的时候为了特判最后一行还要专门写个输出缓冲区。真是个无聊的操作。
得分151/290,151都是在比赛的前150分钟获得的,最后延长出来的60分钟就是让我排名下降喽,本来还是全校前3。不过毕竟这是团体比赛,队友比我强还是得夸夸队友嘞!
以下是赛时代码:
t1 代码没拷贝下来 ac
print("?")
t2 ac
#include<stdio.h>
int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
printf("%d\n",a+b+c);
return 0;
}
t3 ac
#include<stdio.h>
using namespace std;
int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a>=35&&b==1&&c>=33) printf("Bu Tie\n%d",a);
else if(a>=35&&c>=33&&b==0) printf("Shi Nei\n%d",a);
else if(b==1&&(a<35||c<33)) printf("Bu Re\n%d",c);
else if((a<35||c<33)&&b==0) printf("Shu Shi\n%d",c);
return 0;
}
t4 ac
#include<stdio.h>
using namespace std;
int main()
{
int n,i;
scanf("%d",&n);
for(i=1;(i<<1)<=n;) i<<=1;
printf("%d\n",i);
return 0;
}
t5 ac
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
int score[30],ans,alpha[30];
string str;
int getscore(char c)
{
return score[c-'a'+1];
}
int main()
{
cin>>str;
for(int i=1;i<=26;++i)
{
scanf("%d",&score[i]);
}
for(int i=0;i<str.length();++i)
{
++alpha[str[i]-'a'+1];
}
for(int i=1;i<=26;++i) printf("%d ",alpha[i]);
printf("\n");
for(int i=1;i<=26;++i) ans+=score[i]*alpha[i];
printf("%d\n",ans);
return 0;
}
t6
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,m,arr[N];
string str;
void modify1()
{
string str1,str2;
int len1,len2;
scanf("%d",&len1);
for(int i=1;i<=len1;++i)
{
int x;
scanf("%d",&x);
str1+='a'+x-1;
}
scanf("%d",&len2);
for(int i=1;i<=len2;++i)
{
int x;
scanf("%d",&x);
str2+='a'+x-1;
}
auto x1=str.find(str1);
//cout<<str<<endl<<str1<<endl<<str2<<endl;
if(x1>str.length()) return;
string strtmp;
for(int i=0;i<x1;++i) strtmp+=str[i];
strtmp+=str2;
for(int i=x1+len1;i<str.length();++i) strtmp+=str[i];
str=strtmp;
}
void modify2()
{
string strtmp;
for(int i=0;i<str.length()-1;++i)
{
strtmp+=str[i];
if((str[i]+str[i+1])%2==0)
{
strtmp+=str[i]+str[i+1]>>1;
}
}
strtmp+=str[str.length()-1];
str=strtmp;
}
void modify3()
{
int l,r;
scanf("%d%d",&l,&r);
--l;--r;
for(;l<=r;++l,--r) swap(str[l],str[r]);
}
void print()
{
for(int i=0;i<str.length()-1;++i)
{
printf("%d ",str[i]-'a'+1);
}
printf("%d ",str[str.length()-1]-'a'+1);
printf("\n");
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)
{
scanf("%d",&arr[i]);
str+='a'+arr[i]-1;
}
while(m--)
{
int op;
scanf("%d",&op);
if(op==1) modify1();
else if(op==2) modify2();
else if(op==3) modify3();
//printf("123:");print();
}
print();
return 0;
}
/*
14 9 2 21 8 21 9 10 21 5 4 5 14 1 26 8 5 14 4 5 2 21 19 8 9 26 9 6 21 3 8 21 1 14 20 9 2 1
14 9 2 21 8 21 9 10 21 5 4 5 14 1 26 8 5 14 4 5 2 21 19 8 9 26 9 6 21 3 8 21 1 14 20 9 2 1
14 9 2 21 8 21 9 10 21 5 4 5 14 1 26 8 5 14 4 5 2 21 19 8 9 26 9 6 21 3 8 21 1 14 20 9 1 2
14 9 2 21 8 21 9 10 21 5 4 5 14 1 26 8 5 14 4 5 2 21 19 8 9 26 9 6 21 3 8 21 1 14 20 9 1 2
14 9 2 21 8 21 9 10 21 5 4 5 14 1 26 8 5 14 4 5 2 21 19 8 9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2
14 9 2 21 8 21 9 10 21 5 4 5 14 1 26 8 5 14 4 5 2 21 19 8 9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2
14 9 2 21 8 21 15 9 10 21 13 5 4 5 14 1 26 17 8 5 14 9 4 5 2 21 20 19 8 9 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2
14 9 2 21 8 21 15 9 10 21 13 5 4 5 14 1 26 17 8 5 14 9 4 5 2 21 20 19 8 9 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2
14 9 8 7 6 5 4 3 2 1 5 9 8 19 20 21 2 5 4 9 14 5 8 17 26 1 14 5 4 5 13 21 10 9 15 21 8 21 2 9 10 11 12 13 14 1 2
14 9 8 7 6 5 4 3 2 1 5 9 8 19 20 21 2 5 4 9 14 5 8 17 26 1 14 5 4 5 13 21 10 9 15 21 8 21 2 9 10 11 12 13 14 1 2
*/
t7 ac
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n;
LL pow_(LL i,LL j)//����i��j�η�
{
LL ans=1,tmp=1;
while(j)
{if(tmp==1) tmp*=i;
else tmp*=tmp;
if(j&1) ans*=tmp;
j>>=1;
}
return ans;
}
int main()
{
scanf("%lld",&n);
//printf("%lld",pow_(3,4));
for(int i=31;i>=1;--i)//i��ʾ����
{
LL sum=0,cnt=0;
for(int j=1;sum<n;++j)
{
sum+=pow_(j,i);
++cnt;
}
if(sum==n)
{
for(int j=1;j<=cnt-1;++j)
{
printf("%lld^%lld+",j,i);
}
printf("%lld^%lld\n",cnt,i);
return 0;
}
}
printf("Impossible for %lld.\n",n);
return 0;
}
t8 18/20wa
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e3+10;
int arr[N][N],n,m,k,idx,f=1;
struct Node
{
int x,y,h;
bool operator < (const Node &W) const
{
return h>W.h;
}
}t[N*N];
signed main()
{
scanf("%lld%lld%lld",&n,&m,&k);
for(int i=1;i<=n;++i)
{
for(int j=1;j<=m;++j)
{
int x;
scanf("%lld",&x);
arr[i][j]=x;
t[++idx]={i,j,x};
}
}
sort(t+1,t+n*m+1);
while(k--)
{
auto out=t[f];
while(arr[out.x][out.y]==0) out=t[++f];
if(arr[out.x][out.y]!=0)//�ǾͿ�ʼ�ݻ�
{
for(int i=1;i<=n;++i) arr[i][out.y]=0;
for(int i=1;i<=m;++i) arr[out.x][i]=0;
}
}
for(int i=1;i<=n;++i)
{
bool flag=0;
queue<int>que;
for(int j=1;j<=m;++j)
{
if(arr[i][j]!=0)
{
que.push(arr[i][j]);
flag=1;
}
}
while(que.size()>=2)
{
auto x=que.front();
que.pop();
printf("%lld ",x);
}
if(flag)
{
auto x=que.front();
printf("%lld",x);
printf("\n");
}
}
return 0;
}
t9 0/25,我知道这是个模板,但我不会背
#include<bits/stdc++.h>
using namespace std;
string str;
stack<int>num;
stack<char>op;
unordered_map<char,int>pri;
bool is_num(char x)
{
return x>='0'&&x<='9';
}
int main()
{
cin>>str;
pri['+']=1;
pri['-']=1;
pri['*']=2;
pri['/']=2;
int tmpnum=0;
for(int i=0;i<str.length();++i)
{
//��дһ�����������ŵ�������......�����Ҽ���...
if(is_num(i)) tmpnum=tmpnum*10+i-'0';
else if()
}
return 0;
}
// 2+3/4+5
t10 26/30
#include<bits/stdc++.h>
using namespace std;
const int N=5e4+10;
int x0[N],x1[N],x2[N],cnt0,cnt1,cnt2,n;
struct Node
{
int a,b,c;
};
queue<Node>que;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
int x,y;
scanf("%d%d",&x,&y);
if(y==0) x0[++cnt0]=x;
else if(y==1) x1[++cnt1]=x;
else if(y==2) x2[++cnt2]=x;
}
sort(x0+1,x0+cnt0+1);
sort(x1+1,x1+cnt1+1);
sort(x2+1,x2+cnt2+1);
bool flag=0;
for(int i=1;i<=cnt0;++i)
{
if(x0[i]==x0[i-1]) continue;
for(int j=1;j<=cnt1;++j)
{
if(x1[j]==x1[j-1]) continue;
int exp=2*x1[j]-x0[i];
//printf("x1:%d,x2:%d,x3:%d\n",x0[i],x1[j],exp);
int l=1,r=cnt2;
while(l<r)
{
int mid=l+r>>1;
if(x2[mid]>=exp) r=mid;
else l=mid+1;
}
//printf(",double stop at%d\n",x2[l]);
if(x2[l]==exp)//��ȷ
{
que.push({x0[i],x1[j],exp});
flag=1;
}
}
}
if(flag==0) printf("-1\n");
else
{
while(que.size()>=2)
{
auto x=que.front();
que.pop();
printf("[%d, %d] ",x.a,0);
printf("[%d, %d] ",x.b,1);
printf("[%d, %d]\n",x.c,2);
}
auto x=que.front();
printf("[%d, %d] ",x.a,0);
printf("[%d, %d] ",x.b,1);
printf("[%d, %d]",x.c,2);
}
return 0;
}
t11 ac
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int t[N];
int getsec(int hh,int mm,int ss)
{
return hh*3600+mm*60+ss;
}
int main()
{
int n,ans=0;
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
int hh,mm,ss;
scanf("%d:%d:%d",&hh,&mm,&ss);
++t[getsec(hh,mm,ss)];
scanf("%d:%d:%d",&hh,&mm,&ss);
--t[getsec(hh,mm,ss)+1];
}
for(int i=1;i<=1e5;++i)
{
t[i]+=t[i-1];
ans=max(ans,t[i]);
}
printf("%d\n",ans);
return 0;
}
t12 过了暴力
#include<bits/stdc++.h>
using namespace std;
const int N=20;
typedef long long LL;
LL pow_(LL i,LL j)//����i��j�η�
{
LL ans=1,tmp=1;
while(j)
{if(tmp==1) tmp*=i;
else tmp*=tmp;
if(j&1) ans*=tmp;
j>>=1;
}
return ans;
}
bool check(LL n,LL k) //n��һ��kλ��
{
for(int i=0,j=k;i<=k-1;++i,--j)
{
LL x=n/pow_(10,i);
if(x%j!=0) return 0;
}
return 1;
}
int main()
{
LL a,b,c;
bool flag=0;
scanf("%lld%lld%lld",&a,&b,&c);
queue<LL>que;
for(int i=b;i<=c;++i)
{
if(check(i,a))
{
que.push(i);
flag=1;
}
}
if(flag==0) printf("No Solution");
else
{
while(que.size()>=2)
{
auto x=que.front();
que.pop();
printf("%lld\n",x);
}
auto x=que.front();
printf("%lld",x);
}
return 0;
}
t13 不想想了
#include<bits/stdc++.h>
using namespace std;
const int N=510;
int e[N*N*2],ne[N*N*2],w[N*N*2],idx=1,h[N],mood[N*N*2];
void add(int a,int b,int c,int d)
{
e[idx]=b;
ne[idx]=h[a];
w[idx]=c;
mood[idx]=d;
h[a]=idx++;
}
int main()
{
int b,n,m,k;
scanf("%d%d%d%d",&b,&n,&m,&k);
for(int i=1;i<=m;++i)
{
int a,b,c,d;
add(a,b,c,d);
add(b,a,c,d);
}
while(m--)
{
}
return 0;
}
t14 0
#include<stdio.h>
using namespace std;
const int N=1e4+10;
int arr[N][N],n,m;
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)
{
for(int j=1;j<=m;++j)
{
scanf("%d",&arr[i][j]);
}
}
}
t15 不会
#include<bits/stdc++.h>
using namespace std;