zoukankan      html  css  js  c++  java
  • [USACO09MAR]Sand Castle

    嘟嘟嘟

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

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

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

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<cstring>
     6 #include<cstdlib>
     7 #include<cctype>
     8 #include<vector>
     9 #include<stack>
    10 #include<queue>
    11 using namespace std;
    12 #define enter puts("") 
    13 #define space putchar(' ')
    14 #define Mem(a) memset(a, 0, sizeof(a))
    15 typedef long long ll;
    16 typedef double db;
    17 const int INF = 0x3f3f3f3f;
    18 const db eps = 1e-8;
    19 const int maxn = 2.5e4 + 5;;
    20 inline ll read()
    21 {
    22     ll ans = 0;
    23     char ch = getchar(), last = ' ';
    24     while(!isdigit(ch)) {last = ch; ch = getchar();}
    25     while(isdigit(ch)) {ans = ans * 10 + ch - '0'; ch = getchar();}
    26     if(last == '-') ans = -ans;
    27     return ans;
    28 }
    29 inline void write(ll x)
    30 {
    31     if(x < 0) x = -x, putchar('-');
    32     if(x >= 10) write(x / 10);
    33     putchar(x % 10 + '0');
    34 }
    35 
    36 int n, x, y;
    37 int m[maxn], b[maxn];
    38 ll ans = 0;
    39 
    40 int main()
    41 {
    42     n = read(); x = read(); y = read();
    43     for(int i = 1; i <= n; ++i) m[i] = read(), b[i] = read();
    44     sort(m + 1, m + n + 1); sort(b + 1, b + n + 1);
    45     for(int i = 1; i <= n; ++i) ans += (m[i] - b[i]) * (m[i] > b[i] ? y : -x);
    46     write(ans); enter;
    47     return 0;
    48 }
    View Code
  • 相关阅读:
    进制转换
    体验mssql-cli
    从Windows迁移SQL Server到Linux
    CentOS7脱机安装SQL Server 2017
    基础知识:数据类型优先级
    SQL Server 2016正式版安装(超多图)
    制造高CPU使用率的简单方法
    SQL Server启动的几种方法
    SQL Server 2016 RC0 安装(超多图)
    机器学习:Python实现单层Rosenblatt感知器
  • 原文地址:https://www.cnblogs.com/mrclr/p/9569330.html
Copyright © 2011-2022 走看看