Description

KazaQ wears socks everyday.

At the beginning, he has nn pairs of socks numbered from 11 to nn 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 n−1n−1 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 kk-th day.

 

Input

The input consists of multiple test cases. (about 20002000)

For each case, there is a line contains two numbers n,kn,k (2≤n≤109,1≤k≤1018)(2≤n≤109,1≤k≤1018).

 

Output

For each test case, output " Case #xx: yy" in one line (without quotes), where xx indicates the case number starting from 11 and yy denotes the answer of corresponding case.
 
Sample

Sample Input

Sample Output
Case #:
Case #:
Case #:

题意:

  有n双袜子,标号1到n放在柜子里,每天早上起床穿袜子选标号最小的一双。然后晚上回来将穿过的扔到篮子里。当篮子里的袜子数量为n-1的时候,就把这些袜子洗一下,第二天晚上再放回柜子里。问在第K天穿的是哪一个标号的袜子。

思路:

  简单排一下就会发现一个简单的规律,前n天肯定都是按标号穿,然后后面几天因为穿第n双袜子的时候,所以穿1到n-1号,之后n号袜子在洗所以穿1号袜子。

  然后穿1到n-2号,因为此时n-1号在洗,所以接下来穿的是n号袜子。

  依次类推便可发现袜子穿的标号顺序为1、2、...、n      1、2、...、n-1     1、2、...、n、

  由此规律来进行分段,前面n个数直接输出,后面的分开前后两部分,取模就可以得出结果了。

  比如:

    一共四双袜子穿的顺序为:(1 2 3 4)( 1 2 3)( 1 2 4)( 1 2 3)( 1 2 4)……

    一共五双袜子穿的顺序为:(1 2 3 4 5)( 1 2 3 4)( 1 2 3 5)( 1 2 3 4)( 1 2 3 5)……

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<math.h>
using namespace std;
int main()
{
long long n,k;
long long ans;
long long logo=;
while(~scanf("%lld%lld",&n,&k))
{
if(k<=n)
printf("Case #%d: %lld\n",logo++,k);//前n天直接输出k
else
{
k-=n;
long long flag;
flag=k%(n-);//去余数
if(flag==)//如果是最后一天,判断是穿第n双还是n-1双
{
if(k/(n-)%==)
ans=n-;
else
ans=n;
}
else//如果不是最后一天,则输出余数
ans=flag;
printf("Case #%d: %lld\n",logo++,ans);
}
}
}

HDU 6043 KazaQ's Socks (规律)的更多相关文章

  1. HDU 6043 - KazaQ's Socks | 2017 Multi-University Training Contest 1

    /* HDU 6043 - KazaQ's Socks [ 找规律 ] | 2017 Multi-University Training Contest 1 题意: 一共 n 双袜子编号 1~n,每天 ...

  2. 2017 Multi-University Training Contest - Team 1 1011&&HDU 6043 KazaQ's Socks【规律题,数学,水】

    KazaQ's Socks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  3. 2017ACM暑期多校联合训练 - Team 1 1011 HDU 6043 KazaQ's Socks (找规律)

    题目链接 Problem Description KazaQ wears socks everyday. At the beginning, he has n pairs of socks numbe ...

  4. HDU - 6043 KazaQ's Socks(找规律)

    题意:有n双袜子,编号1到n,放在衣柜里,每天早晨取衣柜中编号最小的袜子穿,晚上将这双袜子放在篮子里,当篮子里有n-1双袜子时,清洗袜子,直到第二天晚上才洗好,并将洗好的袜子重新放回衣柜. 分析:规律 ...

  5. hdu 6043 KazaQ's Socks

    规律题.我自己写的规律对长度为2的要特判,wa一万次... 规律题目,容易错的反而是数据小的时候,得长记性. 题解:规律 先是1~n 然后1~n-2 n-1  1~n-2 n 交替出现 比如当n=4 ...

  6. HDU6043 17多校1 KazaQ's Socks 水题

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6043 Problem Description KazaQ wears socks everyday. ...

  7. 杭电 KazaQ's Socks

    KazaQ wears socks everyday. At the beginning, he has n pairs of socks numbered from 1 to n in his cl ...

  8. HDU6043 KazaQ's Socks

    Problem Description KazaQ wears socks everyday. At the beginning, he has n pairs of socks numbered f ...

  9. 【多校联合】(HDU6043)KazaQ's Socks

    [多校联合](HDU6043)KazaQ's Socks 一条纯粹的水题,记录下只是因为自己错的太多而已. 原因在于对数据的细节的把握不佳. 原题 KazaQ's Socks Time Limit: ...

随机推荐

  1. hibernate,createCriteria in条件 是一个集合。list 或 数组等

    hibernate,createCriteria in条件 是一个集合.list 或 数组等 cq.in("states", new String[]{"2", ...

  2. for循环操作数组

    if(!empty($data)){ $arr_length=count($data); //数组的步长 $array_keys_list=array_values($data); //数组的键值 f ...

  3. php中的命名空间

    a.php <?php namespace a\b; class Apple{ function get_info(){ echo 'aaa'.'<br/>'; } } ?> ...

  4. 利用 Traceview 精准定位启动时间测试的异常方法 (工具开源)

    机智的防爬虫标识原创博客地址:http://www.cnblogs.com/alexkn/p/7095855.html博客求关注: http://www.cnblogs.com/alexkn 1.启动 ...

  5. asp.net使用qq邮箱发送邮件

    using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Ne ...

  6. word2-寻找社交新浪微博中的目标用户

    项目简述: 为了进行更加精准的营销, 利用数据挖掘相关算法, 利用开放API或自行编写爬虫获得新浪微博, 知乎等社交网络(可能需要破解验证码)中用户所发布的数据, 利用数据挖掘的相关算法进行分析, 从 ...

  7. etcd raft library设计原理和使用

    早在2013年11月份,在raft论文还只能在网上下载到草稿版时,我曾经写过一篇blog对其进行简要分析.4年过去了,各种raft协议的讲解铺天盖地,raft也确实得到了广泛的应用.其中最知名的应用莫 ...

  8. WriteTeacherObj

    package JBJADV003;import java.io.*;public class WriteTeacherObj { /** * @param args */ public static ...

  9. 页面打印(js/jquery)

    1.js实现(可实现局部打印)  <html> <title>js打印</title> <head></head><body>  ...

  10. 遍历数组按学号找人,若找到则输出信息,否则输出"查无此人"

    //建立一个类类型的数组,并向这个数组内添加学生信息,包括姓名和年龄等 **********************学生类************************** package prac ...