【2017 Multi-University Training Contest - Team 1 1011】KazaQ's Socks

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;
                }
            }
        }
    }

}
posted @ 2017-10-04 18:44  AWCXV  阅读(58)  评论(0编辑  收藏  举报