/*
A jail has N prisoners, and each prisoner has a unique id number,S , ranging from 1 to N . There are M sweets that must be distributed to the prisoners.
The jailer decides the fairest way to do this is by sitting the prisoners down in a circle (ordered by ascending S), and then, starting with some random S, distribute one candy at a time to each sequentially numbered prisoner until all M candies are distributed. For example, if the jailer picks prisoner s=2 , then his distribution order would be (2 ,3,4 ... n-1, n, 1, 2,3,4..) until all M sweets are distributed.
But wait—there's a catch—the very last sweet is poisoned! Can you find and print the ID number of the last prisoner to receive a sweet so he can be warned?
Input Format
The first line contains an integer, T, denoting the number of test cases.
The T subsequent lines each contain 3 space-separated integers:
N(the number of prisoners), M (the number of sweets), and S (the prisoner ID), respectively.
Constraints
1<=T<=100
1<=N<=10^9
1<=M<=10^9
1<=s<=10^9
Output Format
For each test case, print the ID number of the prisoner who receives the poisoned sweet on a new line.
Sample Input
1
5 2 1
Sample Output
2
Explanation
There are N=5 prisoners and M=2 sweets. Distribution starts at ID number s=1 , so prisoner 1 gets the first sweet and prisoner2 gets the second (last) sweet. Thus, we must warn prisoner 2 about the poison, so we print 2 on a new line.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
namespace HackerDemo
{
class SavethePrisoner
{
public void SavethePrisonerMain()
{
int t = Convert.ToInt32(Console.ReadLine());
for (int a0 = 0; a0 < t; a0++)
{
string[] tokens_n = Console.ReadLine().Split(' ');
int n = Convert.ToInt32(tokens_n[0]);
int m = Convert.ToInt32(tokens_n[1]);
int s = Convert.ToInt32(tokens_n[2]);
Int64 sid = 0;
sid = m % n;
sid = sid + s - 1;
if (sid > n)
{
sid = sid - n;
}
Console.WriteLine(sid);
}
}
}
}
No comments:
Post a Comment