51nod1613 翻硬币

链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1613

题意:中文题。。。

分析:自己找规律找出一些,并不会系统分析,完整的分析在这:https://www.zhihu.com/question/26570175。膜膜膜。

代码:

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<math.h>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=10010;
const int MAX=151;
const int MOD1=100000007;
const int MOD2=100000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000007;
const ll INF=10000000010;
typedef unsigned long long ull;
int eve(int x) {
    if (x&1) return x+1;
    return x;
}
int odd(int x) {
    if (x&1) return x;
    return x+1;
}
int get(int n,int k) {
    int ans=n/k-1;
    n-=ans*k;
    if (n&1) return ans+3;
    return ans+2;
}
int main()
{
    int n,k;
    scanf("%d%d", &n, &k);
    if (n&1) {
        if (k&1) printf("%d\n", get(n,k));
        else printf("-1\n");
    } else {
        if (k>n/2) {
            if (k&1) printf("%d\n", eve(n/(n-k)+bool(n%(n-k))));
            else printf("3\n");
        } else {
            if (k&1) printf("%d\n", eve(n/k+bool(n%k)));
            else printf("%d\n", n/k+bool(n%k));
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值