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;
} 
目录
相关文章
|
人工智能 搜索推荐
基于 PAI-ArtLab 使用 ComfyUI 生成人像写真
本实验基于SDXL、InstantID技术,解决AI人像摄影中人物面部特征在风格迁移与图像放大后无法高度还原的问题。内置6种儿童风格提示词模板及提示词翻译模块,支持中文书写相关图像提示词测试个性化风格。需登录阿里云PAI ArtLab平台操作,领取免费试用资源后,通过ComfyUI(专享版)拉起服务并加载工作流,上传图片、选择草图、更换连线等步骤生成不同风格成果。还提供自定义风格模块和常见问题解答,方便用户解锁更多玩法。
QGS
|
Java 关系型数据库 MySQL
浅学lombok
浅学lombok
QGS
289 1
|
机器学习/深度学习 人工智能 自然语言处理
从此告别PPT制作的烦恼:ChatGPT和MindShow帮你快速完成
从此告别PPT制作的烦恼:ChatGPT和MindShow帮你快速完成
|
Python
Python中遇到奇怪的错误ValueError: bad marshal data
不是代码出的问题,是*.pyc文件被改动了。解决方法,删除所有*.pyc文件再运行
5356 0
|
JSON 数据格式
DTHttpJson UE4插件使用说明
DTHttpJson UE4插件使用说明
880 0
|
JavaScript 测试技术 编译器
从0搭建Vue3组件库:引入单元测试框架Vitest
从0搭建Vue3组件库:引入单元测试框架Vitest
1427 0
|
Linux 网络安全 Python
CentOS7下安装SSHGuard阻止SSH暴力破解攻击
CentOS7下安装SSHGuard阻止SSH暴力破解攻击
728 0
CentOS7下安装SSHGuard阻止SSH暴力破解攻击
|
机器学习/深度学习 存储 自然语言处理
基础与构建:GraphRAG架构解析及其在知识图谱中的应用
【10月更文挑战第11天】随着数据的不断增长和复杂化,传统的信息检索和生成方法面临着越来越多的挑战。特别是在处理结构化和半结构化数据时,如何高效地提取、理解和生成内容变得尤为重要。近年来,一种名为Graph Retrieval-Augmented Generation (GraphRAG) 的新架构被提出,它结合了图神经网络(GNNs)和预训练语言模型,以提高多模态数据的理解和生成能力。本文将深入探讨GraphRAG的基础原理、架构设计,并通过实际代码示例展示其在知识图谱中的应用。
2081 0
|
数据采集 机器学习/深度学习 人工智能
基于AI的网络流量分析:构建智能化运维体系
基于AI的网络流量分析:构建智能化运维体系
2277 13
|
机器学习/深度学习 传感器 自动驾驶
基于深度学习的图像识别技术及其在自动驾驶中的应用####
本文深入探讨了深度学习驱动下的图像识别技术,特别是在自动驾驶领域的革新应用。不同于传统摘要的概述方式,本节将直接以“深度学习”与“图像识别”的技术融合为起点,简述其在提升自动驾驶系统环境感知能力方面的核心作用,随后快速过渡到自动驾驶的具体应用场景,强调这一技术组合如何成为推动自动驾驶从实验室走向市场的关键力量。 ####
430 24

热门文章

最新文章

下一篇
开通oss服务