AtCoder Beginner Contest 176 summary

Since we have played another game, school is about to start and play well! ! ! (The dog’s head is still a patch

A --Takoyaki

Sign in question

#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

There was a similar question when I first played a school game,
but this question directly tells the conclusion that a number is a multiple of 9. The necessary and sufficient condition is that the sum of each digit in the decimal system is a multiple of 9
directly. Is a mock question

#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

Record the lastlargest number in front, and then update the answer

#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

Deque bfs, the magic cost is 1 and the other cost is 0, just update.

#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

I'm too lazy to enumerate and write solutions

#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 does not know if it will make up. First pigeon,
come on~

Guess you like

Origin blog.csdn.net/Fighting_Peter/article/details/108183318