AtCoder Beginner Contest 176总结
程序员文章站
2022-06-22 14:45:17
由于打球又鸽了一场,快开学了好好打球(狗头!!!还是补一补A - Takoyaki签到题#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)#pragma GCC optimize(2)#include#includeusing namespace std;int n,x,t;int main(){ cin>>n>>x>...
由于打球又鸽了一场,快开学了好好打球!!!(狗头 还是补一补
A - Takoyaki
签到题
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
using namespace std;
int n,x,t;
int main()
{
cin>>n>>x>>t;
cout<<(n+x-1)/x*t<<endl;
return 0;
}
B - Multiple of 9
第一次打学校比赛的时候就有一个类似的题
不过这题直接把结论告诉了一个数是9的倍数充要条件是十进制下每一位加起来的和是9的倍数
直接让这题称为模拟题
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
string s;
int main()
{
cin>>s;
ll res=0;
for(auto t:s) res+=t-'0';
if(res%9==0) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}
C - Step
记录last
前面最大的数,然后更新答案即可
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=200010;
int a[N],n;
int main()
{
cin>>n;
int last=0;
ll res=0;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++)
{
if(a[i]<last) res+=last-a[i];
else last=a[i];
}
cout<<res<<endl;
return 0;
}
D - Wizard in Maze
双端队列bfs,使用魔法代价为1其他代价为0,更新即可。
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<vector>
#include<set>
#include<map>
#include<deque>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=1010;
pii start,ed;
int n,m;
char g[N][N];
int dist[N][N];
bool st[N][N];
void bfs()
{
memset(dist,0x3f,sizeof dist);
deque<pii> q;
dist[start.x][start.y]=0;
q.push_front(start);
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
while(q.size())
{
auto t=q.front();q.pop_front();
if(st[t.x][t.y]) continue;
st[t.x][t.y]=1;
int d=dist[t.x][t.y];
int a,b;
for(int i=0;i<4;i++)
{
a=t.x+dx[i],b=t.y+dy[i];
if(a<1||b<1||a>n||b>m||g[a][b]=='#'||dist[a][b]<=d) continue;
dist[a][b]=d;
q.push_front({a,b});
}
for(int i=t.x-2;i<=t.x+2;i++)
{
if(i<1||i>n) continue;
for(int j=t.y-2;j<=t.y+2;j++)
{
if(j<1||j>m||g[i][j]=='#'||dist[i][j]<=d+1) continue;
dist[i][j]=d+1;
q.push_back({i,j});
}
}
}
}
int main()
{
cin>>n>>m;
cin>>start.x>>start.y;
cin>>ed.x>>ed.y;
for(int i=1;i<=n;i++) cin>>g[i]+1;
bfs();
if(dist[ed.x][ed.y]==0x3f3f3f3f) cout<<-1<<endl;
else cout<<dist[ed.x][ed.y]<<endl;
return 0;
}
E - Bomber
直接枚举懒得写题解了
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<vector>
#include<set>
#include<map>
#include<deque>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=300010;
int n,m;
int k;
map<pii,int> mp;
int col[N],row[N];
int maxr,maxc;
vector<int> a,b;
int main()
{
cin>>n>>m>>k;
while(k--)
{
int a,b;
cin>>a>>b;
mp[{a,b}]=1;
row[a]++;
col[b]++;
maxr=max(maxr,row[a]);
maxc=max(maxc,col[b]);
}
for(int i=1;i<=n;i++)
if(row[i]==maxr) a.push_back(i);
for(int j=1;j<=m;j++)
if(col[j]==maxc) b.push_back(j);
for(int i=0;i<a.size();i++)
for(int j=0;j<b.size();j++)
if(mp[{a[i],b[j]}]==0)
{
cout<<maxr+maxc<<endl;
return 0;
}
cout<<maxr+maxc-1<<endl;
return 0;
}
F
F不会不知道会不会补。先鸽了
要加油哦~
本文地址:https://blog.csdn.net/Fighting_Peter/article/details/108183318
推荐阅读
-
AtCoder Beginner Contest 173(E 思维模拟 F 容斥 思维题 )
-
AtCoder Beginner Contest 163 D - Sum of Large Numbers(递推&找规律)
-
AtCoder Beginner Contest 182----C. To 3
-
AtCoder Beginner Contest 182----E. Akari
-
AtCoder Beginner Contest 182 题解
-
AtCoder Beginner Contest 182----D. Wandering
-
【Atcoder】Atcoder Beginner Contest 143
-
AtCoder Beginner Contest 176 D-Wizard in Maze(双端队列)
-
AtCoder Beginner Contest 176
-
AtCoder Beginner Contest 176总结