【每日一题】南园满地堆轻絮
[HEOI2014]南园满地堆轻絮
https://ac.nowcoder.com/acm/problem/20012
题意:
思路:
#include <cstdio> #include <algorithm> using namespace std; const int N = 5e6 + 10; int n; int S_a,S_b,S_c,S_d,mod,mx; int a[N]; bool check(int k){ int b = a[1] - k;//越小越好 for(int i = 2;i <= n;i++){ if(a[i] >= b){ b = max(a[i] - k,b); }else if(a[i] + k < b) return 0; } return 1; } int f(int x){ int x_a = 1ll * S_a * x % mod * x % mod* x % mod; int x_b = 1ll * S_b * x % mod * x % mod; int x_c = 1ll * S_c * x % mod; int x_d = S_d % mod; return (((x_a + x_b)%mod + x_c) % mod + x_d) % mod; } int main(){ scanf("%d %d %d %d %d %d %d",&n,&S_a,&S_b,&S_c,&S_d,&a[1],&mod); mx = a[1]; for(int i = 2;i <= n;i++){ a[i] = (f(a[i - 1]) + f(a[i - 2])) % mod; mx = max(mx,a[i]); } int l = 0,r = mx,ans = -1; while(l <= r){ int mid = l + r >> 1; if(check(mid)){ r = mid - 1; ans = mid; }else l = mid + 1; } printf("%d\n",ans); return 0; }
每日一题 文章被收录于专栏
每题一题题目