1011.KazaQ's Socks
来源:互联网 发布:风水织梦网站源码 编辑:程序博客网 时间:2024/06/05 03:40
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 9Sample Output
Case #1: 3
Case #2: 1
Case #3: 2
题解如下
找规律即可。规律是
1,2,⋯,nn numbers, 1,2,⋯,n−1n−1 numbers, 1,2,⋯,n−2,nn−1 numbers, 1,2,⋯,n−1n−1 numbers, 1,2,⋯,n−2,nn−1 numbers,
⋯
⋯ 。
//0MS 1508K#include <cstdio> #include <cstring> #include <algorithm> #include <cmath>typedef long long int ll;using namespace std;int main(){ int cas=1; ll n,k,i; while(scanf("%lld%lld",&n,&k)!=EOF){ printf("Case #%d: ",cas); cas++; if(k<=n){ printf("%lld\n",k); continue; } else{ ll wei,danjie=(k-n)/(n-1); if((k-n)%(n-1)){ danjie++; wei=(k-n)%(n-1); } else{ wei=n-1; } if(danjie%2==0){ if(wei<n-1){ printf("%lld\n",wei); } else{ printf("%lld\n",n); } } if(danjie%2==1){ if(wei<n-1){ printf("%lld\n",wei); } else{ printf("%lld\n",n-1); } } } } return 0;}
- 1011.KazaQ's Socks
- KazaQ's Socks
- KazaQ's Socks
- 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【规律】
- 我的刷机之旅
- 代理模式(Proxy Pattern)。
- 170724 社工-领英爬虫
- wait和notify
- jQuery实现栏目切换
- 1011.KazaQ's Socks
- js请求
- 51nod 1629 B君的圆锥
- 实现右旋、左旋循环移位函数
- Codeforces 832 D. Misha, Grisha and Underground 倍增法求LCA
- leetcode#155. Min Stack
- 《最强大脑——77招让你成为脑力最好的人》读书笔记
- A
- mysqldump全备份及结合binlog日志恢复的全过程 (转)