zoukankan      html  css  js  c++  java
  • [六省联考2017]期末考试

    嘟嘟嘟


    我看我是老了啊,这zz题都在想暴力(还只搞了20分)……
    什么三分, 什么单调性,直接暴力枚举就行了。


    我们暴力枚举最后的成绩公布时间,然后算上二分查找(O(logn))时间单次计算就行。
    刚开始我一直没想出来,怎么求(n)个数和(x)的差的和,一直在搞什么数据结构,其实直接整体考虑,用(n * x)减去(sum[n])就完事了……
    然后计算的时候根据(A, B)的大小关系分两种情况。

    #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, x) memset(a, x, sizeof(a))
    #define In inline
    typedef long long ll;
    typedef unsigned long long ull;
    typedef double db;
    const ull INF = 1e18;
    const db eps = 1e-8;
    const int maxn = 1e5 + 5;
    inline ll read()
    {
      ll ans = 0;
      char ch = getchar(), last = ' ';
      while(!isdigit(ch)) last = ch, ch = getchar();
      while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
      if(last == '-') ans = -ans;
      return ans;
    }
    inline void write(ll x)
    {
      if(x < 0) x = -x, putchar('-');
      if(x >= 10) write(x / 10);
      putchar(x % 10 + '0');
    }
    
    ull A, B, C, sumb[maxn], sumt[maxn], ans = INF;
    int n, m, t[maxn], b[maxn];
    
    int main()
    {
      A = read(), B = read(), C = read();
      n = read(), m = read();
      for(int i = 1; i <= n; ++i) t[i] = read();
      for(int i = 1; i <= m; ++i) b[i] = read();
      sort(t + 1, t + n + 1), sort(b + 1, b + m + 1);
      for(int i = 1; i <= n; ++i) sumt[i] = sumt[i - 1] + t[i];
      for(int i = 1; i <= m; ++i) sumb[i] = sumb[i - 1] + b[i];
      for(int i = 0; i <= b[m]; ++i)
        {
          int pos; ull sum, tp;
          if(B <= A)
    	{
    	  pos = lower_bound(b + 1, b + m + 1, i) - b;
    	  sum = B * (sumb[m] - sumb[pos - 1] - (ull)i * (m - pos + 1));
    	}
          else
    	{
    	  pos = lower_bound(b + 1, b + m + 1, i) - b;
    	  ull tot1 = (ull)i * (pos - 1) - sumb[pos - 1];
    	  ull tot2 = sumb[m] - sumb[pos - 1] - (ull)i * (m - pos + 1);
    	  if(tot1 >= tot2) sum = A * tot2;
    	  else sum = A * tot1 + B * (tot2 - tot1);
    	}
          pos = lower_bound(t + 1, t + n + 1, i) - t;
          tp = pos ? C * ((ull)i * (pos - 1) - sumt[pos - 1]) : 0;
          ans = min(ans, sum + tp);
        }
      write(ans), enter;
      return 0;
    }
    
  • 相关阅读:
    阅读文献的三大问题:坐不住,记不住,想不开
    C++之vector模板类
    C++之string类
    算法学习(1)枚举法求运算符
    二叉树(4)非递归法遍历二叉树
    二叉树(3):对二叉树数的操作
    Pascal's Triangle,Pascal's Triangle II
    Next Permutation
    Permutations,Permutations II,Combinations
    Majority Element,Majority Element II
  • 原文地址:https://www.cnblogs.com/mrclr/p/10558450.html
Copyright © 2011-2022 走看看