bzoj:2018 [Usaco2009 Nov]农场技艺大赛

Description

Input

第1行:10个空格分开的整数: N, a, b, c, d, e, f, g, h, M

Output

第1行:满足总重量最轻,且用度之和最大的N头奶牛的总体重模M后的余数。

Sample Input

2 0 1 5 55555555 0 1 0 55555555 55555555

Sample Output

51

HINT

样例说明:公式生成的体重和有用度分别为: 体重:5, 6, 9, 14, 21, 30 有用度:0, 1, 8, 27, 64, 125.

暴力可过系列

#include<cstdio>
#include<algorithm>
using namespace std;
 
struct na{
    long long w,u;
};
long long N,a,b,c,d,e,f,g,h,M;
na aa[2000001];
bool cmp(na a,na b){
    return a.u>b.u||a.u==b.u&&a.w<b.w;
}
int main(){
    scanf("%lld%lld%lld%lld%lld%lld%lld%lld%lld%lld",&N,&a,&b,&c,&d,&e,&f,&g,&h,&M);
    for (long long i=0;i<3*N;i++){
        long long x=(i*i)%d;
        aa[i].w=((a*i%d)*(x*x%d)%d+(b*x)%d+c)%d;
        x=(i*i)%h;
        aa[i].u=((e*i%h)*(x*x%h)%h+((f*x)%h*i)%h+g)%h;
    }
    sort(aa,aa+3*N,cmp);
    long long ans=0;
    for (long long i=0;i<N;i++){
        ans=(ans+aa[i].w)%M;
    }
    printf("%lld
",ans%M);
}
原文地址:https://www.cnblogs.com/Enceladus/p/5017676.html