atcoder(ABC)

题目分析

首先,这道题暴力就能过。时间大概是:( NMK )(NMK)

由于数据都比较小,所以这道题的正解就是暴力。

题目大意

就是给你一个矩阵和一个字符串,让你求有多少个位置出发不会碰到或遇到障碍。

然后操作分为以下几点: L:左 R: L: D

code

#include<bits/stdc++.h>
#define int long long
#define ri register int
#define N 505
#define INF 2147483647
#define f(x,k,y,z) for(int x=k;x<=y;x+=z)
using namespace std;
int n,m,k,jk,ans,sum,num;
char a[N],mp[N][N];
int cnt,tot,dis[N],pop[N],vis[N],f[N],f1[N];
void read(int &x)
{
    x=0;
    char ch=getchar();
    while(ch<'0'||ch>'9') ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return;
}

void write(int x)
{
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
    return;
}

signed main()
{
    read(n),read(m),read(k);
    scanf("%s",a+1);
    for(int i=1;i<=n;i++) scanf("%s",mp[i]+1);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            int x=i,y=j,flag=0;
            if(mp[i][j]=='#') continue;
            for(int g=1;g<=k;g++)
            {
                if(a[g]=='L') y--;
                if(a[g]=='R') y++;
                if(a[g]=='U') x--;
                if(a[g]=='D') x++;
                if(mp[x][y]=='#'||x<1||x>n||y<1||y>m) {flag=1;break;}
            }
            if(flag==0) ans++;
        }
    }
    printf("%d",ans);
    return 0;
}

由于无法直接获取AtCoder ABC比赛的最新题解,可通过AtCoder官方网站(https://atcoder.jp/)查看最新比赛场次及题目,比赛结束后,在社区论坛如AtCoder的Discuss板块、GitHub等地方能找到他人分享的题解。 参考之前不同场次题解示例,例如AtCoder ABC 171 C题,是将一个数N转化为26进制用abc表示,模拟过程需注意细节,其AC代码如下: ```cpp #include<iostream> #include<cstdio> #include <stdio.h> #include<algorithm> #include<cstring> #include<cmath> #include<cstdlib> #include<queue> #include<map> #include<vector> #include <set> #define ll long long using namespace std; char a[5000000]; int main() { ll n; ll c=1; int m=0; cin>>n; while(n>0) { ll k=n%(26); if(k==0) { k=26; a[m++]='z'; } else { a[m++]='a'+k-1; } n=(n-k)/26; } for(int i=m-1;i>=0;i--) { cout<<a[i]; } return 0; } ``` 又如AtCoder ABC183题的AC代码如下: ```cpp #include<iostream> #include<bit/stdc++.h> #include<algorithm> #include<vector> #include<numeric> using namespace std; int main(void) { ios_base::sync_with_stdio(false); int N,W; cin >> N >> W; vector<int64_t> v(300000); for(int i = 0; i < N; i++){ int S, T, P; cin >> S >> T >> P; v[S] += P; v[T] -= P; } partial_sum(v.begin(), v.end(), v.begin()); if(*max_element(v.begin(), v.end()) > W) { cout << "No" << endl; } else { cout << "Yes" << endl; } return 0; } ``` 再如AtCoder ABC 242题解,使用while循环往上跳,每次字符往后移动1或2,开变量记录,时间复杂度为$O(Q\log k)$,代码如下: ```cpp #include <bits/stdc++.h> using namespace std; typedef unsigned long long uLL; typedef long double LD; typedef long long LL; typedef double db; const int N = 100005; int n, Ti; char x[N]; int main() { scanf("%s%d", x + 1, &Ti); n = strlen(x + 1); for (LL a, b, c; Ti--; ) { scanf("%lld%lld", &a, &b); c = 0; while (a && b > 1) { if (!(b & 1)) ++c; ++c; b = b + 1 >> 1, a--; } c += a; printf("%c\n", char((x[b] - 'A' + c) % 3 + 'A')); } } ``` 还有AtCoder ABC237题是签到题,可使用C++的INT_MAX和INT_MIN,若不知这两个常数可自行定义,AC代码如下: ```cpp #include<bits/stdc++.h> using namespace std; typedef long long LL; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); LL n; cin>>n; if (n>=INT_MIN && n<=INT_MAX){ cout<<"Yes\n"; }else{ cout<<"No\n"; } return 0; } ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值