洛谷 P2965 [USACO09NOV]农活比赛The Grand Farm-off

P2965 [USACO09NOV]农活比赛The Grand Farm-off

题目描述

Farmer John owns 3*N (1 <= N <= 500,000) cows surprisingly numbered 0..3*N-1, each of which has some associated integer weight W_i (1 <= W_i <= d). He is entering the Grand Farm-off, a farming competition where he shows off his cows to the greater agricultural community.

This competition allows him to enter a group of N cows. He has given each of his cows a utility rating U_i (1 <= U_i <= h), which

represents the usefulness he thinks that a particular cow will have in the competition, and he wants his selection of cows to have the maximal sum of utility.

There might be multiple sets of N cows that attain the maximum utility sum. FJ is afraid the competition may impose a total weight limit on the cows in the competition, so a secondary priority is to bring lighter weight competition cows.

Help FJ find a set of N cows with minimum possible total weight among the sets of N cows that maximize the utility, and print the remainder when this total weight is divided by M (10,000,000 <= M <= 1,000,000,000).

Note: to make the input phase faster, FJ has derived polynomials which will generate the weights and utility values for each cow. For each cow 0 <= i < 3*N,

W_i = (a*i^5+b*i^2+c) mod d
and   U_i = (e*i^5+f*i^3+g) mod h
with reasonable ranges for the coefficients (0 <= a <= 1,000,000,000; 0 <= b <= 1,000,000,000; 0 <= c <= 1,000,000,000; 0 <= e <=
1,000,000,000; 0 <= f <= 1,000,000,000; 0 <= g <= 1,000,000,000; 10,000,000 <= d <= 1,000,000,000; 10,000,000 <= h <= 1,000,000,000).
The formulae do sometimes generate duplicate numbers; your algorithm should handle this properly. 

农夫约翰有3N(1 < N < 500000)头牛,编号依次为1..#N,每头牛都有一个整数值的体 重。约翰准备参加农场技艺大赛,向广大的农业社区展示他的奶牛. 大赛规则允许约翰带N头牛参赛.约翰给每头牛赋予了一个“有用度”Ui,它表 示了某头牛在比赛中的有用程度.约翰希望他选出的奶牛的有用度之和最大.

有可能选出很多组的N头牛都能达到有用度最大和.约翰害怕选出的N头牛的总重量会给大赛 带来震撼,所以,要考虑优先选择体重轻的奶牛.

帮助约翰选出N头总重量最轻,并且有用度之和最大的奶牛.输出体重模M后的余数.

注意:为了使输入更快,约翰使用了一个多项式来生成每头牛的体重和有用度.对每头牛/, 体重和有用度的计算公式为:

W_i = (a*i^5+b*i^2+c) mod d
and   U_i = (e*i^5+f*i^3+g) mod h
 (0 <= a <= 1,000,000,000; 0 <= b <= 1,000,000,000; 0 <= c <= 1,000,000,000; 0 <= e <=
1,000,000,000; 0 <= f <= 1,000,000,000; 0 <= g <= 1,000,000,000; 10,000,000 <= d <= 1,000,000,000; 10,000,000 <= h <= 1,000,000,000).

输入输出格式

输入格式:

* Line 1: Ten space-separated integers: N, a, b, c, d, e, f, g, h, and M

输出格式:

* Line 1: A single integer representing the lowest sum of the weights of the N cows with the highest net utility.

输入输出样例

输入样例#1: 复制

2 0 1 5 55555555 0 1 0 55555555 55555555

输出样例#1: 复制

51

说明

The functions generate weights of 5, 6, 9, 14, 21, and 30 along with utilities of 0, 1, 8, 27, 64, and 125.

The two cows with the highest utility are cow 5 and 6, and their combined weight is 21+30=51.

思路:简单的模拟+排序即可。

错音:zz的我忘了在酸w和u的时候取余,也忘了用long long,WA了好几遍Orz

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 1500001
using namespace std;
long long ans;
long long n,a,b,c,d,e,f,g,h,M;
struct nond{ long long u,w; }v[MAXN];
int cmp(nond a,nond b){
    if(a.u==b.u)    return a.w<b.w;
    return a.u>b.u;
}
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++){
        v[i].w=(a%d*i%d*i%d*i%d*i%d*i%d+(b%d*i%d*i%d+c%d)%d)%d;
        v[i].u=(e%h*i%h*i%h*i%h*i%h*i%h+(f%h*i%h*i%h*i%h+g%h)%h)%h;
    }
    sort(v,v+3*n,cmp);
    for(long long i=0;i<n;i++)    ans=(ans+v[i].w)%M;
    cout<<ans;
}

原文地址:https://www.cnblogs.com/cangT-Tlan/p/8688071.html

时间: 2024-10-13 05:17:46

洛谷 P2965 [USACO09NOV]农活比赛The Grand Farm-off的相关文章

洛谷2658 汽车拉力比赛

本题地址:http://www.luogu.org/problem/show?pid=2658 题目描述 博艾市将要举行一场汽车拉力比赛. 赛场凹凸不平,所以被描述为M*N的网格来表示海拔高度(1≤ M,N ≤500),每个单元格的海拔范围在0到10^9之间. 其中一些单元格被定义为路标.组织者希望给整个路线指定一个难度系数D,这样参赛选手从任一路标到达别的路标所经过的路径上相邻单元格的海拔高度差不会大于D.也就是说这个难度系数D指的是保证所有路标相互可达的最小值.任一单元格和其东西南北四个方向

洛谷—— P2658 汽车拉力比赛

https://www.luogu.org/problem/show?pid=2658 题目描述 博艾市将要举行一场汽车拉力比赛. 赛场凹凸不平,所以被描述为M*N的网格来表示海拔高度(1≤ M,N ≤500),每个单元格的海拔范围在0到10^9之间. 其中一些单元格被定义为路标.组织者希望给整个路线指定一个难度系数D,这样参赛选手从任一路标到达别的路标所经过的路径上相邻单元格的海拔高度差不会大于D.也就是说这个难度系数D指的是保证所有路标相互可达的最小值.任一单元格和其东西南北四个方向上的单元

洛谷 P2962 [USACO09NOV]灯Lights

P2962 [USACO09NOV]灯Lights 题目描述 Bessie and the cows were playing games in the barn, but the power was reset and the lights were all turned off. Help the cows get all the lights back on so they can resume their games. The N (1 <= N <= 35) lights conve

洛谷——P2658 汽车拉力比赛

P2658 汽车拉力比赛 题目描述 博艾市将要举行一场汽车拉力比赛. 赛场凹凸不平,所以被描述为M*N的网格来表示海拔高度(1≤ M,N ≤500),每个单元格的海拔范围在0到10^9之间. 其中一些单元格被定义为路标.组织者希望给整个路线指定一个难度系数D,这样参赛选手从任一路标到达别的路标所经过的路径上相邻单元格的海拔高度差不会大于D.也就是说这个难度系数D指的是保证所有路标相互可达的最小值.任一单元格和其东西南北四个方向上的单元格都是相邻的. 输入输出格式 输入格式: 第一行两个整数M和N

洛谷 1707 刷题比赛

/* 矩阵稍微有点难搞 不过也是可以推出来 注意防爆... */ #include<iostream> #include<cstdio> #include<cstring> #define ll long long using namespace std; ll n,mod,p,q,r,t,u,v,w,x,y,z; ll f[12][12],a[12][12]; ll slow_mul(ll a,ll b) { ll ans=0; while(b) { if(b&

洛谷P2964 [USACO09NOV]硬币的游戏A Coin Game

题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game called Xoinc for them. Initially a stack of N (5 <= N <= 2,000) coins sits on the ground; coin i from the top has integer value C_i (1 <= C_i <=

归并排序求逆序对 //(洛谷)U4566 赛车比赛

https://www.luogu.org/problem/show?pid=U4566 显然的逆序对,以前只是嘴巴ac,这次终于打了出来. 逆序对其实就是冒泡排序的排序次数....但是一般的排序时间复杂度为O(n^2),于是都会想到归并排序... 一.二路归并 已知两个有序数组,将其归并为一个有序数组 很显然,将首元素比较,小的扔进目的数组,最后把剩下的扔进去.. 1 int a[n],b[m],tmp[n+m]; 2 int i=1,j=1,k=1; 3 while(i<=n&&

洛谷P3144 [USACO16OPEN]关闭农场Closing the Farm

题目描述 Farmer John and his cows are planning to leave town for a long vacation, and so FJ wants to temporarily close down his farm to save money in the meantime. The farm consists of  barns connected with  bidirectional paths between some pairs of barn

洛谷 P2919 [USACO08NOV]守护农场Guarding the Farm

P2919 [USACO08NOV]守护农场Guarding the Farm 题目描述 The farm has many hills upon which Farmer John would like to place guards to ensure the safety of his valuable milk-cows. He wonders how many guards he will need if he wishes to put one on top of each hill