# | Problem | Pass Rate (passed user / total user) |
---|---|---|
13129 | Prize! |
|
13843 | Yet Another Josephus Problem |
|
14210 | Procat's journey |
|
14219 | All Pass Candy |
|
14574 | Queue correction |
|
Description
There are n people in a circle, numbered from 1 to n in clockwise direction. They are playing a game, and there will be m lucky people that can get the prizes.
Rules of the game:
1. Each prize has a lucky number.
2. Who is counted as the lucky number can get a prize.
3. If the lucky number is odd, count clockwise.
4. If the lucky number is even, count counterclockwise.
5. The student who gets a prize shall leave the circle.
6. After someone left the circle, if the new lucky number is odd, count from the next person, otherwise count from the previous person (in clockwise order).
For example:
n = 8
m = 3
lucky number = 3 4 5
The sequence of getting prize is:
first number is 3, so count clockwise starting from 1: 1 2 3
second is 4, so we count from 2, and counterclockwise: 2 1 8 7
last number is 5, so we count from 8, and clockwise: 8 1 2 4 5
Then people 3, 7, 5 can get the prize.
Please use doubly circular linked list to solve this problem.
Input
The first line has two integer n and m, where n is the number of total people, and m is the number of prizes.
The second line has m positive number a1 ~ am.
testcases:
1. 1 <= m <= n <= 10000, 1 <= ai <= n
2. 1 <= m <= n <= 10000, 1 <= ai <= n
3. 1 <= m <= n <= 10000, 1 <= ai <= n
4. 1 <= m <= n <= 1000000, 1 <= ai <= 10000000, n*m <= 300000000
5. 1 <= k <= n <= 1000000, 1 <= ai <= 10000000, n*m <= 300000000
6. 1 <= k <= n <= 1000000, 1 <= ai <= 10000000, n*m <= 300000000
Output
The output has m lines, each line contains a number: who can get the prize.
Sample Input Download
Sample Output Download
Partial Judge Code
13129.cPartial Judge Header
13129.hTags
Discuss
Description
You must be familiar with Josephus problem. In case your impression is faded, it’s a game that \(n\) people (say \(1,2,\dots,n\)) in a circle and in each round \(k\) people are repeatedly skipped and the next people is eliminated.
In this problem, we are curious about the order people eliminated.
Input
There would be two integers \(n,k\) in a line.
Constraints
\(1 \leq n \leq 10^4\)
\(0 \leq k \leq 10^9\)
Output
For each round, please print the order people eliminated. The order should be printed in a line, and there should be a space after each number.
DO NOT to print '\n' at the end of output.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Procat(破貓), AKA God of cycling is planning for a trip. As a student in the CS department, he decided to use a linked list to represent his trip. However, he accidentally pointed the last node to the body of the linked list, making some of the linked lists contain a cycle. Help him find out if there is a cycle in a given linked list.
Procat plans to visit \(N\) viewpoints. Numbered from \(0\) to \(N-1\). He will start from viewpoint \(0\) and visit viewpoint \(c_i\) after visiting viewpoint \(i\), until \(c_i = -1\). Each viewpoint contains a value \(a_i\).
-
Definition for singly linked list:
typedef struct ListNode { int val; struct ListNode *next; } ListNode;
- This is a partial judge problem. Input and output are handled by
14210.c
. All you have to do is implement the function
bool hasCycle(ListNode *head)
, which returnstrue
if there is a cycle in the given linked list, otherwise returnsfalse
. -
You should not modify the given linked list, or you will get a wrong answer.
Input
There are multiple subtasks in each testcase. The first line of the input contains an integer \(T\) indicating the number of subtasks. For each subtask, there will be three lines, formatted as following:
- One integer \(N\) indicating the number of nodes.
- \(N\) integers \(c_i\) indicating the next node of node \(i\).
- \(N\) integers \(a_i\) indicating the val stored in node \(i\).
\(N\)
\(c_0 \quad c_1 \quad c_2 \quad \ldots \quad c_{N-1}\)
\(a_0 \quad a_1 \quad a_2 \quad \ldots \quad a_{N-1}\)
It’s guaranteed that all nodes can be reached from node 0 in each testcase.
subtask 1:
subtask 2:
subtask 3:
Constraints
\(1 \le T \le 10^4\)
\(1 \le N \le 10^7\)
\(1 \le \sum N \le 10^7\)
\(-1 \le c_i < N\)
\(-10^9 \le a_i \le 10^9\)
- For \(33\%\) of the testcases, \(a\) is unique for each node.
- For \(67\%\) of the testcases, there is no additional constraint.
Output
For each subtask, output one line containing “Yes” if there is a cycle in the given linked list, otherwise output “No”. Print a newline character after each line.
Since this is a partial judge problem, you don’t have to worry about the output format.
Sample Input Download
Sample Output Download
Partial Judge Code
14210.cPartial Judge Header
14210.hTags
Discuss
Description
In the university, there's a tradition where students give out "All Pass Candy" (歐趴糖), or APCs, to their junior peers before midterms, wishing them to get good grades in the upcoming exams.
This year, CSSA (資工系學會) planned to give out the APCs to all first-year students. Since there are so many students, they want to let the students line up in $N$ lines, and a CSSA member would be in charge of giving out candies at the beginning of each line.
However, on the day of the event, Procat (破貓) took a nap, ended up oversleeping and missed the event. Dogeon (鴿子) was playing maimai (洗衣服), and others were busy with their stuff as well. So, Stiff Waist Beast (挺腰獸) has to give out all the candies by himself. Before that, he has to merge all the lines into one. For the sake of fairness, he wants to merge the lines in a way that the student arriving earlier will get the candy first. Please help him merge all the lines.
-
This is a partial judge problem. Input and output are handled by
13584.c
. All you have to do is implement the function
ListNode* mergeLists(ListNode** lists, int n);
, which merges the $n$ non-decreasing singly linked lists into one non-decreasing singly-linked list, and returns the head of the merged list. -
The definition of a singly-linked list node:
typedef struct _ListNode {
int val;
struct _ListNode *next;
} ListNode; -
This is a work of fiction. Any resemblance to actual events or persons is entirely coincidental.
Input
- The first line contains an integer $N$, the number of student lines.
- Each of the following $N$ lines starts with an integer $M_i$, followed by $M_i$ integers $a_{i,1}, a_{i,2}, \ldots, a_{i,M_i}$, representing the information of each line.
- $M_i$ indicates the number of students in the $i$-th line.
- $a_{i,j}$ indicates the arrival order of the $j$-th student in the $i$-th line.
$N$
$M_1 \quad a_{1,1} \quad a_{1,2} \quad \ldots \quad a_{1,M_1}$
$M_2 \quad a_{2,1} \quad a_{2,2} \quad \ldots \quad a_{2,M_2}$
$\enspace \vdots$
$M_N \quad a_{N,1} \quad a_{N,2} \quad \ldots \quad a_{N,M_N}$
Constraints
- $2 \le N \le 10^5$
- $1 \le M_i \le 10^7$
- $1 \le \sum M_i \le 10^7$
- $1 \le a_{i,j} \le 10^9$
- $a_{i,j - 1} \le a_{i,j}$ for $2 \le j \le M_i$
Output
Single line containing $\sum M_i$ integers, representing the students' arrival order in the merged line. Each integer is followed by a space.
Since this is a partial judge problem, you don't have to worry about the output format.
Sample Input Download
Sample Output Download
Partial Judge Code
14219.cPartial Judge Header
14219.hTags
Discuss
Description
The elephants are queuing in a line. However, some of them are standing in the wrong position, so you are asked to help restore the correct order.
Since the elephants are too lazy to call each other by name, they use a lucky number to recognize one another. Therefore, you will receive a linked list where each node contains a lucky number. Your task is to reverse the order of nodes within the range \([l,r]\) (both inclusive, \(1\)-based).
The I/O functions are already implemented in the given file.
You only need to complete the
void solve(Node* head, int l, int r)
fucntion that returns
the same dummy head. Your task is to reverse the linked list within the
specified range \([l,
r]\).
You can ignore the warning while compiling:
cast to smaller integer type 'int' from 'Node *' (aka 'struct Node *') [-Wpointer-to-int-cast]
There is a restriction: You can only modify the “next” pointer of each node to change the order. If you attempt to modify the node values or return a list containing nodes whose addresses do not belong to the original list, you may receive a wrong answer.
Input
The first line contains three integers \(n\), \(l\) and \(r\), representing the size of the list, the start index, and the end index (both inclusive, \(1\)-based).
The second line contains \(n\) integers \(a_1, a_2,...,a_n\), representing the lucky numbers of the elephants.
Contraints
- \(1 \leq l \leq r \leq n \leq 2 \times 10^5\)
- \(1 \leq a_i \leq 10^9\)
Subtask
- (Testcases 1-2) \(1 \leq l \leq r \leq n \leq 1000\)
- (Testcases 3-7) No additional Constraints.
Output
Output the modified list of lucky numbers, each followed by a space.