Cattle-off practice match 44 B segment small y (thinking)

Links: https://ac.nowcoder.com/acm/contest/634/B
Source: Cattle-off network

Title Description
gives the n line segments, the length of the i-th segment is a_ia
i , can jump to each line segment i + 1 j + 1 from the position of a position j in the i-th segment. If the first i + 1 less than the length of the line segment j + 1, then will return to the 0 position segments in Article i, then continue to jump. Q jump from the n-th segment of the i-th segment 0 how many hops the desired position in order to reduce the amount of input, a way to get the following array by unsigned int SA, SB, SC; int MOD; unsigned int Rand () { SA ^ = << 16 SA; SA = SA ^ >>. 5; SA = SA ^ <<. 1; unsigned int = T SA; SA = SB; SB = SC; SC ^ = T ^ SA; return SC; } int main () { CIN >> n-MOD >> >> >> SA SB SC >>; for (int I =. 1; I <= n-; ++ I) A [I] = Rand () MOD +%. 1; } input description : The first line two positive integers n, mod, showing a total of n line segments





















The second line of three numbers, respectively SA, SB, SC
outputs Description:
line a number indicating the number of segments n and from each jump.
Example 1
Input
replication
. 5. 5
. 5. 6. 4
output
copy
13

Ideas:

Suppose each of a [i] are infinitely long, then ans = n * (n-1) / 2

Then we think about the extra jump come from it?

When i + 1 if the first is less than the length of the line segment j + 1, it will return to the i-th line of 0 position, there will be more of a jump.

Then we can know if a position i, went to the j-th segment will jump to the 0 position, then all of the above because i will limit the length of the line segment between i and j jump more than once (you can understand how the drawing. )

Then we can push down from back to front, i look at those in line with the above, do the answers to accumulate.

See details Code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {ll ans = 1; while (b) {if (b % 2) { ans = ans * a % MOD; } a = a * a % MOD; b /= 2;} return ans;}
inline void getInt(int *p);
const int maxn = 20000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
unsigned int SA, SB, SC;
int mod;
int n;
unsigned int a[maxn];
unsigned int Rand()
{
    SA ^= SA << 16;
    SA ^= SA >> 5;
    SA ^= SA << 1;
    unsigned int t = SA;
    SA = SB;
    SB = SC;
    SC ^= t ^ SA;
    return SC;
}
int main()
{
    //freopen("D:\\code\\text\\input.txt","r",stdin);
    //freopen("D:\\code\\text\\output.txt","w",stdout);


    cin >> n >> mod >> SA >> SB >> SC;
    for (int i = 1; i <= n; ++i) { a[i] = Rand() % mod + 1; }

    ll ans=(n*(n-1))/2;
    ll x=a[n];
    for(int i=n-1;i>=1;--i)
    {
        x--;
        if(x>a[i])
        {
            x=a[i];// 取较小的作为限制条件
        }
        if(!x)
        {
            ans+=(i-1);// 这个位置前面的每一个线段都会多跳一次。
            x=a[i];
        }
    }
    cout<<ans<<endl;

    return 0;
}

inline void getInt(int *p)
{
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    } else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Guess you like

Origin www.cnblogs.com/qieqiemin/p/11348352.html