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

精度问题我也是醉了。。

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cmath>
  4. #include <string>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <queue>
  8. using namespace std;
  9. #define rep(i, n) for(int i=0; i<(n); ++i)
  10. #define for1(i,a,n) for(int i=(a);i<=(n);++i)
  11. #define for2(i,a,n) for(int i=(a);i<(n);++i)
  12. #define for3(i,a,n) for(int i=(a);i>=(n);--i)
  13. #define for4(i,a,n) for(int i=(a);i>(n);--i)
  14. #define CC(i,a) memset(i,a,sizeof(i))
  15. #define read(a) a=getint()
  16. #define print(a) printf("%lld", a)
  17. #define dbg(x) cout << (#x) << " = " << (x) << endl
  18. #define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
  19. #define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl
  20. 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; }
  21. inline const int max(const int &a, const int &b) { return a>b?a:b; }
  22. inline const int min(const int &a, const int &b) { return a<b?a:b; }
  23.  
  24. const int N=1500005;
  25. typedef long long ll;
  26. struct dat { ll w, u; }cow[N];
  27. inline const bool cmp(const dat &a, const dat &b) { return a.u==b.u ? a.w<b.w : a.u>b.u; }
  28. int n;
  29. ll m, a, b, c, d, e, f, g, h;
  30.  
  31. int main() {
  32. cin >> n >> a >> b >> c >> d >> e >> f >> g >> h >> m; ll nn=n*3;
  33. for(ll i=0; i<nn; ++i) {
  34. ll i2=(i*i)%d, i3=(i2*i)%d, i5=(i3*i2)%d;
  35. cow[i].w=((a*i5)%d+(b*i2)%d+c)%d;
  36. i2=(i*i)%h; i3=(i2*i)%h, i5=(i3*i2)%h;
  37. cow[i].u=((e*i5)%h+(f*i3)%h+g)%h;
  38. }
  39. sort(cow, cow+nn, cmp);
  40. long long ans=0;
  41. rep(i, n) {
  42. ans+=cow[i].w; if(ans>=m) ans%=m;
  43. }
  44. print(ans);
  45. return 0;
  46. }

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. iOS 调用音乐播放以及视频播放器

    音乐播放 NSString *path = [[NSBundle mainBundle] pathForResource:@"预谋" ofType:@"mp3" ...

  2. Android NDK学习记录(一)

    一.NDK环境在Mac中部署 1.准备eclipse,android sdk安装包,android ndk安装包(http://dl.google.com/android/ndk/android-nd ...

  3. javascript的基本类型剖析:

    javascript的基本数据类型包含 string,number,boolean,function,object,undified基本的6的基本数据类型 这篇文章就主要介绍一下这六种基本数据类型的主 ...

  4. C# 利用反射拷贝类

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. 安装Drupal7.12升级至7.22

    怀揣着为中小企业量身定做一整套开源软件解决方案的梦想开始了一个网站的搭建.http://osssme.org/ [2013-08-11] 资料更新,Drupal 7.22升级至7.23 访问自己的Dr ...

  6. Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet] 异常

    1. 异常描述 FATAL EXCEPTION: main Process: com.whereru.greengrass.goforit, PID: 13847 java.lang.RuntimeE ...

  7. A Translation for Quaternion 一篇对四元数的翻译

    一篇写的非常好的博客:http://www.cnblogs.com/lookof/archive/2012/02/24/2360749.html

  8. Exif.js获取图片的详细信息(苹果手机移动端上传图片旋转90度)

    Exif.js插件介绍 http://code.ciaoca.com/javascript/exif-js/ iOS手机竖着拍的照片经过前端处理之后被旋转了90°的原因以及解决方案 https://w ...

  9. Vivado Logic Analyzer的使用

    chipscope中,通常有两种方法设置需要捕获的信号.1.添加cdc文件,然后在网表中寻找并添加信号2.添加ICON.ILA和VIO的IP Core 第一种方法,代码的修改量小,适当的保留设计的层级 ...

  10. [svc]jdk1.7.0_13(系列)下载url

    蛋疼了,这个版本,找了老半天没找到 最后是同事找到的 http://download.oracle.com/otn/java/jdk/7u13-b20/jdk-7u13-linux-x64.tar.g ...