zoukankan      html  css  js  c++  java
  • 【2017 Multi-University Training Contest

    Link:http://acm.hdu.edu.cn/showproblem.php?pid=6043

    Description

    一个人壁橱里有n双袜子,每天早上取一双最小下标的袜子,然后晚上放到篮子里;当篮子里的袜子个数到达n-1的时候,他会把它们全部洗一遍,然后第二天再把这n-1双放到壁橱里(先取完最后那一只在壁橱里的再把n-1双放进去);

    Solution

    可以模拟一下取袜子的序列,比如有4只袜子
    1 2 3 4 1 2 3 1 2 4 1 2 3 1 2 4
    可以发现;
    一开始n个是1..n
    然后是1..n-2,n-1以及1..n-2,n交替出现了

    NumberOf WA

    0

    Reviw

    规律题。

    Code

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    const int INF = 0x3f3f3f3f;
    
    
    int main()
    {
        ios::sync_with_stdio(false);
        ll n,k;
        int cc = 1;
        while(cin>>n>>k)
        {
            cout<<"Case #"<<cc++<<": ";
            if(n==2)
            {
                cout<<(2-k%2)<<endl;
            }else
            {
                if(k<=n)
                {
                    cout<<k<<endl;
                }else
                {
                    k -= (n-1);
                    int t = k%(2*(n-1));
                    if(t==0)
                        t = 2*(n-1);
                    if(t==1)
                    {
                        cout<<n<<endl;
                    }else if(t==n)
                    {
                        cout<<n-1<<endl;
                    }else
                    {
                        if(t<=n-1)
                            cout<<t-1<<endl;
                        else
                            cout<<t-n<<endl;
                    }
                }
            }
        }
    
    }
    
  • 相关阅读:
    适配器模式
    第五章项目:QuickHit
    试题分析(第二套)
    试题分析(第一套)
    新闻发布系统(分页显示)
    jsp九大内置对象
    文件上传
    jsp统测
    新闻发布系统(首页)
    URL和URI的区别
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626163.html
Copyright © 2011-2022 走看看