嘟嘟嘟

太水了,大佬们就绕道吧……

就是m, b数组分别排个序,然后更改对应位置的m[i]和b[i],就行了。

因为如果m[i]不改为b[i]而是b[i + 1]的话,那么必定要将m[j] (j > i)改为b[i],而这一定比m[i]改为b[i]更劣。

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a) memset(a, 0, sizeof(a))
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-;
const int maxn = 2.5e4 + ;;
inline ll read()
{
ll ans = ;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) {last = ch; ch = getchar();}
while(isdigit(ch)) {ans = ans * + ch - ''; ch = getchar();}
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) x = -x, putchar('-');
if(x >= ) write(x / );
putchar(x % + '');
} int n, x, y;
int m[maxn], b[maxn];
ll ans = ; int main()
{
n = read(); x = read(); y = read();
for(int i = ; i <= n; ++i) m[i] = read(), b[i] = read();
sort(m + , m + n + ); sort(b + , b + n + );
for(int i = ; i <= n; ++i) ans += (m[i] - b[i]) * (m[i] > b[i] ? y : -x);
write(ans); enter;
return ;
}

[USACO09MAR]Sand Castle的更多相关文章

  1. bzoj 3399: [Usaco2009 Mar]Sand Castle城堡

    3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec  Memory Limit: 128 MB Description 约翰用沙子建了一座城堡.正 ...

  2. BZOJ3399: [Usaco2009 Mar]Sand Castle城堡

    3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 22  Solved: 17[Sub ...

  3. 3399: [Usaco2009 Mar]Sand Castle城堡

    3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 37  Solved: 32[Sub ...

  4. LG2945 【[USACO09MAR]沙堡Sand Castle】

    经典的贪心模型,常规思路:将M和B排序即可 看到没有人用优先队列,于是我的showtime到了 说下思路: 读入时将数加入啊a,b堆中,不用处理(二叉堆本来就有有序的性质) 读完后逐个判断,照题目模拟 ...

  5. 洛谷 P2945 [USACO09MAR]沙堡Sand Castle 题解

    题目传送门 大概思路就是把这两个数组排序.在扫描一次,判断大小,累加ans. #include<bits/stdc++.h> using namespace std; int x,y,z; ...

  6. 洛谷 P2945 [USACO09MAR]沙堡Sand Castle

    传送门 题目大意: ai,ai+1,ai+2... 变成 bi,bi+1,bi+2.. 不计顺序,增加和减少a数组均有代价. 题解:贪心+排序 小的对应小的 代码: #include<iostr ...

  7. 随手练—— 洛谷-P2945 Sand Castle(贪心)

    题目链接:https://www.luogu.org/problemnew/show/P2945 (原题 USACO) 要求钱最少,就是试着让M和B的离散程度最小(我自己脑补的,就是总体更接近,我不知 ...

  8. BZOJ 3399 [Usaco2009 Mar]Sand Castle城堡:贪心【最小匹配代价】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3399 题意: 给你一个数列a,和一个可变换顺序的序列b(数列长度≤25000). a增加一 ...

  9. BZOJ 3399 [Usaco2009 Mar]Sand Castle城堡(贪心)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3399 [题目大意] 将一个集合调整成另一个集合中的数,把一个数+1需要消耗x,-1需要 ...

随机推荐

  1. Java中URL重写(urlrewrite+Maven)

    一.UrlRewrite的作用   UrlRewrite即地址重写,用户得到的全部都是经过处理后的URL地址.将我们的动态网页地址转化为静态的地址,如html.shtml,还可以隐藏网页的真正路径.此 ...

  2. 1..net mvc的原理概述

    请求过来,根据ip和端口,由iis服务器进行接收,如果是静态文件则直接返回文件内容,如果无法解析,则根据映射规则找到对应请求后缀 的ASPNET_ISAPI.dll处理程序集,交由其进行处理. 1.此 ...

  3. csharp:A Custom CheckedListBox with Datasource

    /// <summary> /// (eraghi) /// Custom CheckedListBox with binding facilities (Value property) ...

  4. 虚树(Bzoj3611: [Heoi2014]大工程)

    题面 传送门 虚树 把跟询问有关的点拿出来建树,为了方便树\(DP\) 在\(LCA\)处要合并答案,那么把这些点的\(LCA\)也拿出来 做法:把点按\(dfs\)序排列,然后求出相邻两个点的\(L ...

  5. Mongodb安装详解及mongochef视图工具安装。

    按照国际惯例我们先来介绍一下MongoDB. MongoDB是一个基于分布式文件存储的数据库,由c++语言编写,为WEB应用提供可扩展的高性能数据存储解决方案.MongoDB属于非关系数据库,也不能说 ...

  6. Web开发须知的浏览器内幕 缓存与存储篇(2)

    本文禁止转载,由UC浏览器内部出品. 3. HTTP Cache 综述 HTTP Cache是完全按照IETF规范实现的,最新的RFC规范地址是 https://tools.ietf.org/html ...

  7. VS2010项目转换成VS2008

    声明:本篇文章不是本人原创,但是网站的地址没有记下来,所以不能贴出来.但此方法本人亲自验证有效. 一.将.sln文件中的 Microsoft Visual Studio Solution File, ...

  8. jpa dialect设置

    1.如果配置文件格式为application.properties,在配置文件中添加以下代码即可: spring.jpa.database-platform=org.hibernate.dialect ...

  9. Socket(套接字) IP TCP UDP HTTP

    Socket(套接字) 阮老师的微博 (转)什么是套接字(Socket)? 应用层通过传输层进行数据通信时,TCP和UDP会遇到同时为多个应用程序进程提供并发服务的问题.多个TCP连接或多个应用程序进 ...

  10. 八、angularjs 中 filter在controller中的使用--避免多次遍历

    filter在html页面的使用司空见惯,比如: filter在controller中使用可以避免多次使用angular.foreach,来进行遍历.例如: 如果使用filter,则会让代码简洁而且明 ...