【多校训练】hdu 6043 KazaQ's Socks

来源:互联网 发布:淘宝中心网页版登录 编辑:程序博客网 时间:2024/05/16 10:13

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
 

题意:

有n双袜子1~n,每天早上选标号最小的一双。晚上发现只剩一双能穿时,就把之前的洗了,明晚就能穿。问第K天穿的是哪一个标号的袜子。

思路:

找规律发现,如果是n双袜子,有1~n-2的时候按顺序穿,只剩一双时奇数轮剩的是n-1,偶数轮剩的是n。

////  main.cpp//  1011////  Created by zc on 2017/7/25.//  Copyright © 2017年 zc. All rights reserved.//#include <iostream>#include<cstdio>#include<cmath>#define ll long longusing namespace std;int main(int argc, const char * argv[]) {    int kase=0;    ll n,k;    while(~scanf("%lld%lld",&n,&k))    {        ll ans;        if(k<=n)    ans=k;        else        {            k-=n+1;            ll t1=k%(n-1);            ll t2=k/(n-1);            if(t1<=n-3) ans=t1+1;            else ans=n-1+(t2&1);        }        printf("Case #%d: %lld\n",++kase,ans);    }        }

原创粉丝点击