http://www.lydsy.com/JudgeOnline/problem.php?id=2018

精度问题我也是醉了。。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%lld", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=1500005;
typedef long long ll;
struct dat { ll w, u; }cow[N];
inline const bool cmp(const dat &a, const dat &b) { return a.u==b.u ? a.w<b.w : a.u>b.u; }
int n;
ll m, a, b, c, d, e, f, g, h; int main() {
cin >> n >> a >> b >> c >> d >> e >> f >> g >> h >> m; ll nn=n*3;
for(ll i=0; i<nn; ++i) {
ll i2=(i*i)%d, i3=(i2*i)%d, i5=(i3*i2)%d;
cow[i].w=((a*i5)%d+(b*i2)%d+c)%d;
i2=(i*i)%h; i3=(i2*i)%h, i5=(i3*i2)%h;
cow[i].u=((e*i5)%h+(f*i3)%h+g)%h;
}
sort(cow, cow+nn, cmp);
long long ans=0;
rep(i, n) {
ans+=cow[i].w; if(ans>=m) ans%=m;
}
print(ans);
return 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.

Source

【BZOJ】2018: [Usaco2009 Nov]农场技艺大赛(暴力)的更多相关文章

  1. bzoj:2018 [Usaco2009 Nov]农场技艺大赛

    Description Input 第1行:10个空格分开的整数: N, a, b, c, d, e, f, g, h, M Output 第1行:满足总重量最轻,且用度之和最大的N头奶牛的总体重模M ...

  2. bzoj2018 [Usaco2009 Nov]农场技艺大赛

    Description Input 第1行:10个空格分开的整数: N, a, b, c, d, e, f, g, h, M Output 第1行:满足总重量最轻,且用度之和最大的N头奶牛的总体重模M ...

  3. BZOJ 1770: [Usaco2009 Nov]lights 燈( 高斯消元 )

    高斯消元解xor方程组...暴搜自由元+最优性剪枝 -------------------------------------------------------------------------- ...

  4. bzoj 2017 [Usaco2009 Nov]硬币游戏 动态规划

    [Usaco2009 Nov]硬币游戏 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 431  Solved: 240[Submit][Status] ...

  5. BZOJ 1770: [Usaco2009 Nov]lights 燈

    Description 一个图,对一个点进行操作会改变这个点及其相邻的点的状态,问全部变成黑色至少需要几次.数据保证有解. Sol Meet in middle. 我一开始写个高斯消元,发现有两个点过 ...

  6. 【高斯消元】BZOJ 1770: [Usaco2009 Nov]lights 燈

    Description 貝希和她的閨密們在她們的牛棚中玩遊戲.但是天不從人願,突然,牛棚的電源跳閘了,所有的燈都被關閉了.貝希是一個很膽小的女生,在伸手不見拇指的無盡的黑暗中,她感到驚恐,痛苦與絕望. ...

  7. [bzoj 2017] [Usaco2009 Nov]硬币游戏

    一个多月没更博客了..(期间明白了自己有多傻逼. 这种问题大概就倒着做... f[i][j]:表示考虑剩下的硬币i..n,且之前的人取了j个时,先手最多拿到的钱数.aft[i]:表示硬币i..n的总钱 ...

  8. BZOJ 1770: [Usaco2009 Nov]lights 燈 [高斯消元XOR 搜索]

    题意: 经典灯问题,求最少次数 本题数据不水,必须要暴搜自由元的取值啦 想了好久 然而我看到网上的程序都没有用记录now的做法,那样做遇到自由元应该可能会丢解吧...? 我的做法是把自由元保存下来,枚 ...

  9. BZOJ 2019 [Usaco2009 Nov]找工作:spfa【最长路】【判正环】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2019 题意: 奶牛们没钱了,正在找工作.农夫约翰知道后,希望奶牛们四处转转,碰碰运气. 而 ...

随机推荐

  1. vue - vue-loader.conf

    'use strict' // 工具=> build/util.js const utils = require('./utils') // 配置=> build/config/index ...

  2. [Objective-C] - NSObject

    Foundation Framework Classes Data Storage:    NSData provides object-oriented storage for arrays of ...

  3. [LeetCode] Add Two Numbers(stored in List)

    首先,演示一个错误的reverList class Solution { public: ListNode* reverse(ListNode* root) { if(NULL == root) re ...

  4. Excle中range的一些用法

    以下是一些range的简单用法 Sub aa() '-=============================================== '给B列设置填充颜色为黄色 Range(" ...

  5. MiniHttpServer

    Mini HTTP Server which can be embed in EXE, Writen in C#(.net framework 2.0). HTTP request dispatch/ ...

  6. 每秒处理3百万请求的Web集群搭建-如何生成每秒百万级别的 HTTP 请求?

    本文是构建能够每秒处理 3 百万请求的高性能 Web 集群系列文章的第一篇.它记录了我使用负载生成器工具的一些经历,希望它能帮助每一个像我一样不得不使用这些工具的人节省时间. 负载生成器是一些生成用于 ...

  7. Layui 弹出层组件——layer

    layer是作为Layui[经典模块化前端框架]的一个弹层模块,由于其用户基数较大,所以把layer作为独立组件来维护. 基础参数: 基础参数主要指调用方法时用到的配置项,如:layer.open({ ...

  8. glassfish3操作命令

    glassfish3操作命令   启动:C:\Java\glassfish\bin>asadmin start-domain domain1 停止:C:\Java\glassfish\bin&g ...

  9. golang使用sqlite

    安装问题 在import sqlite的时候,golang build 出现以下错误, exec: "gcc": executable file not found in %PAT ...

  10. C# EF使用性能消耗列表 https://msdn.microsoft.com/zh-cn/library/cc853327.aspx

    性能注意事项(实体框架) .NET Framework (current version)   其他版本   本主题介绍 ADO.NET 实体框架的性能特征,并提供一些注意事项帮助改善实体框架应用程序 ...