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. php中引用&的一个小实例

    在百度知道上碰到一段关于php的引用符&的代码,对于初学都来说还是很考验理解分析能力的,把代码和自己的分析贴上来作一个备份,也与大家共勉. 代码片段: $arr =array(1,2,3,4) ...

  2. JAVA类型擦除

    Java泛型-类型擦除 一.概述 Java泛型在使用过程有诸多的问题,如不存在List<String>.class, List<Integer>不能赋值给List<Num ...

  3. abelkhan中的rpc框架

    rpc简介:http://www.ibm.com/developerworks/cn/aix/library/au-rpc_programming/index.html 常见的rpc框架有protob ...

  4. div自身高度、屏幕高度

    获取元素高度 scrollWidth    //显示当前元素的宽度 scrollHeight   //显示当前元素的高度 scrollLeft     //显示当前元素的左边距左侧的距离 scroll ...

  5. 【JS】jquery通知插件toastr

    toastr是一款非常棒的基于jquery库的非阻塞通知提示插件,toastr可设定四种通知模式:成功,出错,警告,提示,而提示窗口的位置,动画效果都可以通过能数来设置,在官方站可以通过勾选参数来生成 ...

  6. PHP源码阅读strtr

    strtr 转换字符串中特定的字符,但是这个函数使用的方式多种. echo strtr('hello world', 'hw', 'ab'); // 第一种 aello borld echo strt ...

  7. jsPlumb之流程图项目总结及实例

    在使用jsPlumb过程中,所遇到的问题,以及解决方案,文中引用了<数据结构与算法JavaScript描述>的相关图片和一部分代码.截图是有点多,有时比较懒,没有太多的时间去详细的编辑. ...

  8. 浅谈Ajax 异步的几点细节

    1.浏览器执行到Ajax代码的这行语句的时候,发出了一个HTTP请求,欲想请求服务器上的数据.服务器此时开始I/O,所谓的I/O就是磁盘的读写,需要花费一些时间,所以不会立即产生下行的HTTP报文: ...

  9. centos7使用cobbler(2.8)批量部署操作系统之二

    1. Cobbler常用命令 1.1 查看cobbler帮助 # cobbler --help usage ===== cobbler <distro|profile|system|repo|i ...

  10. gulp总结

    安装 1.安装node 检测是否安装成功的方法,在命令行输入: node -v npm -v 显示版本号则安装成功 2.装cnmp一定要网络好一点 npm install cnpm -g --regi ...