bzoj2018 [Usaco2009 Nov]农场技艺大赛

57 篇文章 0 订阅

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<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int int>
using namespace std;
inline LL read()
{
    LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
LL n,a,b,c,d,e,f,g,h,m;
struct cow{
	LL w,u;
}aaa[1500010];
inline bool cmp(const cow &a,const cow &b)
{
	return a.u>b.u||a.u==b.u&&a.w<b.w;
}
inline void work()
{
	for(int i=0;i<3*n;i++)
	{
		LL t1=i%d;
		LL t2=(t1*t1)%d;
		LL t5=(((t2*t2)%d)*t1)%d;
		aaa[i].w=(a*t5+b*t2+c)%d;
		LL s1=i%h;
		LL s3=(((s1*s1)%h)*s1)%h;
		LL s5=(((s3*s1)%h)*s1)%h;
		aaa[i].u=(e*s5+f*s3+g)%h;
	}
}
int main()
{
	n=read();
	a=read();
	b=read();
	c=read();
	d=read();
	e=read();
	f=read();
	g=read();
	h=read();
	m=read();
	work();
	sort(aaa,aaa+3*n,cmp);
	LL sum=0;
	for (int i=0;i<n;i++) sum=(sum+aaa[i].w)%m;
	printf("%lld\n",sum);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值