17 多校

来源:互联网 发布:淘宝中待付款什么意思 编辑:程序博客网 时间:2024/05/29 16:27

KazaQ's Socks

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 256    Accepted Submission(s): 171


Problem Description
KazaQ wears socks everyday.

At the beginning, he has n pairs of socks numbered from 1 to n in his closets. 

Every morning, he puts on a pair of socks which has the smallest number in the closets. 

Every evening, he puts this pair of socks in the basket. If there are n1 pairs of socks in the basket now, lazy KazaQ has to wash them. These socks will be put in the closets again in tomorrow evening.

KazaQ would like to know which pair of socks he should wear on the k-th day.
 

Input
The input consists of multiple test cases. (about 2000)

For each case, there is a line contains two numbers n,k (2n109,1k1018).
 

Output
For each test case, output "Case #xy" in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.
 

Sample Input
3 73 64 9
 

Sample Output
Case #1: 3Case #2: 1Case #3: 2
 

题目链接:点击打开链接

题意: KazaQ有n双袜子,每次都在只剩一双袜子时把之前穿过的袜子给洗了,每双袜子都有自己的编号从1到n,每天穿所有干净的袜子中编号最小的一双。问第k天穿的袜子编号是多少。

找规律,带几个例子进去很快就找到规律了,前面n个为1、2、3、…、n,后面的循环周期就是(n-1)* 2 前n-1为1、2、3、…、n-2、n-1 ,后n-1为1、2、3、…、n-2、n 。

#include<iostream>#include<stdio.h>#include<string.h>using namespace std;long long n,k,cas = 0;int main(){    while(~scanf("%lld%lld",&n,&k))    {        if(k<=n)            printf("Case #%lld: %lld\n",++cas,k);        else        {            k -= n;            if(k%(n-1))                printf("Case #%lld: %lld\n",++cas,k%(n-1));            else                printf("Case #%lld: %lld\n",++cas,n-(k/(n-1)%2));        }    }    return 0;}


原创粉丝点击