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


你可能感兴趣的:(51nod1613 翻硬币)