题目链接

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 n−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 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 (2≤n≤109,1≤k≤1018).

Output

For each test case, output "Case #x: y" 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 7

3 6

4 9

Sample Output

Case #1: 3

Case #2: 1

Case #3: 2

分析:

有n双袜子分别编号1~n,每天从干净的袜子中选择一双编号最小的袜子穿,如果干净的袜子只剩下一双了,就把所有穿过的袜子洗干净接着穿,选择的时候仍然满足上面的规则,问第k天穿的袜子的编号是多少?

这就是一个找规律的题,我们通过两组数据来看一下他的规律:

数据1: 3 7

那每天穿的袜子的序列就是:

1 2 3 1 2 1 3 那么第七天穿的袜子就是编号3,

如果我们接着往下看的话,就会发现整个序列是这样子的:

1 2 3 1 2 1 3 1 2 1 3 1 2 1 3······

就会发现除了前n天以外,穿的袜子的编号的循环节是 1 2 1 3。

数据2: 4 9

那每天穿的袜子的序列就是:

1 2 3 4 1 2 3 1 2 那么第七天穿的袜子就是编号2,

如果我们接着往下看的话,就会发现整个序列是这样子的:

1 2 3 4 1 2 3 1 2 4 1 2 3 1 2 4 1 2 3 1 2 4 ······

就会发现除了前n天以外,穿的袜子的编号的循环节是 1 2 3 1 2 4。

通过上面的两组数据我们就可以发现他的循环规律:

我们将每个循环节的前半部分和后半部分分开,会发现最后一位是在n和n-1直接,前面的就是第几次去袜子对于(n-1)的一个余数。

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
long long int n,k,Case=1;
{
while(~scanf("%lld%lld",&n,&k))
{
printf("Case #%lld: ",Case++);
if(k<=n) ///直接输出来就行了
printf("%lld\n",k);
else
{
long long int num=(k-n)/(n-1);///num表示第几次取半循环
long long int yu=(k-n)%(n-1);///yu表示在半循环中取第几个
if(num%2==0)///偶数次
{
if(yu==0)///最后一个
printf("%lld\n",n);
else
printf("%lld\n",yu);
}
else///奇数次
{
if(yu==0)///最后一个
printf("%lld\n",n-1);
else
printf("%lld\n",yu);
}
}
}
}
return 0;
}

2017ACM暑期多校联合训练 - Team 1 1011 HDU 6043 KazaQ's Socks (找规律)的更多相关文章

  1. 2017ACM暑期多校联合训练 - Team 7 1010 HDU 6129 Just do it (找规律)

    题目链接 Problem Description There is a nonnegative integer sequence a1...n of length n. HazelFan wants ...

  2. 2017ACM暑期多校联合训练 - Team 2 1006 HDU 6050 Funny Function (找规律 矩阵快速幂)

    题目链接 Problem Description Function Fx,ysatisfies: For given integers N and M,calculate Fm,1 modulo 1e ...

  3. 2017ACM暑期多校联合训练 - Team 2 1011 HDU 6055 Regular polygon (数学规律)

    题目链接 **Problem Description On a two-dimensional plane, give you n integer points. Your task is to fi ...

  4. 2017ACM暑期多校联合训练 - Team 8 1011 HDU 6143 Killer Names (容斥+排列组合,dp+整数快速幂)

    题目链接 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith ...

  5. 2017ACM暑期多校联合训练 - Team 6 1011 HDU 6106 Classes (容斥公式)

    题目链接 Problem Description The school set up three elective courses, assuming that these courses are A ...

  6. 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 ...

  7. 2017ACM暑期多校联合训练 - Team 4 1004 HDU 6070 Dirt Ratio (线段树)

    题目链接 Problem Description In ACM/ICPC contest, the ''Dirt Ratio'' of a team is calculated in the foll ...

  8. 2017ACM暑期多校联合训练 - Team 9 1005 HDU 6165 FFF at Valentine (dfs)

    题目链接 Problem Description At Valentine's eve, Shylock and Lucar were enjoying their time as any other ...

  9. 2017ACM暑期多校联合训练 - Team 9 1010 HDU 6170 Two strings (dp)

    题目链接 Problem Description Giving two strings and you should judge if they are matched. The first stri ...

随机推荐

  1. Scrum Meeting Beta - 4

    Scrum Meeting Beta - 4 NewTeam 2017/12/2 地点:新主楼F座二楼 任务反馈 团队成员 完成任务 计划任务 安万贺 完成了部分页面标题栏颜色的修改和字体的调整Iss ...

  2. 201621123037 《Java程序设计》第4周学习总结

    #Week04-面向对象设计与继承 1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 关键词:超级父类."is-a".父类.子类.重载.继承.多态 1.2 尝 ...

  3. 软工网络15团队作业4-DAY7

    每日例会 昨天的工作. 张陈东芳:sql连接的基本完成,尝试被其他类调用,未导入全部商品信息: 吴敏烽:基本完成商品信息的调用: 周汉麟:设定商品的调用规则: 林振斌:设计缓存区代码,用于存取最近浏览 ...

  4. Jmeter 快速入门--简单的http压测

    1.添加线程组 打开jmeter主窗口后,选择左侧树形结构里的"测试计划",然后右键选择添加,选择"threads(users)",选择"线程组&qu ...

  5. 图文详解 IntelliJ IDEA 15 创建 Maven 构建的 Java Web 项目(使用 Jetty 容器)

    图文详解 IntelliJ IDEA 15 创建 maven 的 Web 项目 搭建 maven 项目结构 1.使用 IntelliJ IDEA 15 新建一个项目.  2.设置 GAV 坐标  3. ...

  6. ARP(Adress Resolution Protocol): 地址解析协议

    地址解析协议(Address Resolution Protoclol),其基本功能为通过目标设备的IP地址,查询目标设备的MAC地址,以保证通信的顺利.它是IPV4中网络层必不可少的协议.不过在IP ...

  7. C# WebBrowser控件模拟登录

    一.问题点: 1.模拟登录后,如果带有嵌套的iframe嵌套,不好读取iframe内容,可以直接指定iframe抓取网址 2.C# 清除WebBrowser控件的Session和Cookie 参考文档 ...

  8. 第77天:jQuery事件绑定触发

    一.元素操作 1. 高度和宽度 $(“div”).height(); // 高度 $(“div”).width(); // 宽度 .height()方法和.css(“height”)的区别: 返回值不 ...

  9. collection 在创建迭代器后 不能在添加数据 否则会出现并发问题

    collection 在创建迭代器后 不能在添加数据 否则会出现并发问题

  10. xshell代理设置

    1.宿主机设置隧道 上面的端口随意,不与本机使用的端口重合即可,下面的端口是管理系统的端口 2.宿主机上面创建的虚机设置代理 3.怎么通过web浏览器直接登录虚机ip网址:https://blog.c ...