【BZOJ】2018: [Usaco2009 Nov]农场技艺大赛(暴力)
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
Sample Output
HINT
样例说明:公式生成的体重和有用度分别为: 体重:5, 6, 9, 14, 21, 30 有用度:0, 1, 8, 27, 64, 125.
Source
【BZOJ】2018: [Usaco2009 Nov]农场技艺大赛(暴力)的更多相关文章
- bzoj:2018 [Usaco2009 Nov]农场技艺大赛
Description Input 第1行:10个空格分开的整数: N, a, b, c, d, e, f, g, h, M Output 第1行:满足总重量最轻,且用度之和最大的N头奶牛的总体重模M ...
- bzoj2018 [Usaco2009 Nov]农场技艺大赛
Description Input 第1行:10个空格分开的整数: N, a, b, c, d, e, f, g, h, M Output 第1行:满足总重量最轻,且用度之和最大的N头奶牛的总体重模M ...
- BZOJ 1770: [Usaco2009 Nov]lights 燈( 高斯消元 )
高斯消元解xor方程组...暴搜自由元+最优性剪枝 -------------------------------------------------------------------------- ...
- bzoj 2017 [Usaco2009 Nov]硬币游戏 动态规划
[Usaco2009 Nov]硬币游戏 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 431 Solved: 240[Submit][Status] ...
- BZOJ 1770: [Usaco2009 Nov]lights 燈
Description 一个图,对一个点进行操作会改变这个点及其相邻的点的状态,问全部变成黑色至少需要几次.数据保证有解. Sol Meet in middle. 我一开始写个高斯消元,发现有两个点过 ...
- 【高斯消元】BZOJ 1770: [Usaco2009 Nov]lights 燈
Description 貝希和她的閨密們在她們的牛棚中玩遊戲.但是天不從人願,突然,牛棚的電源跳閘了,所有的燈都被關閉了.貝希是一個很膽小的女生,在伸手不見拇指的無盡的黑暗中,她感到驚恐,痛苦與絕望. ...
- [bzoj 2017] [Usaco2009 Nov]硬币游戏
一个多月没更博客了..(期间明白了自己有多傻逼. 这种问题大概就倒着做... f[i][j]:表示考虑剩下的硬币i..n,且之前的人取了j个时,先手最多拿到的钱数.aft[i]:表示硬币i..n的总钱 ...
- BZOJ 1770: [Usaco2009 Nov]lights 燈 [高斯消元XOR 搜索]
题意: 经典灯问题,求最少次数 本题数据不水,必须要暴搜自由元的取值啦 想了好久 然而我看到网上的程序都没有用记录now的做法,那样做遇到自由元应该可能会丢解吧...? 我的做法是把自由元保存下来,枚 ...
- BZOJ 2019 [Usaco2009 Nov]找工作:spfa【最长路】【判正环】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2019 题意: 奶牛们没钱了,正在找工作.农夫约翰知道后,希望奶牛们四处转转,碰碰运气. 而 ...
随机推荐
- iOS 调用音乐播放以及视频播放器
音乐播放 NSString *path = [[NSBundle mainBundle] pathForResource:@"预谋" ofType:@"mp3" ...
- Android NDK学习记录(一)
一.NDK环境在Mac中部署 1.准备eclipse,android sdk安装包,android ndk安装包(http://dl.google.com/android/ndk/android-nd ...
- javascript的基本类型剖析:
javascript的基本数据类型包含 string,number,boolean,function,object,undified基本的6的基本数据类型 这篇文章就主要介绍一下这六种基本数据类型的主 ...
- C# 利用反射拷贝类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 安装Drupal7.12升级至7.22
怀揣着为中小企业量身定做一整套开源软件解决方案的梦想开始了一个网站的搭建.http://osssme.org/ [2013-08-11] 资料更新,Drupal 7.22升级至7.23 访问自己的Dr ...
- 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 ...
- A Translation for Quaternion 一篇对四元数的翻译
一篇写的非常好的博客:http://www.cnblogs.com/lookof/archive/2012/02/24/2360749.html
- Exif.js获取图片的详细信息(苹果手机移动端上传图片旋转90度)
Exif.js插件介绍 http://code.ciaoca.com/javascript/exif-js/ iOS手机竖着拍的照片经过前端处理之后被旋转了90°的原因以及解决方案 https://w ...
- Vivado Logic Analyzer的使用
chipscope中,通常有两种方法设置需要捕获的信号.1.添加cdc文件,然后在网表中寻找并添加信号2.添加ICON.ILA和VIO的IP Core 第一种方法,代码的修改量小,适当的保留设计的层级 ...
- [svc]jdk1.7.0_13(系列)下载url
蛋疼了,这个版本,找了老半天没找到 最后是同事找到的 http://download.oracle.com/otn/java/jdk/7u13-b20/jdk-7u13-linux-x64.tar.g ...