HDU6043 KazaQ's Socks

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

Code:

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <ctype.h>

using namespace std;

int main()
{
    long long int n,k,cnt=0;
    while(cin>>n>>k)
    {
        if(n>=k)
            cout<<"Case #"<<cnt++<<": "<<k<<endl;
        else
        {
            int a=(k-n)/(n-1),b=(k-n)%(n-1);
            if(b!=0)
                cout<<"Case #"<<cnt++<<": "<<b<<endl;
            else
            {
                if(a%2==0)
                    cout<<"Case #"<<cnt++<<": "<<n<<endl;
                else
                    cout<<"Case #"<<cnt++<<": "<<n-1<<endl;
            }
        }
    }
    return 0;
}

HDU6043 KazaQ's Socks

时间: 2024-10-10 08:02:26

HDU6043 KazaQ's Socks的相关文章

杭电 KazaQ&#39;s Socks

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

HDU 6043 KazaQ&#39;s Socks (规律)

Description KazaQ wears socks everyday. At the beginning, he has nn pairs of socks numbered from 11 to nn 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 sock

hdu 6043 KazaQ&#39;s Socks

规律题.我自己写的规律对长度为2的要特判,wa一万次... 规律题目,容易错的反而是数据小的时候,得长记性. 题解:规律 先是1~n 然后1~n-2 n-1  1~n-2 n 交替出现 比如当n=4 的时候 1 2 3 4  1 2 3 1 2 4  1 2 3  1 2 4 ...... AC代码: #include <cstdio> #include <iostream> using namespace std; typedef long long ll; int main()

2017 Multi-University Training 1 解题报告

Add More Zero Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2245    Accepted Submission(s): 1053 Problem Description There is a youngster known for amateur propositions concerning several ma

【补题】多校联合训练第一场

1001  Add More Zero Problem Description There is a youngster known for amateur propositions concerning several mathematical hard problems.Nowadays, he is preparing a thought-provoking problem on a specific type of supercomputer which has ability to s

CodeForces 731C Socks

http://codeforces.com/problemset/problem/731/C 并查集+贪心 将要求颜色相同的袜子序号放入一个集合中 贪心:然后统计这个集合中出现次数最多但颜色 可以得到这个集合要repain的次数 代码有难度 统计集合数 int tot;//总的集合数 for (int i = 1; i <= n; i++) if(par[i] == i) { rec[tot++] = i;//记录根节点 } //统计每个集合红颜色的个数 map<int, int> cl

Linux VPS上使用kingate搭建socks代理服务器

kingate 是一位国人开发的代理服务器 ,支持http,socks,ftp等多种协议.支持多线程.tcp端口映射.规则控制.时间控制.用户认证.http管理等功能. kingate官网:http://sourceforge.net/projects/kingate/ 安装所需的依赖包 Debian: apt-get install build-essential automake make gcc g++CentOS: yum install make automake gcc gcc-c+

python抓取数据,python使用socks代理抓取数据

在python中,正常的抓取数据直接使用urllib2 这个模块: import urllib2 url = 'http://fanyi.baidu.com/' stream = urllib2.urlopen(url) cont = stream.read() print cont 如果要走http代理的话,我们也可以使用urllib2,不需要引用别的模块: import urllib2 url = 'https://clients5.google.com/pagead/drt/dn/dn.j

BadVPN详解之--始记:透明socks代理与tun2socks

上周六晚上闲来无事跟以前的同事聊天,问之最近有没有接触到什么比较好玩的技术,答曰tun2socks.这个正合我的胃口,我所谓的好玩的技术是那种简单,有用的技术点或者技术框架,能在10分钟内领略其原理和思想,能在20分钟内跑起来,能在半天内彻底剖析它的结构,能在此后很久的时间受益无穷.OpenVPN就是这样的"好玩"的东西,网卡点灯也算,tun2socks是另一个,当然还有一个更好玩的,那就是BadVPN,我要在另外的文章中单独介绍.本文先来介绍tun2socks,它其实是BadVPN的