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. 如何远程调试zookeeper集群

    我们在阅读一些源码的时候,如果能调试源代码将会大大的提高我们的阅读效率.最近在学习zookeeper源码,分享下如何调试zookeeper集群. zookeeper代码,调试环境搭建 1.下载zook ...

  2. Struts2 Action接收POST请求JSON数据及其实现解析

    一.认识JSON JSON是一种轻量级.基于文本.与语言无关的数据交换格式,可以用文本格式的形式来存储或表示结构化的数据. 二.POST请求与Content-Type: application/jso ...

  3. html页面多个a标签点击时显示不同的样式

    <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...

  4. [leetcode-583-Delete Operation for Two Strings]

    Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 t ...

  5. DDD理论学习系列(9)-- 领域事件

    DDD理论学习系列--案例及目录 1. 引言 A domain event is a full-fledged part of the domain model, a representation o ...

  6. mybatis存取blob对象+@Cacheable实现数据缓存

    参考文档: http://www.ibm.com/developerworks/cn/opensource/os-cn-spring-cache/ 需求场景: 当前业务通过第三方接口查询一个业务数据, ...

  7. P3390 【模板】矩阵快速幂

    题目背景 矩阵快速幂 题目描述 给定n*n的矩阵A,求A^k 输入输出格式 输入格式: 第一行,n,k 第2至n+1行,每行n个数,第i+1行第j个数表示矩阵第i行第j列的元素 输出格式: 输出A^k ...

  8. MessageBoxButtons.OKCancel的选择事件

    private void 退出ToolStripMenuItem1_Click(object sender, EventArgs e) { DialogResult resault = Message ...

  9. jsp注册页面的省份联动(网上copy别人的,然后自己弄了一下才知道怎么用)

    首先写一个js里面是所有的省份一些七七八八的东西,直接复制黏贴过去就好了. var addressInit = function(_cmbProvince, _cmbCity, _cmbArea, d ...

  10. MySQL 启动参数说明及性能优化建议

    [mysqld] port = 3306 serverid = 1 socket = /tmp/mysql.sock skip-name-resolve #禁止MySQL对外部连接进行DNS解析,使用 ...