当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6232:Confliction

题目描述
Recently, Alice and Bob are working on a resource-sharing computation model. In this model, there are two processing units, and a memory space which could be represented as unlimited linear grids $ \ldots, A_{-3}, A_{-2}, A_{-1}, A_0, A_1, A_2, A_3, \ldots$. Each processing units has a pointer to mark exactly one grid in the memory. In each clock turn, the pointer would stay at the current grid, move the pointer one grid forward, or move the pointer one grid backward. In their work, Alice and Bob would submit their codes, and their programs would start at the same time. Initially, both pointers would be located at a random grid, and move according to a set of instructions. If both pointers are at the same grid at the same time, the confliction counter would plus one and record it(If their initial grids are the same, the counter would still record it). Now it is your job to find the maximum conflictions the counter could record.
输入解释
The first line is the number of test cases.
For each test case, the first is an integer $N_{Alice} (N_{Alice} \leq 100000)$, donating the length of the instructions of Alice.

The next $N_{Alice}$ lines describe Alice`s instructions. Each line consists of two integer $c, t$. $c$ could be $-1, 0, 1$, donating moving forward, staying, and moving backward respectively. $t$ is a non-negative integer donating that the instruction $c$ would be executed $t$ times, in the next $t$ clock turns.

The next line is an integer $N_{Bob} (N_{Bob} \leq 100000)$, donating the length of the instructions of Bob.

The next $N_{Bob}$ lines describe Bob`s instructions. Each line consists of two integer $c, t$. $c$ could be $-1, 0, 1$, donating moving forward, staying, and moving backward respectively. $t$ is a non-negative integer donating that the instruction $c$ would be executed $t$ times, in the next $t$ clock turns.

Suppose $L_{Alice}$ equals the sum of all $t$ in Alice's program, and $L_{Bob}$ equals the sum of all $t$ in Bob's program.
It is guaranteed $L_{Alice} = L_{Bob}$ and $L_{Alice}, L_{Bob} \leq 10^{18}$.
输出解释
For each test case, output a line containing the maximum conflictions.
输入样例
2
1
1 2
2
1 1
-1 1
1
0 6
4
-1 2
1 1
-1 2
1 1
输出样例
2
3
来自杭电HDUOJ的附加信息
Recommend jiangzijing2015

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6232

最后修改于 2020-10-25T23:29:32+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
8000/4000MS(Java/Others) 262144/262144K(Java/Others)