KazaQ's Socks
来源:互联网 发布:联通网络电视客户端 编辑:程序博客网 时间:2024/05/23 19:16
Problem Description
KazaQ wears socks everyday.
At the beginning, he hasn 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 aren−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 thek -th day.
At the beginning, he has
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
KazaQ would like to know which pair of socks he should wear on the
Input
The input consists of multiple test cases. (about 2000 )
For each case, there is a line contains two numbersn,k (2≤n≤109,1≤k≤1018) .
For each case, there is a line contains two numbers
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 73 64 9
Sample Output
Case #1: 3Case #2: 1Case #3: 2
- /*
- 一共n双袜子编号1~n,每天早上选取编号最小的一双穿,
- 当晚上发现只剩一双袜子能穿时,把之前的袜子都洗了,
- 明天晚上就可以穿了。
- 问第k天穿的是编号为几的袜子
- 思路:
- 规律题,以四双为例,穿袜子的序列为:
- [1 2 3 4] [1 2 3] [1 2 4] [1 2 3]…[...]………
- 前n天 就是相应编号,超过n天后有规律,周期是n-1,
- 第一个周期是 [1 2 3]
- 第二个周期是 [1 2 4]
- 第三个周期是 [1 2 3]
- ……………………………………………………
- 第奇数个周期是[1 2 .... n-1];
- 第偶数个周期是[1 2 .... n];
- */
- #include <iostream>
- #include <cstdio>
- using namespace std;
- typedef unsigned long long ull;
- ull n,k;
- int main()
- {
- int t = 0;
- while (cin >> n >> k){
- t++;
- if (k <= n) {
- cout << "Case #" << t << ": " << k << endl;
- }
- else{
- k -= n;
- if (k % (n-1) != 0){
- cout << "Case #" << t << ": " << k % (n-1) << endl;
- }
- else{
- if ((k / (n-1)) % 2 == 0){
- cout << "Case #" << t << ": " << n << endl;
- }
- else{
- cout << "Case #" << t << ": " << n-1 << endl;
- }
- }
- }
- }
- return 0;
- }
阅读全文
0 0
- KazaQ's Socks
- KazaQ's Socks
- KazaQ's Socks
- 1011.KazaQ's Socks
- hdu6043--KazaQ's Socks
- HDU6043-KazaQ's Socks
- KazaQ's Socks
- HDU-KazaQ's Socks
- KazaQ's Socks
- KazaQ's Socks
- KazaQ's Socks
- hdu6043 KazaQ's Socks
- KazaQ's Socks
- KazaQ's Socks
- KazaQ's Socks HDU
- 杭电 KazaQ's Socks
- HDU 6043 KazaQ's Socks
- HDU6043 KazaQ's Socks【规律】
- text-align/align
- 是否有一种完美语言来终结“编程语言之争”?
- java:获取字符串中第一个汉字和第一个汉字汉字标点符号的位置
- RHEL 6.3使用CentOS yum源 (redhat yum安装失败)
- 今日头条 2017年秋招编程题 :“最大乘积和”
- KazaQ's Socks
- 面试or笔试2——等概率生成0,1
- jsp的简单了解,6中JSP页面元素的简单应用
- MYSQL触发器T-SQL
- Beginning Spring学习笔记——第5章(一)ORM和JPA基础
- Android签名验证原理解析
- HashSet,TreeSet,LinkedHashSet 的用法和区别
- 剑指offer(十三)调整数组顺序使奇数位于偶数前面
- 在有序但含有空的数组中查找字符串