牛客练习赛31

 

A题(搜索)

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define INF 1e18
using namespace std;
const int mod = 1e9 + 7;
const int MAXN = 1e6 + 10;
int m, n;
string mp[MAXN];
 
void DFS(int x, int y) {
    if (mp[x][y] != '.')return;
    mp[x][y] = '*';
    if (x + 1 < n)DFS(x+1,y);
    if (x - 1 >= 0)DFS(x-1,y);
    if (y + 1 < m)DFS(x,y+1);
    if (y - 1 >=0)DFS(x,y-1);
    return;
}
 
int main() {
    ios::sync_with_stdio(false);
 
    cin >> n >> m;
    forn(i, 0, n - 1)cin >> mp[i];
    forn(i, 0, n - 1)if (mp[i][0] == '.')DFS(i,0);
    forn(i, 0, n - 1)if (mp[i][m-1] == '.')DFS(i,m-1);
    forn(i, 0, m - 1)if (mp[0][i] == '.')DFS(0,i);
    forn(i, 0, m- 1)if (mp[n-1][i] == '.')DFS(n-1,i);
     
    int ans = 0;
    forn(i, 0, n - 1)forn(j, 0, m - 1)if (mp[i][j] != '*')ans++;
 
    cout << ans << endl;
 
    return 0;
}

B题(找规律)

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define INF 1e18
using namespace std;
const int mod = 1e9 + 7;
const int MAXN = 1e6 + 10;
int m, n;
string mp[MAXN];
 
void DFS(int x, int y) {
    if (mp[x][y] != '.')return;
    mp[x][y] = '*';
    if (x + 1 < n)DFS(x + 1, y);
    if (x - 1 >= 0)DFS(x - 1, y);
    if (y + 1 < m)DFS(x, y + 1);
    if (y - 1 >= 0)DFS(x, y - 1);
    return;
}
 
int main() {
    ios::sync_with_stdio(false);
     
    int t; cin >> t;
    while (t--) {
        int n; cin >> n;
        if (n == 1) printf("Kozilek, Butcher of Truth\n");
        else
            printf("Ulamog, the Infinite Gyre\n");
    }
 
    return 0;
}

D题(模拟)

#include <iostream>
#include <bits/stdc++.h>
#include <set>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    string str,com;
    cin>>str>>com;
    string::iterator i=com.begin();

    int ind=0;
    int mod=0;
    while(i!=com.end()){
        char c=*(i++);
        char t;
        int ii;
        if(mod){
            if(c=='e')
                mod=0;
            else str.insert(str.begin()+ind++,c);
            continue;
        }
        switch(c){
            case 'i':mod=1;break;
            case 'f':t=*(i++);
                    ii=ind+1;
                    while(ii<str.size()){
                        if(str[ii]==t){
                            ind=ii;
                            break;
                        }
                        ii++;
                    }break;
            case 'x':str.erase(str.begin()+ind);break;
            case 'l':if(ind<str.size()) ind++;break;
            case 'h':if(ind>0)ind--;break;
            default :break;
        }
    }
    cout<<str<<endl;
    return 0;
}

E题(思维)

#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        if(n==1){
            cout<<"0 0 1 1"<<endl;
            cout<<"0 0 1 0"<<endl;
            continue;
        }
        for(int i=0;i<n-1;i+=2){
            printf("%d %d %d %d\n",i,0,n,n-1-i);
        }
        for(int i=1;i<n-1;i+=2){
            printf("%d %d %d %d\n",0,i,n-1-i,n);
        }
        printf("%d %d %d %d\n",0,n,n,n-1);
        printf("%d %d %d %d\n",n,0,n-1,n);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值