HDU-6229 ICPC-沈阳M- Wandering Robots 概率
题意:
在一个n*n的地图中,有一个初始在(0,0)位子的机器人,每次等概率的向相邻的格子移动或者留在原地。问最后留在格子(x,y)(x+y>=n-1)的地方的概率。
思路:
这道题由于每个格子的贡献是不同的,在四个角格子的贡献是3分(留下来,两个边来的),中间的5分,有一条边与边相连的4分。如果这个点是障碍物,则把这个点的贡献抹为0,再把其四周的格子贡献-1.
由于开不下数组,可以用map
// #pragma GCC optimize(3)
// #pragma comment(linker, "/STACK:102400000,102400000") //c++
// #pragma GCC diagnostic error "-std=c++11"
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>
#include <map> using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
#define max3(a,b,c) max(max(a,b), c);
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x7f7f7f7f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e8+;
const double esp = 1e-;
const double PI=acos(-1.0);
const double PHI=0.61803399; //黄金分割点
const double tPHI=0.38196601; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} /*-----------------------showtime----------------------*/
map<pii,int>mp;
int nx[][] = {
{,}, {,} ,{-,},{,-}
};
int T,n,k;
int get(int x,int y){
if(x>&&x<n- && y> && y<n-)
return ;
if(x==&&y==)return ;
if(x==n-&&y==)return ;
if(x==&&y==n-)return ;
if(x==n-&&y==n-)return ;
return ;
}
ll gcd(ll a, ll b){
if(b == )return a;
return gcd(b, a % b);
}
int main(){
scanf("%d", &T);
for(int tt=; tt<=T; tt++){
mp.clear();
scanf("%d%d", &n, &k);
if(n == ){
printf("Case #%d: 1/1\n", tt);
continue;
} ll sum = *+(n-)**+(n-)*(n-)*;
ll dec = ;
ll up = *+(n-)**+(n-)*(n-)/*; for(int i=; i<=k; i++){
int x,y;
scanf("%d%d", &x, &y); for(int i=; i<; i++){
int tx = x + nx[i][];
int ty = y + nx[i][];
if(tx < || tx >= n||ty<||ty>=n)continue;
if(mp.count(pii(tx,ty))){
if(mp[pii(tx,ty)] == )continue;
mp[pii(tx,ty)] --;
if(tx + ty >= n-)up--;
sum--;
}
else {
mp[pii(tx,ty)] = get(tx,ty) - ;
if(tx + ty >= n-)up--;
sum--;
}
}
if(mp.count(pii(x,y))) {
if(mp[pii(x,y)] == )continue;
if(x + y >= n-)up -= mp[pii(x,y)];
sum -= mp[pii(x,y)];
mp[pii(x,y)] = ;
}
else{
mp[pii(x,y)] = ;
if(x + y >= n-)up -= get(x,y);
sum -= get(x,y);
}
}
ll gg = gcd(up, sum);
printf("Case #%d: %lld/%lld\n", tt, up/gg, sum/gg); // for(int i=0; i<n; i++){
// for(int j=0; j<n; j++){
// if(mp.count(pii(i,j)))
// cout<<i<<" , "<<j<<"="<<mp[pii(i,j)]<<endl;
// }
// cout<<endl;
// }
} return ;
}
HDU - 6229
HDU-6229 ICPC-沈阳M- Wandering Robots 概率的更多相关文章
- HDU 6229 - Wandering Robots - [概率题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6229 转载: https://blog.csdn.net/Anna__1997/article/det ...
- HDU 6229 Wandering Robots(2017 沈阳区域赛 M题,结论)
题目链接 HDU 6229 题意 在一个$N * N$的格子矩阵里,有一个机器人. 格子按照行和列标号,左上角的坐标为$(0, 0)$,右下角的坐标为$(N - 1, N - 1)$ 有一个机器人, ...
- hdu6229 Wandering Robots 2017沈阳区域赛M题 思维加map
题目传送门 题目大意: 给出一张n*n的图,机器人在一秒钟内任一格子上都可以有五种操作,上下左右或者停顿,(不能出边界,不能碰到障碍物).题目给出k个障碍物,但保证没有障碍物的地方是强联通的,问经过无 ...
- 2018 ICPC 沈阳网络赛
2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...
- ACM-ICPC 2017 沈阳赛区现场赛 M. Wandering Robots && HDU 6229(思维+期望)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6229 参考题解:https://blog.csdn.net/lifelikes/article/det ...
- 【概率】【找规律】hdu6229 Wandering Robots
题意:一个机器人在正方形迷宫的左上角,迷宫里有些格子有障碍物,每一步机器人会等概率地向能走的格子转移(包含自身).问你无限长的时间之后,机器人处于矩形对角线的右下方的概率. 无限长时间意味着,起点没有 ...
- HDU 5894 hannnnah_j’s Biological Test (组合数学) -2016 ICPC沈阳赛区网络赛
题目链接 #include <map> #include <queue> #include <math.h> #include <stdio.h> #i ...
- HDU 5898 odd-even number (数位DP) -2016 ICPC沈阳赛区网络赛
题目链接 题意:一个数字,它每个数位上的奇数都形成偶数长度的段,偶数位都形成奇数长度的段他就是好的.问[L , R]的好数个数. 题解:裸的数位dp, 从高到低考虑每个数位, 状态里存下到当前位为止的 ...
- HDU 5901 Count primes (1e11内的素数个数) -2016 ICPC沈阳赛区网络赛
题目链接 题意:求[1,n]有多少个素数,1<=n<=10^11.时限为6000ms. 官方题解:一个模板题, 具体方法参考wiki或者Four Divisors. 题解:给出两种代码. ...
随机推荐
- 【Android】Theme.AppCompat.Light 问题
Android 开发的 styles.xml 文件中遇到了这个问题: <style name="AppBaseTheme" parent="Theme.AppCom ...
- 关于定时器Scheduled(cron)的问题
定时器配置步骤参考:http://blog.csdn.NET/sd4000784/article/details/7745947 下面给出cron参数中各个参数的含义: CRON表达式 含义 & ...
- codeforces 339A.Helpful Maths B.Xenia and Ringroad 两水题
A.题意就是把字符串里面的数字按增序排列,直接上代码. #include <string.h> #include <stdio.h> #include <algorith ...
- Linux下,为应用程序添加桌面图标(ubuntu18.4)
一.桌面图标位置 Lniux下桌面图标储存路径为:/usr/share/applications 二.桌面图标格式 所有桌面图标格式均为desktop,即名为XXX.desktop 三.编辑内容(常用 ...
- 使用excel计算骰子输赢概率
如何得到使用3个骰子掷赢4个骰子的概率(每个骰子的点数为1-6,点数一样算输) 分为3步解决: 第一步.计算n个骰子得到m点数的分布 1个骰子能得到1.2.3.4.5.6点数,每个点数出现的方式只有1 ...
- 算法与数据结构基础 - 字典树(Trie)
Trie基础 Trie字典树又叫前缀树(prefix tree),用以较快速地进行单词或前缀查询,Trie节点结构如下: //208. Implement Trie (Prefix Tree)clas ...
- Java——擦除
直接代码分析一波: import java.util.*; public class Ex12 { public static void main(String[] args) { Class c1 ...
- android ——ListView
谷歌官方文档的介绍:https://developer.android.com/reference/android/widget/ListView.html 显示可垂直滚动的视图集合,其中每个视图都立 ...
- 深入解析Mysql中事务的四大隔离级别及其所解决的读现象
本文详细介绍四种事务隔离级别,并通过举例的方式说明不同的级别能解决什么样的读现象.并且介绍了在关系型数据库中不同的隔离级别的实现原理. 在DBMS中,事务保证了一个操作序列可以全部都执行或者全部都不执 ...
- 【Python3爬虫】爬取美女图新姿势--Redis分布式爬虫初体验
一.写在前面 之前写的爬虫都是单机爬虫,还没有尝试过分布式爬虫,这次就是一个分布式爬虫的初体验.所谓分布式爬虫,就是要用多台电脑同时爬取数据,相比于单机爬虫,分布式爬虫的爬取速度更快,也能更好地应对I ...