您的位置:首页 > 其它

hdu 6043 KazaQ's Socks

2017-07-26 15:07 260 查看
规律题。我自己写的规律对长度为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++;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: