【BZOJ】3399: [Usaco2009 Mar]Sand Castle城堡(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=3399
贪心就是将两组排序,然后直接模拟即可。。
如果我们用a去匹配一个绝对值和它差不多的值,那么去匹配的那个位置显然要和它这个位置匹配,同样的高度差。。。
自己理解吧。。
#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("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; 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=25500;
int a[N], b[N], n, x, y, ans; int main() {
read(n); read(x); read(y);
for1(i, 1, n) read(a[i]), read(b[i]);
sort(a+1, a+1+n); sort(b+1, b+1+n);
for1(i, 1, n) if(a[i]>b[i]) ans+=(a[i]-b[i])*y; else ans+=(b[i]-a[i])*x;
print(ans);
return 0;
}
Description
Input
Output
Sample Input
3 1
1 2
1 2
Sample Output
HINT
第1个城齿降低1,第2个城齿提高1
Source
【BZOJ】3399: [Usaco2009 Mar]Sand Castle城堡(贪心)的更多相关文章
- bzoj 3399: [Usaco2009 Mar]Sand Castle城堡
3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec Memory Limit: 128 MB Description 约翰用沙子建了一座城堡.正 ...
- BZOJ 3399 [Usaco2009 Mar]Sand Castle城堡:贪心【最小匹配代价】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3399 题意: 给你一个数列a,和一个可变换顺序的序列b(数列长度≤25000). a增加一 ...
- BZOJ 3399 [Usaco2009 Mar]Sand Castle城堡(贪心)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3399 [题目大意] 将一个集合调整成另一个集合中的数,把一个数+1需要消耗x,-1需要 ...
- 3399: [Usaco2009 Mar]Sand Castle城堡
3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 37 Solved: 32[Sub ...
- BZOJ3399: [Usaco2009 Mar]Sand Castle城堡
3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 22 Solved: 17[Sub ...
- DP经典 BZOJ 1584: [Usaco2009 Mar]Cleaning Up 打扫卫生
BZOJ 1584: [Usaco2009 Mar]Cleaning Up 打扫卫生 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 419 Solve ...
- BZOJ 3401: [Usaco2009 Mar]Look Up 仰望( 单调栈 )
n <= 105 , 其实是10 ^ 5 ....坑...我一开始写了个模拟结果就 RE 了.. 发现这个后写了个单调栈就 A 了... ---------------------------- ...
- BZOJ 3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 动态规划
3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=34 ...
- bzoj 1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害
1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害 Description Farmer John的农场里有P个牧场,有C条无向道路连接着他们,第i条道路连接着 ...
随机推荐
- 什么是Cookie。Cookie的原理介绍,Cookie的简单应用
1 介绍:Cookies亦称Cookie .Cookies是一种能够让网站服务器把少量数据储存到客户端的硬盘或内存,或是从客户端的硬盘读取数据的一种技术.Cookies是当你浏览某网站时,由Web服务 ...
- Ubuntu安装Mac皮肤
如果是ubuntu的PC版,在稳定性方面的要求不是非常高,而又想换换界面养养眼,像我一般只用我的Ubuntu12.04来写写代码,娱乐娱乐的,可以试试Ubuntu的Mac皮肤. 好了,废话不多说,上图 ...
- webDriver API——第5部分Special Keys
The Keys implementation. class selenium.webdriver.common.keys.Keys Bases: object Set of special keys ...
- 一直加载“fonts.googleapis.com”的解决办法
原文:http://www.tuicool.com/articles/6bayeq 最近国内对google又开始了新一轮的屏蔽,很多wordpress用户发现一个现象,那就是网站前台和后台打开都非常慢 ...
- C#开发Unity游戏教程循环遍历做出推断及Unity游戏演示样例
C#开发Unity游戏教程循环遍历做出推断及Unity游戏演示样例 Unity中循环遍历每一个数据,并做出推断 非常多时候.游戏在玩家做出推断以后.游戏程序会遍历玩家身上大量的所需数据,然后做出推断. ...
- LNMP环境搭建——MySQL篇
The world's most popular open source database 1.Install MySQL root@kallen:~# apt-get install mysql-s ...
- C语言-常用知识和技巧
1. char string[MAXSIZE], *tmp = string; 2."&&", "||", "?:", &q ...
- elasticsearch mapping问题解决
1.报错信息如下: [--16T00::,][WARN ][logstash.outputs.elasticsearch] Could not index event to Elasticsearch ...
- centos7下安装openvpn,访问内网服务器 (三)证书取消授权
1.创建临时证书 使用easy-rsa创建额外的证书: [root@origalom openvpn]# cd /usr/share/easy-rsa/2.0/ [root@origalom 2.0] ...
- php 验证访问浏览器是电脑还是手机
//判断如果为手机用户则 if(checkmobile()==true) { $url=$_SERVER["HTTP_HOST"]; $urlHost=GetHost($url); ...