solo01

数字游戏

Kimi和Sunny在玩一个数字游戏。游戏规则如下:
(1) 每个人各随机抽取n张写有1-100中某个正整数的卡片,假定卡片的数量不限,随机抽取的数字中可能会有重复数字。
(2) 每一轮游戏双方各亮出一张卡片,卡片上数字大者加1分,数字小者不扣分,相等则都不加分。
(3) n轮游戏后得分高者获胜。
Kimi知道Sunny也很聪明,要想获胜不那么容易。他只想知道在两个人的数字都已经给定的情况下,他最多可以拿到多少分。
现在请你编写一个程序帮帮Kimi。

输入

单组输入。
第1行输入一个正整数n表示每人随机抽取的卡片的数量,n不超过1000。
第2行包含n个1-100之间的正整数表示Kimi抽到的卡片上的数字,两两之间用英文空格隔开。
第3行包含n个1-100之间的正整数表示Sunny抽到的卡片上的数字,两两之间用英文空格隔开。

输出

输出Kimi最多可以得到的分数。

样例输入
5
3 4 5 5 2
1 4 5 3 2
样例输出
4

#include<bits/stdc++.h>
using namespace std;
 
int a[1001];
int b[1001];
 
int main(){
    //这个题,对于kimi的每一张牌,尽量去找到比它小的牌就好,也就是说,尽量去满足他得分的条件,
    //要排个序
 	//没想到
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    int mark=0,i=0,j=0;
    while(i<n){
        if(a[i]>b[j]){
            mark++;
            i++;
            j++;
        } else
            i++;
    }
    cout<<mark<<endl;
    //system("pause");
    return 0;
}

Morse Code

题目描述
Morse code, also known as Morse code, is a kind of on-off signal code, which expresses different English letters, numbers and punctuation symbols through different order. It was invented in 1837 and is an early form of digital communication. Different from modern digital communication, Morse code consists of two basic signals: short point signal “•” and reading “drop”; Keep the long signal “-” for a certain time and read “Da”.
In order to increase the difficulty of decoding, the communication group decided that there must be more than one short message number “•” between every two long signals “-” in Morse code of any length, otherwise it will be regarded as invalid code. For example, the number of schemes of an effective Morse code with a length of 3 is 5, which are respectively: - • -, - • •, • -, • • -, • • •.
Here is the length of Morse code. Do you know the number of effective Morse code schemes?

输入
The input has multiple cases (no more than 100) of test data.
Each test case occupies one line, which is a positive integer N(1 ≤ N ≤ 1000000) represents the length of the Morse code given to you.
The end of input will be represented by a line of test case where A equal to 0. This test case should not be processed.

输出
Each test case outputs a line, which is an integer, that is, the modular result of 2021 by the number of schemes of effective Morse code.

样例输入
2
3
0
样例输出
3
5

别被英文唬住了,就是个递推规律题,记得取模

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

long long a[1000001];

int main(){

    int n;
    a[1]=2;a[2]=3;
    for(int i=3;i<=1000000;i++){
        a[i]=a[i-1]+a[i-2];
        a[i]=a[i]%2021;
    }
        
    while(cin>>n&&n){
        cout<<a[n]<<endl;
    }    
    system("pause");
    return 0;
}

X星危机

最近宇宙局势很乱,X星人感受到了来自Y星的巨大威胁。
X星人决定修建一系列防御工事,X星人首先在一张矩形地图上设计防御工事。
在该地图上,每一个小格称为一个单元。没有修建防御工事的单元用“*”表示,修建了防御工事的单元用“@”表示。多个相邻的防御工事单元(只考虑上、下、左、右相邻)可以连接到一起形成一个防御单元群(当然,也可能存在只有一个防御单元的防御单元群),X星人希望在每一个防御单元群中至少有一个这样一个防御单元,它的上、下、左、右全部都是防御单元,以便用来做指挥部或者存放重要物资。
现在给你一张防御工事地图,你能否编写一个程序统计有多少个满足要求的防御单元群?

`输入
单组输入。
第1行输入两个不超过1000的正整数m和n,表示矩阵的行和列,两者之间用英文空格隔开。
接下来m行,每行包含n个’‘或’@‘,其中’‘表示非防御单元,’@'表示防御单元。

输出
输出两个整数,分别为防御单元群的总个数和满足要求的防御单元群的个数。其中,满足要求的防御单元群是指在该防御单元群中至少存在一个防御单元,其上、下、左、右也是防御单元。

样例输入
5 5
@@@@
@
***
**@@@
**@@@
@@@@@
样例输出
3 1

搜索题
dfs

#include<iostream>
#include<cstring>
using namespace std;
char map[1001][1001];
int num[1001][1001];
int ans[1000000];
int mark=0,count=0;
int n,m;
int dir[][2]={{-1,0},{0,-1},{1,0},{0,1}};

void dfs(int x,int y,int mark){
    int dx,dy;
    if(x<1||x>m||y<1||y>n)return;
    if(num[x][y]>0||map[x][y]!='@')return;
    num[x][y]=mark;
    for (int i=0;i<4;i++){
        dx=x+dir[i][0];
        dy=y+dir[i][1];
        dfs(dx,dy,mark);
    }
}

int main(){

    cin>>m>>n;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            cin>>map[i][j];
        }
    }
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            if(num[i][j]==0&&map[i][j]=='@'){
                dfs(i,j,++mark);
            }
        }
    }
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            if(num[i][j]!=0){
                bool flag=true;
                for (int k=0;k<4;k++){
                    if(num[i+dir[k][0]][j+dir[k][1]]!=num[i][j]){
                        flag=false;
                        break;
                    }
                }
                if(flag)ans[num[i][j]]=1;
            }
        }
    }
    for(int i=1;i<=mark;i++) if(ans[i]) count++;
    cout<<mark<<" "<<count<<endl;
    //system("pause");
    return 0;
}

大佬的dfs:

#include<iostream>
#include<cstring>
using namespace std;
char map[1001][1001];
bool vis[1001][1001];
int ans[1000000];
int mark=0,count=0;
int n,m;
int dir[][2]={{-1,0},{0,-1},{1,0},{0,1}};

bool check(int x,int y){
    if(x<1||x>m||y<1||y>n||map[x][y]=='*')return false;
    return true;
}

int dfs(int x,int y){
    int res=0,k=0;
    int dx,dy;
    for (int i=0;i<4;i++){
        dx=x+dir[i][0];
        dy=y+dir[i][1];
        if(check(dx,dy)&&!vis[dx][dy]){
            vis[dx][dy]=true;
            res |=dfs(dx,dy);
        }
        if(check(dx,dy))k++;
    }
    if(k==4)res=1;
    return res;
}

int main(){

    cin>>m>>n;
    for(int i=1;i<=m;++i){
        scanf("%s",map[i]+1);
    }
    for(int i=1;i<=m;++i){
        for(int j=1;j<=n;++j){
            if(!vis[i][j]&&map[i][j]=='@'){
                mark++;
                count+=dfs(i,j);
            }
        }
    }
    cout<<mark<<" "<<count<<endl;
    //system("pause");
    return 0;
}

tql。。。orz

bfs

#include<iostream>
#include<queue>
using namespace std;
typedef pair<int,int>PII;
char map[1001][1001];
bool vis[1001][1001];


int mark=0,count=0;
int n,m;
int dir[][2]={{-1,0},{0,-1},{1,0},{0,1}};

bool check(int x,int y){
    if(x<1||x>m||y<1||y>n||map[x][y]=='*')return false;
    return true;
}

int bfs(int x,int y){
    queue<PII>q;
    q.push({x,y});
    vis[x][y]=true;
    bool ok=false;
    while(!q.empty()){
        PII u=q.front();
        q.pop();
        int x=u.first;
        int y=u.second;
        int k=0;
        for (int i=0;i<4;i++){
            int dx=x+dir[i][0];
            int dy=y+dir[i][1];
            if(check(dx,dy)&&!vis[dx][dy]){
            q.push({dx,dy});
            vis[dx][dy]=true;
            }
            if(check(dx,dy))k++;
        }
    if(k==4)ok=true;
    }
   if(ok)return 1;
   else return 0;
}

int main(){

    cin>>m>>n;
    for(int i=1;i<=m;++i){
        scanf("%s",map[i]+1);
    }
    for(int i=1;i<=m;++i){
        for(int j=1;j<=n;++j){
            if(!vis[i][j]&&map[i][j]=='@'){
                mark++;
                count+=bfs(i,j);
            }
        }
    }
    cout<<mark<<" "<<count<<endl;
    //system("pause");
    return 0;
}

后续再补充了,得去学搜索了

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是君倩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值