HDU 6043 KazaQ's Socks【规律】
来源:互联网 发布:加内特职业生涯总数据 编辑:程序博客网 时间:2024/06/01 07:52
KazaQ's Socks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 938 Accepted Submission(s): 578
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
Source
2017 Multi-University Training Contest - Team 1
规律:[1.....n] [1....(n-1)] [1....(n-2) n ] [1...(n-1)] [1....(n-2) n ]........
循环节:(n-1)+(n-2)+1
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<queue>#include<stack>#include<vector>#include<map>#include<set>#include<algorithm>using namespace std;#define ll long long#define ms(a,b) memset(a,b,sizeof(a))#define maxn 510const int M=1e6+10;const int inf=0x3f3f3f3f;const int mod=1e9+7;const double eps=1e-10;ll n,m;int main(){ int cas=1; while(~scanf("%lld%lld",&n,&m)) { if(m<=n)printf("Case #%d: %lld\n",cas++,m); else { m-=n; ll loop=(n-1)+(n-2)+1; ll ans=(m-1)%loop+1; if(ans<=n-1)printf("Case #%d: %lld\n",cas++,ans); else if(ans<=(n-1)+(n-2))printf("Case #%d: %lld\n",cas++,ans-(n-1)); else printf("Case #%d: %lld\n",cas++,n); } } return 0;}
阅读全文
0 0
- HDU 6043 KazaQ's Socks 找规律
- HDU 6043 KazaQ's Socks 【规律】
- HDU 6043 KazaQ's Socks【规律】
- hdu 6043 KazaQ's Socks(规律)
- HDU 6043(KazaQ's Socks) 规律题 Java
- HDU 6043 KazaQ's Socks
- hdu 6043 KazaQ's Socks
- HDU 6043 KazaQ's Socks
- HDU 6043 KazaQ's Socks
- HDU-KazaQ's Socks
- KazaQ's Socks HDU
- HDU6043 KazaQ's Socks【规律】
- HDU 6043 KazaQ's Socks(周期)
- HDU 6043 KazaQ's Socks(水~)
- (数学)HDU 6043 KazaQ's Socks
- 2017杭电多校联赛 1011 KazaQ's Socks(找规律)HDU 6043
- HDU 6043 KazaQ's Socks(暑期训练1011)
- 【多校训练】hdu 6043 KazaQ's Socks
- The First Ryu Application
- 在Ubuntu16.04上安装QQ
- UVA
- 退了实验室之后的生活
- 图片在块级元素中的对齐问题(取消图片在垂直和水平方向上的空隙)
- HDU 6043 KazaQ's Socks【规律】
- Mac下的解压命令
- 使用wsimport生成客户端java类
- 动态顺序表的实现
- 嵌入式Linux驱动笔记(七)------浅析tty与uart框架
- 【算法设计与数据结构】为何程序员喜欢将INF设置为0x3f3f3f3f?
- Activiti教学项目Lemon OA
- poj2828(线段树单点更新)
- 1、指针与递归