zoukankan      html  css  js  c++  java
  • 杭电 KazaQ'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. If there are n1 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.
    InputThe input consists of multiple test cases. (about 2000)

    For each case, there is a line contains two numbers n,k (2n109,1k1018).OutputFor 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
     
    找规律的题目,拿n=5来说,从第一天开始依次为123451234123512341235,前五个对应1-5,即前n个对应1-n,之后每(n-1)个为单位变化,所以对于k<=n,直接输出k,对于k>n,k-=n,此时再对k履行那个规律,见代码。
     
    #include <iostream>
    #include <algorithm>
    #include <map>
    #include <cstdio>
    using namespace std;
    int which(long long n,long long k)
    {
        if(k<=n)return k;
        k-=n;//规律
        int d=k%(n-1);
        int c=k/(n-1);
        if(d)return d;
        return n-(c%2);
    }
    int main()
    {
        long long n,k;
        int i=1,d;
        while(cin>>n>>k)
        {
            d=which(n,k);
            printf("Case #%d: %d
    ",i,d);
            i++;
        }
    }
  • 相关阅读:
    Halcon学习笔记之缺陷检测(二)
    tensorflow常用函数库
    luogu P2765 魔术球问题 (最小路径覆盖)
    luogu P2423 [HEOI2012]朋友圈 (最大团)
    poj 2226 Muddy Fields (二分图)
    匈牙利算法板子
    二分图
    AC日记——【模板】树链剖分 洛谷 P3384
    AC日记——[ZJOI2008]树的统计Count bzoj 1036
    去重排序
  • 原文地址:https://www.cnblogs.com/8023spz/p/7498951.html
Copyright © 2011-2022 走看看