zoukankan      html  css  js  c++  java
  • hrbust 2069 萌萌哒十五酱的衣服~ stl

    中文题意就不解释了

    思路嘛 就是暴力

    不过是用stl暴力

    描述一遍题意就行了 其他的交给multiset去操作

    其中还有一个小的知识点

    反向迭代器和普通迭代器是不能相互转化的

    要用base()方法获取相应迭代器再进行赋值操作

     1 #include<bits/stdc++.h>
     2 #define cl(a,b) memset(a,b,sizeof(a))
     3 #define debug(x) cerr<<#x<<"=="<<(x)<<endl
     4 using namespace std;
     5 
     6 const int maxn=15000+10;
     7 const int mod=1000000;
     8 
     9 multiset<int>a[2];
    10 
    11 int main()
    12 {
    13     int n;
    14     while(~scanf("%d",&n))
    15     {
    16         a[0].clear(),a[1].clear();
    17         int last=-1,ans=0;
    18         int x,y;
    19         for(int i=0; i<n; i++)
    20         {
    21             scanf("%d%d",&x,&y);
    22             if(a[0].empty()&&a[1].empty())
    23             {
    24                 last=x;
    25                 a[x].insert(y);
    26             }
    27             else if(x==last&&a[!last].empty())
    28             {
    29                 a[last].insert(y);
    30             }
    31             else
    32             {
    33                 auto set_iter=a[last].lower_bound(y);
    34                 if(*a[last].rbegin()<y)
    35                 {
    36                     //set_iter=a[last].rbegin();
    37                     //上面这句话是不对的 因为反向迭代器不能给普通迭代器赋值
    38                     //所以要用base()方法获取相应的迭代器再赋值
    39                     set_iter=a[last].rbegin().base();
    40                 }
    41                 int mi=abs(*set_iter-y);
    42                 if(set_iter!=a[last].begin())
    43                 {
    44                     set_iter--;
    45                 }
    46                 if(mi>=abs(*set_iter-y))
    47                 {
    48                     a[last].erase(set_iter);
    49                     ans+=abs(*set_iter-y);
    50                     ans%=mod;
    51                 }
    52                 else
    53                 {
    54                     set_iter++;
    55                     a[last].erase(set_iter);
    56                     ans+=mi;
    57                     ans%=mod;
    58                 }
    59             }
    60         }
    61         printf("%d
    ",ans);
    62     }
    63     return 0;
    64 }
    65 
    66 /*
    67 
    68 5
    69 0 2
    70 0 4
    71 1 3
    72 1 2
    73 1 5
    74 
    75 */
  • 相关阅读:
    react中refs的使用
    在npm发布自己造的轮子
    如何阅读一本书——分析阅读模板
    如何阅读一本书——检视阅读模板
    Redis教程——检视阅读
    如何阅读一本书——分析阅读Pre
    SVN常用功能介绍(二)
    SVN常用功能介绍(一)
    分页sql大全
    .NetCore 登录(密码盐+随机数)
  • 原文地址:https://www.cnblogs.com/general10/p/7224948.html
Copyright © 2011-2022 走看看