题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6229

参考题解:https://blog.csdn.net/lifelikes/article/details/78452558

       https://www.cnblogs.com/cxhscst2/p/8215717.html

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi acos(-1)
#define pii pair<int,int>
#define pb push_back
const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const int MAXN = 15e4 + ;
const int MAXM = 2e6 + ; int n,k;
int dx[] = {-,,,};
int dy[] = {,-,,};
map<pii,bool>ma;
map<pii,int>sub; bool judge(int x,int y) {
if(x < || x >= n || y < || y >= n) return false;
return true;
} int check(int x,int y) {
if(x == || x == n - ) {
if(y == || y == n - ) return ;
else return ;
} else {
if(y == || y == n - ) return ;
else return ;
}
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
#endif
int cas = ;
int t;
scanf("%d",&t);
while(t--) {
ma.clear();
sub.clear();
scanf("%d%d",&n,&k);
if(n == ) {
printf("Case #%d: 1/1\n",cas++);
continue;
}
ll ans1 = 16ll * (n - ) + 5ll * (n - ) * (n - ) + ;
ll ans2 = 5ll * (1ll * n * (n + ) / - 2ll * (n - ) - ) + 8ll * (n - ) + ;
while(k--) {
int x,y;
scanf("%d%d",&x,&y);
if(ma[mp(x,y)]) {
ans1 -= sub[mp(x,y)];
if(x + y >= n - ) ans2 -= sub[mp(x,y)];
sub[mp(x,y)] = ;
} else {
ma[mp(x,y)] = true;
ans1 -= check(x,y);
if(x + y >= n - ) ans2 -= check(x,y);
sub[mp(x,y)] = ;
}
for(int i = ; i < ; i++) {
int nx = x + dx[i], ny = y + dy[i];
if(!judge(nx,ny)) continue;
if(ma[mp(nx,ny)]) {
if(sub[mp(nx,ny)]) {
ans1--;
if(nx + ny >= n - ) ans2--;
sub[mp(nx,ny)]--;
}
} else {
ma[mp(nx,ny)] = true;
sub[mp(nx,ny)] = check(nx,ny) - ;
ans1--;
if(nx + ny >= n - ) ans2--;
}
}
}
ll gcd = __gcd(ans1,ans2);
ans1 /= gcd, ans2 /= gcd;
printf("Case #%d: %lld/%lld\n",cas++,ans2,ans1);
}
return ;
}

ACM-ICPC 2017 沈阳赛区现场赛 M. Wandering Robots && HDU 6229(思维+期望)的更多相关文章

  1. ACM-ICPC 2017 沈阳赛区现场赛 G. Infinite Fraction Path && HDU 6223(BFS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6223 参考题解:https://blog.csdn.net/qq_40482495/article/d ...

  2. ACM-ICPC 2016 沈阳赛区现场赛 I. The Elder && HDU 5956(斜率DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5956 题意:一颗树上每条边有个权值,每个节点都有新闻要送到根节点就是1节点,运送过程中如果不换青蛙就是 ...

  3. 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)

    摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...

  4. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  5. ACM总结——2017ACM-ICPC北京赛区现场赛总结

    现在距离比赛结束已经过了一个多星期了,也是终于有时间写下心得了.回来就是被压着做项目,也是够够的. 这次比赛一样是我和两个学弟(虽然是学弟,但我的实力才是最弱的T_T)一起参加的,成绩的话打铁,算是情 ...

  6. ACM-ICPC 2017 西安赛区现场赛 K. LOVER II && LibreOJ#6062. 「2017 山东一轮集训 Day2」Pair(线段树)

    题目链接:西安:https://nanti.jisuanke.com/t/20759   (计蒜客的数据应该有误,题目和 LOJ 的大同小异,题解以 LOJ 为准)     LOJ:https://l ...

  7. ACM-ICPC 2015 沈阳赛区现场赛 I. Triple && HDU 5517(二维BIT)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5517 题意:有二元组(a,b),三元组(c,d,e).当b == e时它们能构成(a,c,d)然后,当 ...

  8. ACM-ICPC 2015 沈阳赛区现场赛 F. Frogs && HDU 5514(容斥)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5514 题意:有m个石子围成一圈, 有n只青蛙从跳石子, 都从0号石子开始, 每只能越过xi个石子.问所 ...

  9. 2014ACM/ICPC亚洲区鞍山赛区现场赛1009Osu!

    鞍山的签到题,求两点之间的距离除以时间的最大值.直接暴力过的. A - Osu! Time Limit:1000MS     Memory Limit:262144KB     64bit IO Fo ...

随机推荐

  1. [转帖]Oracle 起诉 Google 事件

    Oracle 起诉 Google 事件 https://www.cnblogs.com/panchanggui/p/9449842.html Oracle 是世界第二大软件公司 世界第一大DBMS公司 ...

  2. mysql数据库基础-2019-9-10(随堂笔记)

    mysql数据库基础 在cmd情况下启动mysql数据库:(配置path环境变量后可忽略) 运行mysql1. 进入mysql路径2. 执行:mysql -uroot -p,安装时的密码 1.数据库& ...

  3. fiddler模拟发送请求和响应

    iddler模拟发送请求和响应 一.fiddler模拟发送请求 1.fiddler模拟发送get请求 1)例如:访问博客园https://www.cnblogs.com/,并且登录输入密码账号登录,再 ...

  4. python3连接oracle数据库

    声明:python,cx_Oracle和instantclient的版本应一致 我这里使用的版本是python3.6 64位 ,cx_Oracle-5.3-11g.win-amd64-py3.6-2和 ...

  5. Spark Scala当中reduceByKey的用法

    [学习笔记] /*reduceByKey(function)reduceByKey就是对元素为KV对的RDD中Key相同的元素的Value进行function的reduce操作(如前所述),因此,Ke ...

  6. 【AtCoder】AGC007

    AGC007 A - Shik and Stone 如果i + j走过的格子只有一个,那么就是可以走到 #include <bits/stdc++.h> #define fi first ...

  7. 【AtCoder】AGC005

    AGC005 A - STring 用一个栈,如果遇到S就弹入,如果遇到T栈里有S就弹出栈顶,否则T在最后的串里,最后计算出的T和栈里剩的S就是答案 #include <bits/stdc++. ...

  8. abstract class 与 interface

    abstract class和interface是Java语言中对于抽象类定义进行支持的两种机制,正是由于这两种机制的存在,才赋予了Java强大的面向对象能力. abstract class和inte ...

  9. 聊聊BIO、NIO与AIO的区别

    题目:说一下BIO/AIO/NIO 有什么区别?及异步模式的用途和意义? 1F 说一说I/O首先来说一下什么是I/O? 在计算机系统中I/O就是输入(Input)和输出(Output)的意思,针对不同 ...

  10. LC 1. Two Sum

    题目介绍 Given an array of integers, return indices of the two numbers such that they add up to a specif ...