现在的位置: 首页 > 综合 > 正文

bzoj2018 [Usaco2009 Nov]农场技艺大赛

2018年01月12日 ⁄ 综合 ⁄ 共 1138字 ⁄ 字号 评论关闭

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);
}

抱歉!评论已关闭.