zoukankan      html  css  js  c++  java
  • 第二次作业

    题意:从(0,0)走到(n-1,n-1)有多少钟走法,并且只能在右上三角走,只能
    向右和下走!

    #include<iostream>
    #include<string.h>
    using namespace std;
    int res,n;
    void dfs(int p,int q){
        if(p>=n||q>=n) return ;
        if(p==n-1&&q==n-1)
            res++;
        else{
            if(p+1<=q)
                dfs(p+1,q);
            if(p<=q+1)
                dfs(p,q+1);
        }
    }
    int main(){
        cin>>n;
        res = 0;
        dfs(0,0);
        cout<<res<<endl;
        return 0;
    }

     /*501.合并排序 (10分)
    C时间限制:3000 毫秒 |  C内存限制:3000 Kb
    题目内容:
    使用合并排序算法编程,对整数数组排序
    输入描述
    第一行输入元素个数,第二行输入要排序的数组
    输出描述
    排好序的数组
    输入样例
    7
    2 5 4 1 3 7 6
    输出样例
    1 2 3 4 5 6 7
    */

    #include<iostream>
    #include<stdio.h>
    #include<string.h>
    using namespace std;
    const int maxn = 1e3+10;
    int a[maxn];
    void paixu(int l,int mid,int r){
        int L[maxn],R[maxn];
        int ss=l;
        memset(L,0,sizeof(L));
        memset(R,0,sizeof(R));
        int j1=0,j2=0;
        for(int i=l;i<=mid;i++){
            L[j1++] = a[i];
        }    
        for(int i=mid+1;i<=r;i++){
            R[j2++] = a[i];
        }    
        int j =0,i=0 ;
        while(i<j1&&j<j2){
            if(L[i]<R[j]){
                a[l++] = L[i++];
    
            }
            else{
                a[l++] = R[j++];
            }
        }
        
        while(i<j1)
            a[l++] = L[i++];
        while(j<j2){
            a[l++] = R[j++];
        }
            
        l--;
        
    }
    
    void merge(int s,int e){
        if(s==e)
            a[s]=a[e] ;
        else{
            int mid = (s + e)/2;
            merge(s,mid);
            merge(mid+1,e);
            paixu(s,mid,e);
        }
        
    }
    
    int main(){
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        merge(1,n);
        for(int i=1;i<=n;i++)
            printf("%d ",a[i]);
        return 0;
    }
  • 相关阅读:
    入门OJ 1278【关系网络】
    HDU 1372【Knight Moves】
    ZOJ 1047【Image Perimeters】
    log4J——在Spring中的使用
    实用性很强的文章(不来源于博客园)
    详解AOP——用配置文件的方式实现AOP
    Spring与Web项目整合的原理
    IOC——Spring的bean的管理(注解方式)
    IOC——Spring的bean的管理(xml配置文件)
    关于XML文件
  • 原文地址:https://www.cnblogs.com/lusiqi/p/11601580.html
Copyright © 2011-2022 走看看