题目描述

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=;i<*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+*n,cmp);
for(long long i=;i<n;i++) ans=(ans+v[i].w)%M;
cout<<ans;
}

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

  1. 洛谷 1938 [USACO09NOV]找工就业Job Hunt

    洛谷 1938  [USACO09NOV]找工就业Job Hunt 题目描述 Bessie is running out of money and is searching for jobs. Far ...

  2. [洛谷P1707] 刷题比赛

    洛谷题目连接:刷题比赛 题目背景 nodgd是一个喜欢写程序的同学,前不久洛谷OJ横空出世,nodgd同学当然第一时间来到洛谷OJ刷题.于是发生了一系列有趣的事情,他就打算用这些事情来出题恶心大家-- ...

  3. 洛谷P2831 愤怒的小鸟 + 篮球比赛1 2

    这三道题一起做,有一点心得吧. 愤怒的小鸟,一眼看上去是爆搜,但是实现起来有困难(我打了0分出来). 还有一种解法是状压DP. 抛物线一共只有那么多条,我们枚举抛物线(枚举两个点),这样就能够预处理出 ...

  4. 洛谷 U14472 数据结构【比赛】 【差分数组 + 前缀和】

    题目描述 蒟蒻Edt把这个问题交给了你 ---- 一个精通数据结构的大犇,由于是第一题,这个题没那么难.. edt 现在对于题目进行了如下的简化: 最开始的数组每个元素都是0 给出nnn,optopt ...

  5. 洛谷——P2658 汽车拉力比赛

    P2658 汽车拉力比赛 题目描述 博艾市将要举行一场汽车拉力比赛. 赛场凹凸不平,所以被描述为M*N的网格来表示海拔高度(1≤ M,N ≤500),每个单元格的海拔范围在0到10^9之间. 其中一些 ...

  6. 洛谷—— P2658 汽车拉力比赛

    https://www.luogu.org/problem/show?pid=2658 题目描述 博艾市将要举行一场汽车拉力比赛. 赛场凹凸不平,所以被描述为M*N的网格来表示海拔高度(1≤ M,N ...

  7. 洛谷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 c ...

  8. 洛谷 P2962 [USACO09NOV]灯Lights

    题目描述 Bessie and the cows were playing games in the barn, but the power was reset and the lights were ...

  9. 洛谷 P1938 [USACO09NOV] 找工就业Job Hunt

    这道题可以说是一个复活SPFA的题 因为数据比较小,SPFA也比较简单 那就复习(复读)一次SPFA吧 #include<iostream> #include<cstdio> ...

随机推荐

  1. [App Store Connect帮助]三、管理 App 和版本(1)添加 App 至您的帐户

    在向 App Store Connect 上传您 App 的构建版本之前,您必须先在您的 App Store Connect 帐户内新建一个 App. 如果您想将 iOS App 和 Apple TV ...

  2. (转)Vue 爬坑之路(三)—— 使用 vue-router 跳转页面

    使用 Vue.js 做项目的时候,一个页面是由多个组件构成的,所以在跳转页面的时候,并不适合用传统的 href,于是 vue-router 应运而生. 官方文档: https://router.vue ...

  3. Android 获取android安装apk框的安装状态(如点击取消、返回)

    最近鼓捣android,碰到个问题,因为没有root权限,需要调用Intent安装apk,但需要获取用户是否安装了(如,用户点击了返回或取消),查了很多文章,最后可以解决,但有瑕疵,解决方法如下: p ...

  4. [转][IPC通信]基于管道的popen和pclose函数

    标准I/O函数库提供了popen函数,它启动另外一个进程去执行一个shell命令行. 这里我们称调用popen的进程为父进程,由popen启动的进程称为子进程. popen函数还创建一个管道用于父子进 ...

  5. PHP开发之旅-验证码功能实现

    验证码这样的功能可以说是无处不在了,接下来使用php来实现验证码这样的功能,这里我是将验证码实现抽取到一个类中独立开来,那么后面如果再使用到验证码功能,直接引入该类文件并创建该类的实例,就可以使用验证 ...

  6. animation仿进度条

    animation:使用的好可以有很多酷炫效果 仿进度条效果.

  7. 清瘦的记录者: 一个比dbutils更小巧、好用的的持久化工具

    https://gitee.com/bitprince/memory 1. 概述 1.1 连接.语句和结果集 从JDBC的规范上看,其对数据访问层有相当简洁的抽象:1.连接(connection) 2 ...

  8. JS——三元表达式

    三元表达式: var n1 = 2 > 3 ? true : false; alert(n1);//返回false

  9. [Windows Server 2008] Serv-U安全设置

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:Serv- ...

  10. C#使用Win32函数的一些类型转换

    C#在访问Win 32 Api时需要处理C 结构与C#结构的映射,这在MSDN以及许多Blog上都可以找到参考的资料.Win 32 中有一些定义复杂的Struct,这些结构体拥有长度固定的数组或者一些 ...