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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章