zoukankan      html  css  js  c++  java
  • poj1942(Paths on a Grid)

    题目地址:Paths on a Grid

    题目大意:

        给你一个矩形的格子,让你从左下角走到右上角,每次移动只能向上或者向右,问你有多少种可能的路径。

    解题思路:

         水题,排列组合。推出公式C(m+n,较小的那个数) 

    代码:

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <sstream>
     4 #include <cstdlib>
     5 #include <cstring>
     6 #include <cstdio>
     7 #include <string>
     8 #include <bitset>
     9 #include <vector>
    10 #include <queue>
    11 #include <stack>
    12 #include <cmath>
    13 #include <list>
    14 //#include <map>
    15 #include <set>
    16 using namespace std;
    17 /***************************************/
    18 #define ll long long
    19 #define int64 __int64
    20 #define PI 3.1415927
    21 /***************************************/
    22 const int INF = 0x7f7f7f7f;
    23 const double eps = 1e-8;
    24 const double PIE=acos(-1.0);
    25 const int d1x[]= {0,-1,0,1};
    26 const int d1y[]= {-1,0,1,0};
    27 const int d2x[]= {0,-1,0,1};
    28 const int d2y[]= {1,0,-1,0};
    29 const int fx[]= {-1,-1,-1,0,0,1,1,1};
    30 const int fy[]= {-1,0,1,-1,1,-1,0,1};
    31 const int dirx[]= {-1,1,-2,2,-2,2,-1,1};
    32 const int diry[]= {-2,-2,-1,-1,1,1,2,2};
    33 /*vector <int>map[N];map[a].push_back(b);int len=map[v].size();*/
    34 /***************************************/
    35 void openfile()
    36 {
    37     freopen("data.in","rb",stdin);
    38     freopen("data.out","wb",stdout);
    39 }
    40 priority_queue<int> qi1;
    41 priority_queue<int, vector<int>, greater<int> >qi2;
    42 /**********************华丽丽的分割线,以上为模板部分*****************/
    43 
    44 int main()
    45 {
    46     //zuhe();
    47     long long n,m;
    48     while(scanf("%lld%lld",&n,&m)&&(n+m))
    49     {
    50         long long tt,t;
    51         if (m<n)
    52         {
    53             t=n;
    54             n=m;
    55             m=t;
    56         }
    57         t=n;
    58         tt=m+n;
    59         double ce=1.0;
    60         while(t)
    61         {
    62             ce=(double)(ce*tt)/(double)t;
    63             t--;
    64             tt--;
    65         }
    66         printf("%.0lf
    ",ce);
    67     }
    68     return 0;
    69 }
    View Code
  • 相关阅读:
    this用法
    break/continue的使用
    解决:sql server无法在C盘下创建database/操作系统错误5(拒绝访问)
    (转)科普:SATA、PCIe、AHCI、NVMe
    Java按位取反运算符“~”的工作原理
    <剑指offer> 第12题
    <剑指offer> 第11题
    <剑指offer> 第10题
    <剑指offer> 第9题
    <剑指offer> 第8题
  • 原文地址:https://www.cnblogs.com/ZhaoPengkinghold/p/4002706.html
Copyright © 2011-2022 走看看