zoukankan      html  css  js  c++  java
  • 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
    ",sum);
    }
    

      

    ——by zhber,转载请注明来源
  • 相关阅读:
    LRUK算法例子
    php socket编程入门例子
    之前做的一个leetcode的题目记录下(留个纪念)
    php防范时序攻击的办法
    python使用es的例子(记录下)
    mysql随机抽取一定数量的记录
    go module包管理学习笔记
    nginx location匹配规则
    解决go get卡住的问题(转)
    supervisor 学习笔记(转)
  • 原文地址:https://www.cnblogs.com/zhber/p/4035899.html
Copyright © 2011-2022 走看看