CCF-CSP_201604(第7次)

1-折点计数


//水题
#include<iostream>
using namespace std;
const int maxn=10000;
int a[maxn];
int main(){
    int n,count=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n-2;i++)
        if((a[i]>a[i-1]&&a[i]>a[i+1])||(a[i]<a[i-1]&&a[i]<a[i+1]))
            count++;
    printf("%d\n",count);
    return 0;
}

2.俄罗斯方块


/* CCF201604-2 俄罗斯方块 */
 
#include <iostream>
 
const int ROW = 15;
const int COL = 10;
const int N = 4;
 
int board[ROW+1][COL];
int block[N][N];
struct {
    int row, col;
} coords[N];
 
using namespace std;
 
int main()
{
    int row, col;
 
    // 输入数据
    for(int i=0; i<ROW; i++)
        for(int j=0; j<COL; j++)
            cin >> board[i][j];
    for(int i=0; i<N; i++)
        for(int j=0; j<N; j++)
            cin >> block[i][j];
    cin >> col;
 
    // 底边全放1
    for(int j=0; j<COL; j++)
        board[ROW][j] = 1;
 
    // 提取小方块坐标
    int k = 0;
    for(int i=N-1; i>=0; i--)
        for(int j=0; j<N; j++)
            if(block[i][j] == 1) {
                coords[k].row = i;
                coords[k].col = j;
                k++;
            }
 
    // 模拟小方块落下过程
    row = 1;
    col--;
    bool checkflag;
    for(;;) {
        checkflag = false;
 
        for(int i=0; i<N; i++)
            if(board[row + coords[i].row][col + coords[i].col] == 1) {
                checkflag = true;
                break;
            }
 
        if(checkflag)
            break;
 
        row++;
    }
    row--;
 
    // 合并小方块到方格
    for(int i=0; i<N; i++)
        board[row + coords[i].row][col + coords[i].col] = 1;
 
    // 输出结果
    for(int i=0; i<ROW; i++) {
        for(int j=0; j<COL; j++) {
            if(j != 0)
                cout << " ";
            cout << board[i][j];
        }
        cout << endl;
    }
 
    return 0;
}
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 1 0 0 
0 0 0 0 0 0 1 0 0 0 
0 0 0 0 0 0 1 0 0 0 
1 1 1 0 0 0 1 1 1 1 
0 0 0 0 1 0 0 0 0 0 
0 0 0 0 
0 1 1 1 
0 0 0 1 
0 0 0 0 
3

0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 1 0 0 
0 0 0 0 0 0 1 0 0 0 
0 0 0 0 0 0 1 0 0 0 
1 1 1 1 1 1 1 1 1 1 
0 0 0 0 1 1 0 0 0 0 

3.路径解析


#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;

int main(){
    int p,flag;
    string s,t;
    
    scanf("%d",&p);
    getchar();//报错点,使用getline()函数前,去掉空白符
    getline(cin,s);//s:当前目录
    for(int i=1;i<=p;i++){
        getline(cin,t);//会读入换行符
        if(t.size()==0){//1.空字符串,正规化为当前目录
            t=s;
        }
        if(t[0]!='/'){  //2.相对路径,不以/符号开头,表示从当前目录开始构建的路径
            t=s+'/'+t;
        }
      
        while(t[t.length()-1]=='/'&&t.length()>1){
            t=t.substr(0,t.length()-1);  //去掉结尾的'/'
        }
        while((flag=(int)t.find("//"))!=-1){
            t.erase(flag,1);//去掉多余的'//'
        }
       
        while((flag=(int)t.find("/./"))!=-1){
            t.erase(flag,2); //.表示本目录
        }
        while((flag=(int)t.find("/../"))!=-1){//..表示上一级目录
            if(flag==0){//根目录为/,相对路径转换后开头为//../
                t.erase(flag,3);
            }else{
                 int count=4;
                 while(flag>=1&&t[flag-1]!='/'){
                     flag--;
                     count++;
                 }
                 t.erase(flag,count);
            }
        }
        cout<<t<<endl;
    }
}
7
/d2/d3
/d2/d4/f1
../d4/f1
/d1/./f1
/d1///f1
/d1/
///
/d1/../../d2
 
/d2/d4/f1
/d2/d4/f1
/d1/f1
/d1/f1
/d1
/
/d2

4.游戏


//bfs
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
const int N = 100;
const int DIRECTSIZE = 4;
struct node {
    int row, col, level;
};
struct direct {
    int drow, dcol;
} direct[DIRECTSIZE] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

int visited[N+1][N+1][300+1];
int n,m;

int bfs()
{
    node start;
    start.row = 1;
    start.col = 1;
    start.level = 0;
    
    queue<node> q;
    q.push(start);
    while(!q.empty()) {
        node front;
        front = q.front();
        q.pop();
       
        if(front.row == n && front.col == m)//到达终点则结束
            return front.level;
        
        for(int i=0; i<DIRECTSIZE; i++) {//四个方向移动一格
            node v;
            v.row = front.row + direct[i].drow;
            v.col = front.col + direct[i].dcol;
            v.level = front.level + 1;
            
            if(v.row < 1 || v.row > n || v.col < 1 || v.col > m) // 行列越界则跳过
                continue;
            if(visited[v.row][v.col][v.level]) // 已经访问过的点不再访问
                continue;
            
            q.push(v);
            visited[v.row][v.col][v.level] = 1;  // 向前搜索:标记v点为已经访问过,v点加入队列中
        }
    }
    
    return 0;
}

int main()
{
    int t, r, c, a, b;
    
    memset(visited, 0, sizeof(visited));
    cin >> n >> m >> t;             //行数、列数、方格图中有危险的方格数量 (1,1)->(m,n)
    for(int i=1; i<=t; i++) {        //(r,c)在(a,b)时刻危险
        cin >> r >> c >> a >> b;
        for(int j=a; j<=b; j++)     // 设置方格危险时间,使之那些时间不可进入
            visited[r][c][j] = 1;
    } 
    int ans = bfs();
    cout << ans << endl; //返回层数,即时间
    
    return 0;
}
3 3 3
2 1 1 1
1 3 2 10
2 2 2 10
 
6

5.无线网络


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值