题目传送: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. 笔记react router 4(一)

    用过react router4.X的小伙伴一定知道,比起3.X的版本,router的使用上有了很大的改变. 首先,我们只需要安装 react-router-dom 即可使用.看到“dom”想必你就该知 ...

  2. php自动填充

    1.str_pad() 函数把字符串填充为新的长度. 2.str_pad(string,length,pad_string,pad_type) 参数 描述 string 必需.规定要填充的字符串. l ...

  3. mybatis的update使用选择

    更新后台设置时,会分多个页面更新同一个表中的数据,愿想是尽量减少sql请求数据量并且减少重复代码. 比如博客园的: 假如只有一个用户信息表,这样的话每个页面只更新部分字段. 这种情况下的更新推荐在xm ...

  4. Django之WSGI 和MVC/MTV

    一.什么是WSGI? WEB框架的本质是一个socket服务端接收用户请求,加工数据返回给客户端(Django),但是Django没有自带socket需要使用 别人的 socket配合Django才能 ...

  5. 牛客网 PAT 算法历年真题 1009 : 1019. 数字黑洞 (20)

    1019. 数字黑洞 (20) 时间限制 1000 ms 内存限制 32768 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小) 题目描述 给定任一个各位数字不完全相同的4 ...

  6. VLC添加水印

    Name: LibVLC control APIDescription: VLC media player external control libraryVersion: 2.1.3 参照:http ...

  7. springMVC中对HTTP请求form data和request payload两种数据发送块的后台接收方式

    最近在做项目中发现,前台提交数据时,如果通过form表单提交和ajax发送json时,springMVC后台接收不能都通过@ModelAttribute方式处理,经过一番查找后,ajax发送json请 ...

  8. nodejs安装 淘宝镜像

    1◆ nodejs下载 2◆ 安装 3◆ 测试   4◆ 淘宝镜像 npm install -g cnpm --registry=https://registry.npm.taobao.org   5 ...

  9. Java Web(二) Servlet详解

    什么是Servlet? Servlet是运行在Web服务器中的Java程序.Servlet通常通过HTTP(超文本传输协议)接收和响应来自Web客户端的请求.Java Web应用程序中所有的请求-响应 ...

  10. laravel的firstOrCreate的作用:先查找表,如果有就输出数据,如果没有就插入数据

    public function zan(Post $post){ $param=[ 'user_id'=>\Auth::id(), 'post_id'=>$post->id ] Za ...