您的位置:首页 > 其它

【HDU】6043 - KazaQ's Socks(思维)

2017-07-26 09:25 411 查看
题目链接:点击打开题目



这个写一串例子就知道规律了。

代码如下:

#include<queue>
#include<cmath>
#include<stack>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f
#define CLR(a,b) memset(a,b,sizeof(a))
#define PI acos(-1.0)
int main()
{
LL n,k;
int Case = 1;
while (~scanf ("%lld %lld",&n,&k))
{
printf ("Case #%d: ",Case++);
if (n == 2)
{
printf ("%lld\n",((k-1)%2)+1);
continue;
}
if (k <= n)
printf ("%lld\n",k);
else
{
k -= n - 1;
LL ant = ((k-1) / (n-1)) + 1;
LL rest = ((k-1) % (n-1)) + 1;
if (rest == 1)
printf ("%lld\n",(ant & 1) ? n : n-1);
else
printf ("%lld\n",rest-1);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: