hdu 6043 KazaQ's Socks

规律题。我自己写的规律对长度为2的要特判,wa一万次。。。

规律题目,容易错的反而是数据小的时候,得长记性。

题解:规律 先是1~n 然后1~n-2 n-1  1~n-2 n 交替出现

比如当n=4 的时候 1 2 3 4  1 2 3 1 2 4  1 2 3  1 2 4 ......

AC代码:

#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
int main()
{
    int Case=1;
    ll n,m;
    while(cin>>n>>m)
    {
        if(n==2)// 注意对2 特判。
        {
            if(m%2)  printf("Case #%d: %lld\n",Case,(ll)1);
            else   printf("Case #%d: %lld\n",Case,(ll)2);

            Case++;
            continue;
        }
        if(m<=n)
        {
           printf("Case #%d: %lld\n",Case,m);
           Case++;
           continue;
        }
        ll temp=m-n;
        ll ret=temp/(n-1);
        ll zz=temp%(n-1);
        if(zz!=0)
        {
            printf("Case #%d: %lld\n",Case,zz);
        }
        else
        {
            if(ret%2)
            {
                printf("Case #%d: %lld\n",Case,n-1);
            }
            else printf("Case #%d: %lld\n",Case,n);
        }
        Case++;
    }

}

 

posted @ 2017-07-26 15:07  猪突猛进!!!  阅读(87)  评论(0编辑  收藏  举报