test5 3-20 2021 provincial election simulation contest five

Exam review

first question? ? What kind of interaction is it? ( ̄ ̄)σ…(__)ノ|Wall

The second question was taken a few days ago, so I know it is polya polyap o l y a , but the binomial theorem that is pushed to the end is not correct, so I can only useFFT FFTF F T , the problem is violentFFT FFTF F T has been adjusted for a long time! ! It seems that this week we still have to focus on convolution [the external link image transfer failed, the source site may have an anti-leech mechanism, it is recommended to save the image and upload it directly (img-pJWa65au-1616329681876)(file:///C:\ PROGRA2\Baidu\BAIDUP1\5039001.0\dict\Default\0423961.PNG)]

The expectation of the third question, (・.・) I suddenly remembered that I have to hurry up and adjust my expectation

It's already easy. After all, someone who doesn't know much about the meaning of expectations has found a formula

But stuck in the time complexity of the violent search behind, and this seems to have a bit of accuracy? ?

LYK loves

Insert picture description here

Insert picture description hereInsert picture description here
To be added—————————————————————————————————————————————— ———————————————————————————————————————————————— ———————————————————————————————————————————————— ———————

LYK loves girls

Insert picture description here
Insert picture description here

p o l y a polya The theorem of p o l y a , Mr. He explained briefly, the number of coloring types, the number oftracks/the length of the sequence

#include <cstdio>
#include <iostream>
using namespace std;
#define int long long
#define mod 1000000007
#define maxn 100005
int n, k;
int g[maxn], f[maxn], sum[maxn];

int qkpow( int x, int y ) {
    
    
	int ans = 1;
	while( y ) {
    
    
		if( y & 1 ) ans = ans * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return ans;
}

int gcd( int x, int y ) {
    
    
	if( ! y ) return x;
	else return gcd( y, x % y );
}

signed main() {
    
    
	scanf( "%lld %lld", &n, &k );
	g[0] = g[1] = sum[0] = 1, sum[1] = 2;
	for( int i = 2;i <= n;i ++ ) {
    
    
		g[i] = ( sum[i - 1] - ( ( i - k - 2 < 0 ) ? 0 : sum[i - k - 2] ) + mod ) % mod;
		sum[i] = ( sum[i - 1] + g[i] ) % mod;
	}
	int ans = 0;
	for( int i = 1;i <= n;i ++ ) {
    
    
		int d = gcd( n, i );
		if( ! f[d] ) {
    
    
			for( int j = 1;j <= min( k + 1, d );j ++ ) 
				f[d] = ( f[d] + j * g[d - j] % mod ) % mod;//1(m-j) 0 0 0 0 0 0 1(i) 
			//乘以j就是因为最后面的0和1可以彼此旋转也是新的方案
			if( k >= n ) f[d] = ( f[d] + 1 ) % mod;
		}
		ans = ( ans + f[d] ) % mod;
	}
	ans = ans * qkpow( n, mod - 2 ) % mod;
	if( k == n ) ans = ( ans - 1 + mod ) % mod;
	printf( "%lld\n", ans );
	return 0;
}

LYK loves jumping

Insert picture description here
t i ≠ 0 t_i≠ 0 ti=0 , set to skipxxx positions, thesum of theexpected steps issum sumsum,则 d p [ i ] = 1 + s u m x dp[i]=1+\frac{sum}{x} dp[i]=1+xsum
t i = 0 t_i=0 ti=0 , set to jump toxxx ahhh is not equal tohi h_ihiThe position of the expected number of steps is sum sums u myyy ahhh equalshi h_ihi的位置,则 d p [ i ] = x + y x + s u m x dp[i]=\frac{x+y}{x}+\frac{sum}{x} dp[i]=xx + and+xsum

#include <cstdio>
#include <algorithm>
using namespace std;
#define maxn 100005
struct node {
    
    
	int id, h, t;
}dot[maxn];
int n;
bool vis[maxn];
double step[maxn], sum[maxn], ans[maxn];

bool cmp( node x, node y ) {
    
    
	return ( x.h == y.h ) ? x.t > y.t : x.h < y.h;
}

int main() {
    
    
	scanf( "%d", &n );
	for( int i = 1;i <= n;i ++ ) scanf( "%d", &dot[i].h ), dot[i].id = i;
	for( int i = 1;i <= n;i ++ ) scanf( "%d", &dot[i].t );
	sort( dot + 1, dot + n + 1, cmp );
	for( int i = 1;i <= n;i ++ ) {
    
    
		int l = 1, r = i;
		while( l <= r ) {
    
    
			int mid = ( l + r ) >> 1;
			if( dot[mid].h <= dot[i].h - dot[i].t ) l = mid + 1;
			else r = mid - 1;
		}
		if( i == r ) {
    
    //说明前i个格子都能跳 包括自己 那么意味着ti=0
			int j;
			for( j = i + 1;j <= n;j ++ )//i是特殊类型段的开头第一个 往后找于之等高切tj=0的格子
				if( dot[j].h == dot[i].h && dot[j].t == dot[i].t );
				else break;
			j --;
			for( int k = i;k <= j;k ++ ) {
    
    
				if( vis[k - 1] || i == 1 ) vis[k] = 1, step[k] = 0;
				else step[k] = ( sum[i - 1] + j ) / ( i - 1 );
				vis[k] |= vis[k - 1];
				sum[k] = sum[k - 1] + step[k];
			}
			i = j;
			continue;
		}
		if( vis[r] ) step[i] = 0;
		else if( ! r ) step[i] = 1;
		else step[i] = sum[r] / r + 1;
		vis[i] |= vis[i - 1];
		sum[i] = sum[i - 1] + step[i];
	}
	for( int i = 1;i <= n;i ++ ) ans[dot[i].id] = step[i];
	for( int i = 1;i <= n;i ++ ) printf( "%.4f ", ans[i] );
	return 0;
}

Guess you like

Origin blog.csdn.net/Emm_Titan/article/details/115029999