• hdu6229 Wandering Robots 2017沈阳区域赛M题 思维加map


    题目传送门

    题目大意:

    给出一张n*n的图,机器人在一秒钟内任一格子上都可以有五种操作,上下左右或者停顿,(不能出边界,不能碰到障碍物)。题目给出k个障碍物,但保证没有障碍物的地方是强联通的,问经过无限长的时间后,停留在所有(x,y)(x+y>=n-1)的概率有多大。

    思路:

    概论题看上去很恐怖,但其实想到了就很简单。

    先考虑没有障碍物的情况,由于是无限长的时间,那么最开始的时间机器人的走法是不会影响最终答案的,所以经过比较短的时间后,机器人可以出现在图上的任意地方,在这个时候到下一秒,机器人在不同格子能操作的数量是一个类似下面这个矩阵,而对于一个格子,能到这个格子的情况也是下面这个矩阵。

    34443

    45554

    45554

    45554

    34443

    也就是说,到下一秒的总情况数量就是上面这个矩阵的sum,合法的区域就是右下角这块的sum,在没有障碍物的情况下,概率就是这样了。

    现在考虑上障碍物,一个格子放上障碍物,如果他旁边的格子没有障碍物,那么总情况就减少从其他格子到这个格子的情况,和从这个格子到其他格子的情况,如果旁边有障碍物,则不会有从其他格子到这个格子的情况,所以只要减去本身就可以了(事实上,没有减去这个1是因为在计算旁边的障碍物时已经减去了)。也就是分母减去(self+tot),tot为旁边的障碍数。

    最后算一下gcd就可以了。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<string.h>
     6 #include<sstream>
     7 #include<set>
     8 #include<map>
     9 #include<vector>
    10 #include<queue>
    11 #include<stack>
    12 #include<bitset>
    13 #define CLR(a,b) memset(a,b,sizeof(a))
    14 using namespace std;
    15 typedef long long ll;
    16 inline int rd() {
    17     int f = 1;
    18     int x = 0;
    19     char s = getchar();
    20     while (s<'0' || s>'9') {
    21         if (s == '-')f = -1;
    22         s = getchar();
    23     }
    24     while (s >= '0'&&s <= '9') {
    25         x = x * 10 + s - '0';
    26         s = getchar();
    27     }
    28     x *= f;
    29     return x;
    30 }
    31 ll n,p,q;
    32 inline ll gcd(ll a,ll b) {
    33     if(b==0)return a;
    34     return gcd(b,a%b);
    35 }
    36 int k;
    37 map<pair<int ,int >,int >mp;
    38 int fx[4][2]= {{0,1},{0,-1},{1,0},{-1,0}};
    39 int check(int x,int y) {
    40     if((x==0||x==n-1)&&(y==0||y==n-1))  return 3;
    41     if((x==0||x==n-1)&&(y!=0&&y!=n-1))  return 4;
    42     if((y==0||y==n-1)&&(x!=0&&x!=n-1))  return 4;
    43     return 5;
    44 }
    45 int main() {
    46     int x,y;
    47     int T,cas=1;
    48     cin>>T;
    49     while(T--) {
    50         scanf("%lld%d",&n,&k);
    51         mp.clear();
    52         p=((3*4)+((n-2)*4*4)+(n-2)*(n-2)*5);   //分母
    53         q=((3*3)+((n-2)*2*4)+((n-2)*(n-1)/2*5));  //分子 
    54         while(k--) {
    55             scanf("%d%d",&x,&y);
    56             mp[make_pair(x,y)]=1;
    57         }
    58         for(auto it:mp) {
    59             x=it.first.first;
    60             y=it.first.second;
    61             p-=check(x,y);
    62             if( x + y >= n - 1 )q -= check(x,y);
    63             for(int i=0; i<4; i++) {
    64                 int xx = x + fx[i][0],yy = y+fx[i][1];
    65                 if(xx<0||yy<0||xx>=n||yy>=n)continue;
    66                 if(!mp.count(make_pair(xx,yy))) {
    67                     p -= 1;
    68                     if(xx + yy >= n-1) {
    69                         q -= 1;
    70                     }
    71                 }
    72             }
    73         }
    74         ll g=gcd(p,q);
    75         printf("Case #%d: %lld/%lld
    ",cas++,q/g,p/g);
    76     }
    77 }
    View Code

    Wandering Robots

    Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
    Total Submission(s): 466    Accepted Submission(s): 239


    Problem Description
    In an attempt to colonize Mars, some scientists were tasked with cleaning the planet. A cleaning robot, Marsba,was build with a huge restricted area in the Mars as a massive N × N square grid with K (K ≤ 1000) impassable barriers. This area are numbered from (0, 0) to (N - 1, N - 1) sequentially from left to right, row by row, where N ≤ 10000. The starting point of Marsba is situated on the top left corner lattice (0, 0). Marsba had instructions to program him with equal probability of remaining in the same lattice or travelling to an adjacent one. (Two lattices are said to be adjacent if they share a common edge.) This meant an equal probability being split equally between remaining in the lattice and the number of available routes. Specifically, for the lattice Marsba located in which has d adjacent lattices without impassable barriers, the probability for Marsba of remaining in the lattice or travelling to any adjacent lattice is frac{1}{d+1} .
    Then, those scientists completely forgot about it.
    Many millennia ago, a young man realizes the importance of the cleaning robot, Marsba, at the end of the forgotten.
    For further research, he asks you to calculate the probability of Marsba’s location (x, y) satisfying x + y ≥ N - 1.
    Let the probability be an irreducible fraction of the form p/q, you should output p and q respectively, with a fraction slash as the separator.
     
    Input
    The first line of the input contains an integer t (t ≤ 1000) specifying the number of test cases.
    For each case, the first line contains two positive integers N and K. Each of the next K lines contains the coordinate of a barrier.
    Note that the starting point (0, 0) has no barrier and all test cases guarantee the connectivity of all lattices free of barriers.
     
    Output
    For each case output its label first, then output the probability as an irreducible fraction.
     
    Sample Input
    5 3 0 3 1 1 1 3 2 1 1 2 2 3 3 1 1 1 2 2 2 5 4 1 1 1 2 2 3 3 2
     
    Sample Output
    Case #1: 2/3 Case #2: 5/8 Case #3: 10/19 Case #4: 7/16 Case #5: 43/71
  • 相关阅读:
    Oracle自带的sql developer导入导出数据
    LSMW批处理工具操作手册
    JS控制TABLE表格在任意一行下面添加一行(有待完善)
    SAP销售模块塑工常见问题和解决方案(自己收藏)
    SAP采购订单历史明细报表源代码(自己收藏)
    SAP公司间采购订单关联交货单报表源代码(自己收藏)
    《嵌入式系统可靠性设计技术及案例解析》读书笔记(七)
    《嵌入式系统可靠性设计技术及案例解析》读书笔记(六)
    《嵌入式系统可靠性设计技术及案例解析》读书笔记(五)
    《嵌入式系统可靠性设计技术及案例解析》读书笔记(四)
  • 原文地址:https://www.cnblogs.com/mountaink/p/9543423.html
Copyright © 2020-2023  润新知