题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6043

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和第几天k,问你第k天穿的袜子序号为几。
题解:可以通过分析n=3和n=4的情况来推断,打括号的说明是一起洗的。
          n=3:(1 2)( 3 1 )(2 1)( 3 1)( 2 1)( 3 1).....
          n=4:  (1 2 3) (4 1 2) (3 1 2) (4 1 2) (3 1 2) (4 1 2) (3 1 2)......
          除去第一个括号,每一个括号的开头都是仅剩的最后一双袜子,然后会从上一括号中洗好的再选(0~n-2)双,所以就有了这样的规律。
 
 #include<iostream>
#include<cstdio> using namespace std; int main()
{
int t=;
long long n,k,res;
while(~scanf("%lld%lld",&n,&k))
{
if(k<=n)
{
res=k;
}
else
{
k-=n;
int q=k%(n-);
if(q==)
if(k/(n-)%==)
res=n;
else
res=n-;
else
res=q;
}
printf("Case #%d: %lld\n",t++,res);
}
return ;
}

HDU6043 17多校1 KazaQ's Socks 水题的更多相关文章

  1. 17 多校1 Add More Zero 水题

    Problem Description There is a youngster known for amateur propositions concerning several mathemati ...

  2. HDU 6140 17多校8 Hybrid Crystals(思维题)

    题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...

  3. 2019浙大校赛--E--Potion(签到水题)

    一丢丢思维就ok 题目大意: 魔法师要煮药,有n个等级的药,所需要的药物为a1,a2...an,意为第n级需要多少药物,下一行为库存的不同等级药物,药物可降级使用不可升级. 思路:从高级药物开始解,把 ...

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

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

  5. HDU6043 KazaQ's Socks

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

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

  7. HDU 6043 KazaQ's Socks (规律)

    Description KazaQ wears socks everyday. At the beginning, he has nn pairs of socks numbered from 11  ...

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

  9. 杭电 KazaQ's Socks

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

随机推荐

  1. ECharts 报表事件联动系列四:柱状图,折线图,饼状图实现联动

    代码如下: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" c ...

  2. [洛谷 P1972] HH的项链(SDOI2009)

    P1972 [SDOI2009]HH的项链 题目描述 HH 有一串由各种漂亮的贝壳组成的项链.HH 相信不同的贝壳会带来好运,所以每次散步完后,他都会随意取出一段贝壳,思考它们所表达的含义.HH 不断 ...

  3. linux文件软链接、硬链接

    在linux ext2文件系统中,一个文件的属性存放在inode中,而数据存放在block中.每个文件占用一个inode,inode中记录了文件的权限和block地址,通过inode可以定位到bloc ...

  4. nodejs利用sequelize-auto 根据数据库的table 生成model

    1.打开cmd命令窗口,安装sequelize-auto npm install -g sequelize-auto 在使用sequelize-auto之前需要安装全局的mysql(举例mysql) ...

  5. Qt贴图实现地图标记效果

    #include "wgtmap.h" #include "ui_wgtmap.h" #include <QPainter> #define IMG ...

  6. Scanner类完成用户键盘录入

    l  Scanner类 Scanner类是引用数据类型的一种,我们可以使用该类来完成用户键盘录入,获取到录入的数据. Scanner使用步骤: 导包:import java.util.Scanner; ...

  7. input text 在苹果微信浏览器中有上上阴影

    box-shadow:0px 0px 0px rgba(0,0,0,0); -webkit-appearance:none;

  8. django自定义标签,int转化为str类型

    1.在app中创建templatetags目录,目录名必须为templatetags 2.在目录templatetags中创建一个.py文件,例如 strFilter.py strFilter.py ...

  9. day04流程控制之while循环

    流程控制之while循环 1.什么是while循环 循环指的是一个重复做某件事的过程 2.为何有循环 为了让计算机能像人一样重复 做某件事 3.如何用循环 ''' # while循环的语法:while ...

  10. java局部变量,成员变量在堆和栈中的存储

    对于局部变量,如果是基本类型,会把值直接存储在栈:如果是引用类型,比如String s = new String("william");会把其对象存储在堆,而把这个对象的引用(指针 ...