ACdream 群赛1221 Problem B: cxlove is a good man
2012-12-21 21:36
495 查看
Problem B: cxlove is a good man
Time Limit: 3 Sec Memory Limit:128 MB
Submit: 121 Solved: 27
[Submit][Status][Web Board]
Description
众所周知,爱酱(cxlove)是个绝世好男人。好男人的标准之一就是能解决妹子提出的一切问题!
有一天,好奇宝宝娜娜做题时发现了一种神器的树。树的前几层如下图:
如你所见:
除开最上面两个奇怪的东西之外,树的每个节点上都有一个数字,
某个节点的分子是在该节点左上的第一个节点和其右上节点的分子的和,
某个节点的分母是在该节点的左上的第一个节点和其右上第一个节点的分母的和。
例如, 2/3 这个节点的左上第一个节点是1/2,右上第一个节点是 1/1。
现在给定从根节点到某个节点的路径。
用L(x),R(x)表示。L(x)表示像沿着左子树走了x步,R(x)表示沿着右走了x步,
例如:L(2)R(1)L(1) 表示3/8
Input
一个数字n接下来n行,每行一个字母a,一个数字b
a='L'表示沿着树往左走
a='R' 表示沿着树往右走
n<=10^7
所有b的和小于10^18
Output
两个数 p,q, 分别是到达节点的分子mod 1000000007 和分母mod 1000000007Sample Input
1R 5
3
R 2
R 5
R 3
Sample Output
6/111/1
HINT
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <cmath> #include <stack> #include <map> using namespace std; #define LL long long struct NOD { LL a,b; }; LL re[10000009]; int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif char ch[5],c,c0; LL tmp; int n; NOD a,b,ta,tb; while(~scanf("%d",&n)){ if(n==0){ printf("1/1\n"); continue; } scanf("%s%lld",ch,&tmp); if(ch[0]=='L') c0 = c = 'L'; else c0 = c = 'R'; int cnt = 0; re[0] = tmp; for(int i=1; i<n; i++){ scanf("%s%lld",ch,&tmp); if(ch[0]==c) re[cnt] += tmp; else{ re[++cnt] = tmp; c = ch[0]; } } for(int i=0; i<=cnt; i++) re[i] = re[i]%1000000007; b.a = b.b = 1; if(c0=='L') a.a = 0,a.b = 1; else a.a = 1,a.b = 0; for(int i=0; i<=cnt; i++){ tb.a = (a.a*re[i]+b.a)%1000000007; tb.b = (a.b*re[i]+b.b)%1000000007; ta.a = (a.a*re[i]+b.a-a.a)%1000000007; ta.b = (a.b*re[i]+b.b-a.b)%1000000007; a = ta,b = tb; } cout<<b.a<<"/"<<b.b<<endl; } return 0; }
相关文章推荐
- acdream 1039: cxlove is a good man 左右子树规律题
- SDNU__1221.This is a water problem.
- GFOJ problem 470: [HbFS-]Red is good 解题报告
- acdream 1038: nanae is a good girl 置换群-循环因子
- 每日英语:Female muscle | Now is not a good time to be a man
- The good life is one inspired by love and guided by knowledge
- acdream 1028 第三次群赛Problem G: Multiplication
- what is your choice?man with money or man with love?”(你选择什么?有钱人还是爱你的人?)
- 好人难寻 A Good Man Is Hard to Find 弗兰纳里 奥康纳
- ACdream 群赛11.10 Problem J: I can't describe the problem
- Xenomai on the Beaglebone Black in 14 easy steps ---fwqlzz love is for ever
- [bzoj1419]Red is good 期望DP
- ACdream原创群赛(16) J
- [CodeForces]-672B-Different is Good
- Problem 747D - Winter Is Coming
- Why is try {…} finally {…} good; try {…} catch{} bad?
- Android:安装apk时提示:There is a problem parsing the package
- 20080331 - What is the GAC, What problem does it solve
- What is a good EPUB reader on Linux
- Why Go Is Not Good