A14108 | Ruler Of The Zoo
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
After realizing that Zookeeper is just a duck, the animals have overthrown Zookeeper. They now have to decide a new ruler among themselves through a fighting tournament of the following format:
Initially, animal $0$ is king, while everyone else queues up with animal $1$ at the front of the queue and animal $n-1$ at the back. The animal at the front of the queue will challenge the king to a fight, and the animal with greater strength will win the fight. The winner will become king, while the loser joins the back of the queue.
An animal who wins $3$ times consecutively will be crowned ruler for the whole zoo. The strength of each animal depends on how many consecutive fights he won. Animal $i$ has strength $A_i$ with $0$ consecutive win, $B_i$ with $1$ consecutive win, and $C_i$ with $2$ consecutive wins. Initially, everyone has $0$ consecutive win.
For all animals, $A_i > B_i$ and $C_i > B_i$ . Also, the values of $A_i$ , $B_i$ , $C_i$ are distinct (all $3n$ values are pairwise different).
In other words, an animal who is not a king has strength $A_i$ . A king usually has a strength of $B_i$ or $C_i$ . The exception is on the first turn, the first king (animal $0$ ) has strength $A_i$ .
Who is the new ruler, and after how many fights? Or will it end up that animals fight forever with no one ending up as ruler?
Initially, animal $0$ is king, while everyone else queues up with animal $1$ at the front of the queue and animal $n-1$ at the back. The animal at the front of the queue will challenge the king to a fight, and the animal with greater strength will win the fight. The winner will become king, while the loser joins the back of the queue.
An animal who wins $3$ times consecutively will be crowned ruler for the whole zoo. The strength of each animal depends on how many consecutive fights he won. Animal $i$ has strength $A_i$ with $0$ consecutive win, $B_i$ with $1$ consecutive win, and $C_i$ with $2$ consecutive wins. Initially, everyone has $0$ consecutive win.
For all animals, $A_i > B_i$ and $C_i > B_i$ . Also, the values of $A_i$ , $B_i$ , $C_i$ are distinct (all $3n$ values are pairwise different).
In other words, an animal who is not a king has strength $A_i$ . A king usually has a strength of $B_i$ or $C_i$ . The exception is on the first turn, the first king (animal $0$ ) has strength $A_i$ .
Who is the new ruler, and after how many fights? Or will it end up that animals fight forever with no one ending up as ruler?
输入格式
The first line contains one integer $n$ ( $4 \leq n \leq 6000$ ) — number of the animals.
$i$ -th of the next $n$ lines contains $3$ integers $A_i$ , $B_i$ and $C_i$ ( $0 \leq A_i, B_i, C_i \leq 10^9$ ).
It is guaranteed that $A_i > B_i$ and $C_i > B_i$ , and that all values of $A_i$ , $B_i$ and $C_i$ are distinct.
$i$ -th of the next $n$ lines contains $3$ integers $A_i$ , $B_i$ and $C_i$ ( $0 \leq A_i, B_i, C_i \leq 10^9$ ).
It is guaranteed that $A_i > B_i$ and $C_i > B_i$ , and that all values of $A_i$ , $B_i$ and $C_i$ are distinct.
输出格式
Output two integers in a single line. The first is the index of the animal that will become ruler, and the second is the number of fights passed until some animal becomes the ruler.
If the animals will fight for infinitely long, output -1 -1 instead.
If the animals will fight for infinitely long, output -1 -1 instead.
输入输出样例
输入 #1
4 5 1 2 10 8 11 9 0 3 7 4 6
输出 #1
-1 -1
输入 #2
5 11 7 12 8 6 14 2 1 10 13 0 9 5 3 4
输出 #2
1 7
The following describes the sequence of events for the second sample. Note that in fight $1$ , the king (animal $0$ ) has strength $A_0$ . The tournament ends at fight $7$ as animal $1$ wins fight $5$ , $6$ and $7$ . 
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted