1011.KazaQ's Socks

简介: Problem Description KazaQ wears socks everyday.

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

题解如下

找规律即可。规律是 1,2,,nn numbers,1,2,,n1n1 numbers,1,2,,n2,nn1 numbers,1,2,,n1n1 numbers,1,2,,n2,nn1 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;
} 
目录
相关文章
|
1月前
|
数据安全/隐私保护
socks5代理
socks5代理使用密码认证时无法打开文档
138 3
|
5月前
|
Go
socks5 搭建代理服务
socks5 搭建代理服务
253 0
|
1天前
|
监控 安全 网络协议
SOCKS/SOCKS5代理协议是什么
SOCKS代理协议是客户端与服务器间通信的桥梁,通过中间服务器实现安全连接。SOCKS5是其升级版,增加了用户认证、UDP支持和IPv6地址功能,提供更强加密和更高安全性。常用于匿名浏览、企业流量监控及网络访问安全。理解其原理并恰当使用,能保障网络隐私和安全。
|
6天前
|
网络协议 安全 网络安全
Socks VS HTTP 谁才是最快的代理协议
Socks VS HTTP 谁才是最快的代理协议
|
1月前
|
数据采集 缓存 监控
Socks5 与 HTTP 代理在网络安全中的应用
Socks5 与 HTTP 代理在网络安全中的应用
12 0
|
4月前
|
数据采集 网络协议 安全
http代理ip和socks代理ip有什么区别?哪个好?
HTTP(HyperText Transfer Protocol)即超文本传输协议。是Internet上行信息传输时使用最为广泛的一种非常简单的网络协议。Socks是一种网络传输协议,主要用于客户端与外网服务器之间通讯的中间传递。
|
缓存 网络协议 安全
使用s5代理服务(socks5代理)可以做哪些事?其链接速度如何?
使用Socks5代理可以做很多事情,从保护你的隐私到访问受限制的网站。
|
网络协议 网络安全 网络架构
SOCKS5协议
SOCKS5协议
162 0
|
Shell 开发工具 数据安全/隐私保护
SS5 - SOCKS5 代理服务器安装
SS5 - SOCKS5 代理服务器安装
930 0
|
缓存 网络协议 搜索推荐
网络协议之:haproxy的Proxy Protocol代理协议
代理大家应该都很熟悉了,比较出名的像是nginx,apache HTTPD,stunnel等。 我们知道代理就是代替客户端向服务器端进行消息请求,并且希望在代理的过程中保留初始的TCP连接信息,例如源和目标IP和端口等,以提供一些个性化的操作。 一般情况下,为了实现这个目标,有一些现成的解决办法,比如在HTTP协议中,可以使用“X-Forwarded-For”标头,来包含有关原始源地址,还有”X-Original-To”用来携带目的地址的信息。