Codeforces Round #412 B. T-Shirt Hunt

来源:互联网 发布:股票买卖软件下载3.0 编辑:程序博客网 时间:2024/05/17 04:07

Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt.

Unfortunately, you didn’t manage to get into top 25, but you got into top 500, taking place p.

Now the elimination round of 8VC Venture Cup 2017 is being held. It has been announced that the Codecraft-17 T-shirt winners will be chosen as follows. Let s be the number of points of the winner of the elimination round of 8VC Venture Cup 2017. Then the following pseudocode will be executed:

i := (s div 50) mod 475repeat 25 times:    i := (i * 96 + 42) mod 475    print (26 + i)

Here “div” is the integer division operator, “mod” is the modulo (the remainder of division) operator.

As the result of pseudocode execution, 25 integers between 26 and 500, inclusive, will be printed. These will be the numbers of places of the participants who get the Codecraft-17 T-shirts. It is guaranteed that the 25 printed integers will be pairwise distinct for any value of s.

You’re in the lead of the elimination round of 8VC Venture Cup 2017, having x points. You believe that having at least y points in the current round will be enough for victory.

To change your final score, you can make any number of successful and unsuccessful hacks. A successful hack brings you 100 points, an unsuccessful one takes 50 points from you. It’s difficult to do successful hacks, though.

You want to win the current round and, at the same time, ensure getting a Codecraft-17 T-shirt. What is the smallest number of successful hacks you have to do to achieve that?

题意

很有趣的题面,通过 successful hack 和 unsuccessful hack 增减 Round 的 points,以此达到通过下述随机数生成器生成的数恰好存在 p 。要求 points 不得低于 y ,且通过 AC 已经获得了 x points 。问最少的 successful hack 次数。

i := (s div 50) mod 475repeat 25 times:    i := (i * 96 + 42) mod 475    print (26 + i)

解题思路

根据该随机数生成器可以知道初始 i 是 (s div 50) mod 475 得到的,即 i[0,475) ,由于必然有解,则通过枚举最多进行 475 次,对时间复杂度没有过多要求。

由于要求 successful hack 次数最少,即该场 Round 分数应尽可能低,分数的可能性为 x+k50 。故令 X 为满足 X=x+k50Xy 的最小值。每次增加 50 points 同时判断是否能满足随机数出现 p 。

代码

#include<bits/stdc++.h>using namespace std;int p, x, y;bool jug(int s){    int i = s/50 % 475;    for(int ica=0;ica<25;ica++) {        i = (i*96 + 42) % 475;        if(i+26 == p)   return true;    }    return false;}int main(){    scanf("%d %d %d",&p,&x,&y);    int X = x, ans = 0;    while(X-50 >= y)    X-=50;    while(1) {        if(jug(X)) {            printf("%d\n", ans);            return 0;        }        X += 50;        if(X-x == 50)   ans++,  x+=100;    }}
0 0
原创粉丝点击