【多校联合】(HDU6043)KazaQ’s Socks

一条纯粹的水题,记录下只是因为自己错的太多而已。

原因在于对数据的细节的把握不佳。

原题

KazaQ’s Socks

  • Time Limit: 2000/1000 MS (Java/Others)
  • Memory Limit: 131072/131072 K (Java/Others)

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

代码

#include <iostream>
#include <bits/stdc++.h>
using namespace std; typedef long long ll; int main()
{
ll n,k,kase=0;
while(cin>>n>>k)
{
cout<<"Case #"<<++kase<<": ";
if(k>n)
{
k-=n;
int flag=(k/(n-1)+1)%2;
if(flag)
cout<<int(k%(n-1)==0?n:k%(n-1))<<endl;
else cout<<int(k%(n-1)==0?n-1:k%(n-1))<<endl;
}
else cout<<k<<endl;
}
return 0;
}

Original Address

最新文章

  1. SQL记录
  2. android性能优化练习:过度绘制
  3. Writing to a MySQL database from SSIS
  4. Moses训练与测试
  5. pdf转word
  6. HFSS 边界条件
  7. 20145208《Java程序设计》第2周学习总结
  8. SQL 数据类型,增删改查语句
  9. 总结: Struts2 + Spring 的线程安全问题
  10. Import data from SQLServer with Sqoop
  11. POJ 3094 Quicksum(简单的问题)
  12. Android应用开发基础篇(8)-----SurfaceView
  13. lca转RMQ
  14. 【知识整理】这可能是最好的RxJava 2.x 教程(完结版)
  15. win10 uwp 视差效果
  16. SpringMVC配置双数据源,一个java项目同时连接两个数据库
  17. linux系统中,文件的三种特殊权限
  18. Win10系统盘制作及安装流程
  19. java实现多个文件以压缩包导出到本地
  20. poj1958 strange towers of hanoi

热门文章

  1. 2018.10.2 Eclipse中如何测地修改一个we项目步骤
  2. 【luogu P3369 普通平衡树(Treap/SBT)】 模板 Splay
  3. Entity Framework 五
  4. Question 20171116 StringBuffer和StringBuilder的扩容机制
  5. Linux CentOS7下安装Zookeeper-3.4.10服务(最新)
  6. spring入门(七) spring mvc+mybatis+generator
  7. UICollectionViewCell「居左显示」
  8. 设置全局导航栏颜色,标题大小和UIBarButtonItem字体大小
  9. Struts2知识点小结(四)--拦截器与注解开发
  10. Percona-Tookit工具包之pt-ioprofile