7.29河西J2训练课day05 课后总结
Score
一坨
T1:100分,用时30s
T2:20分,用时1分钟
T3:10分,用时20分钟
T4:75分,用时20分钟
T5:0分,用时60分钟
又™垫底了/(ㄒoㄒ)/~~
解析
T1
题意:把一串数字中的
思路:字符串遍历一遍即可。
代码:
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
cin>>s;
for(int i=0;i<s.size();i++)
{
if(s[i]=='4') s[i]='8';
}
cout<<s;
return 0;
}
总结:水题
T2
题意:给出
思路:每颗雷旁边八格全部 INT_MIN就行了,最后判断的时候记得判断是
代码:
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int mp[510][510];
int n,m,q;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>q;
while(q--)
{
int x,y;
cin>>x>>y;
mp[x][y]=INT_MIN;
mp[x-1][y-1]++;
mp[x-1][y]++;
mp[x-1][y+1]++;
mp[x][y-1]++;
mp[x][y+1]++;
mp[x+1][y-1]++;
mp[x+1][y]++;
mp[x+1][y+1]++;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(mp[i][j]<0)
{
cout<<"* ";
}
else
{
cout<<mp[i][j]<<" ";
}
}
cout<<endl;
}
return 0;
}
总结:暴力,开始写的时候最后一项忘记写++,痛失35分……
T3
题意:
思路:尽量两两一组,利用双指针优化,如果不能则把 r--即可。
代码:
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=3e4+5;
int w,n,p[N],t[205],cnt=0;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>w>>n;
for(int i=1;i<=n;i++)
{
cin>>p[i];
}
sort(p+1,p+1+n);
int l=1,r=n;
while(l<=r)
{
if(p[l]+p[r]<=w) l++,r--,cnt++;
else r--,cnt++;
}
cout<<cnt<<endl;
return 0;
}
总结:开始时没想到可以用双指针。其实想对方向还是蛮简单的。
T4
题意:如果一个数
思路:埃氏筛+前缀和预处理,优化时间复杂度,然后输出
代码:
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=1e5+5;
bool t[N];
int s[N];
void eop()
{
t[0]=t[1]=1;
for(int i=2;i*i<=1e5;i++)
{
if(t[i]==0)
{
for(int j=2;j*i<=1e5;j++) t[i*j]=1;
}
}
return ;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
eop();
int cnt=0;
for(int i=2;i<=1e5;i++)
{
s[i]=s[i-1];
if(t[i]==0&&t[(i+1)/2]==0)
{
s[i]++;
}
}
int n;
cin>>n;
while(n--)
{
int l,r;
cin>>l>>r;
cout<<s[r]-s[l-1]<<endl;
}
return 0;
}
总结:不搞前缀和会TLE,痛失25分……
T5
题意:
藏宝楼共有
寻宝说明书的最后用红色大号字体写着:“寻宝须知:帮助你找到每层上楼房间的指示牌上的数字(即每层第一个进入的房间内指示牌上的数字)总和为打开宝箱的密钥”。
思路:结构体储存房间信息,让需求等于本层有多少楼梯房,然后循环,如果遇到的楼梯房数量等于需求,那么跳出前往下一层并让总和增加。
优化:需求其实可以对
代码:
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
struct l
{
int lt,pz;
};
l room[10005][105];
int cnt[10005],ans=0,n,m;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=0;j<m;j++)
{
cin>>room[i][j].lt>>room[i][j].pz;
cnt[i]+=room[i][j].lt;
}
}
int dq;
cin>>dq;
for(int i=1;i<=n;i++)
{
ans=(room[i][dq].pz+ans)%20123;
int xq=room[i][dq].pz%cnt[i],res=0;
if(xq==0) xq=cnt[i];
while(1)
{
if(room[i][dq].lt==1) res++;
if(xq==res) break;
dq=(dq+1)%m;
}
}
cout<<ans<<endl;
return 0;
}
总结
依旧一坨,看来需要注重下墨菲定律。
哎其实没事,洛谷运势告诉我今日宜装弱,众所周知谦虚是美德。