| 比赛 | 
    20110916 | 
    评测结果 | 
    AWWWWWWEEE | 
    | 题目名称 | 
    盛大的 Farm-off | 
    最终得分 | 
    10 | 
    | 用户昵称 | 
    kaaala | 
    运行时间 | 
    1.699 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    4.13 MiB  | 
    | 提交时间 | 
    2011-09-16 20:08:02 | 
显示代码纯文本
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
using namespace std;
struct type
{
	long w,u;
}sum[500001];
int n,a,b,c,d,e,f,g,h,m;
long ans;
int cmp(const void *a,const void *b)
{
	if(((type *)a)->u>((type *)b)->u)
		return -1;
	else
		return 1;
	if(((type *)a)->w>((type *)b)->w)
		return 1;
	else
		return -1;
	return 1;
}
int main()
{
	int i;
	ifstream fin("farmoff.in");
	ofstream fout("farmoff.out");
	fin>>n>>a>>b>>c>>d>>e>>f>>g>>h>>m;
	for(i=1;i<=3*n;i++)
	{
		sum[i].w=(a*(int)pow((double)i-1,5.0)+b*(int)pow((double)i-1,2.0)+c)%d;
		sum[i].u=(e*(int)pow((double)i-1,5.0)+f*(int)pow((double)i-1,3.0)+g)%h;
	}
	qsort(sum+1,n*3,sizeof(sum[0]),cmp);
	for(i=1;i<=n;i++)
		ans+=sum[i].w%m;
	fout<<ans<<endl;
	fin.close();
	fout.close();
	return 0;
}