【codeforces 807B】TShirt Hunt

【题目链接】:http://codeforces.com/contest/807/problem/B

【题意】

你在另外一场已经结束的比赛中有一个排名p;
然后你现在在进行另外一场比赛
然后你当前有一个分数x;
以及另外一个分数y,表示如果要拿第一需要的分数;
你可以通过hack使得分数x大于分数y;
然后你最后的分数x会决定你那个排名p能不能在已经结束的那场比赛中拿到奖品;
问你技能拿到奖品,又能在这场比赛中夺冠;至少需要hack成功多少次(失败的不需要输出);
(hack规则和cf的一样)

【题解】

如果x< y
则一直给x递增100;
则只要可以保证x>y,就能一直减50分;
然后看看你的分数能不能让你在第p名拿到奖品;
这种情况下,成功hack次数都为0,只是一直是失败的hack;
否则;
然后变回初始的x;
每次考虑hack成功一次以及hack成功和失败各一次的情况;
即+100和+50(这两种情况都是hack成功次数+1能覆盖的情况)
写个暴力就好;
判断分数为x的时候排名为P能不能拿到奖品,可以写个函数

【Number Of WA

0

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e3+100;;

int p,x,y,cnt=0;

bool pd(int s)
{
    int i = (s/50)%475;
    rep1(j,1,25)
    {
        i = (i*96+42)% 475;
        if (i+26==p) return true;
    }
    return false;
}

int main()
{
    //freopen("F:\\rush.txt","r",stdin);
    ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not use
    cin >> p >> x >> y;
    while (x<y)
    {
        x+=100;
        cnt++;
    }
    int tx = x;
    while (x-50>=y)
    {
        x-=50;
        if (pd(x))
            return cout << cnt << endl,0;
    }
    x = tx;
    while (!pd(x))
    {
        cnt++;
        x+=50;
        if (pd(x)) break;
        x+=50;
    }
    cout << cnt << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/AWCXV/p/7626334.html