• R is the order a rabbit (末尾不能有空格!!,蚂蚁爬动问题)


    In a remote place, there is a rabbits market where rabbits can be bought and sold in every day. The trading rules in this market are as follows:
    
    1.The market is available only in morning and afternoon in one day. And the rabbit transaction price may be different every day even different between morning and afternoon in a day.
    
    2.It is prohibited that purchasing more than once in a day. And only one rabbit can be purchased at a time.
    
    3. You can only sell once in a day, but you can sell rabbits unlimited quantities (provided that you have so many rabbits)
    
    Mr.Cocktail has traded in this market for N days, suppose he has unlimited money to buy rabbits. Before the first day and after the last day, he has no rabbits. Now, in these N days, how much money did he earn the most?
    
    Input
    The first line contains a positive integer N, which means there are N days in total (1 \leq n \leq 10^5)(1≤n≤10 
    5
     )
    
    Next, there are N lines, each line contains two positive integers, representing the rabbit price in the morning and afternoon of the day a_i,b_i(1 \leq a_i ,b_i \leq 10^9)a 
    i
    ​
     ,b 
    i
    ​
     (1≤a 
    i
    ​
     ,b 
    i
    ​
     ≤10 
    9
     ).
    
    Output
    Output an integer on a line to indicate the answer.
    
    Sample 1
    Inputcopy    Outputcopy
    3
    1 6
    2 3
    7 1
    11
    Sample 2
    Inputcopy    Outputcopy
    2
    5 4
    3 2
    0
    Note
    In example 1, a rabbit was purchased for 1 in the morning of the first day, and a rabbit was purchased for1inthemorningofthefirstday,andarabbitwaspurchasedfor2 in the afternoon of the second day. On the morning of the third day, the two rabbits were sold, a total profit of $11.
    
    The price of the rabbit in sample 2 continues to decrease, and it is impossible to make money through buying and selling, so choose not to make any buying and selling, and output the answer 0.
    View problem

    swjtu—春季集训 - Virtual Judge (vjudge.net)

    思路:

    • 就是拿到蚂蚁爬的问题,碰撞相互变向,我们思考就让他不变向,按着原来方向走就行了,
    • 这样 k秒过后,就是 答案的位置,
    • 如何确定每一个位置具体是那个呢?
    • 按照 原来的位置进行排序,因为不允许相互穿过去,所以k秒后,原来的排序大小还是不变
    #include <bits/stdc++.h>
    using namespace std;
    #define ri register int
    #define M  100055
    
    template <class G >void read(G &x)
    {
        x=0;int f=0;char ch=getchar();
        while(ch<'0'||ch>'9'){f|=ch=='-';ch=getchar();}
        while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
        x=f?-x:x;
        return ;
    }
    
    struct dian{
        int  val,id;
        int v;
        bool operator <(const dian &t)const
        {
            return val<t.val;
        }
    }p[M];
    int n,m;
    int num[M];
    long long ans[M];
    int main(){
        
        read(n);read(m);
        for(ri i=1;i<=n;i++)
        {
            read(p[i].val);read(p[i].v);
            p[i].id=i;
        }
        sort(p+1,p+1+n);
        for(ri i=1;i<=n;i++)
        {
            num[i]=p[i].id;
        }
        for(ri i=1;i<=n;i++)
        {
            p[i].val+=p[i].v*m;
        }
        sort(p+1,p+1+n);
        for(ri i=1;i<=n;i++)
        {
            ans[num[i]]=p[i].val;
        }
        for(ri i=1;i<=n;i++)
        {
            if(i==1)
            printf("%lld",ans[i]); ////////////// ma de 
            else printf(" %lld",ans[i]);  
        }
        return 0;
        
    }
    View Code

    后记:

    • !!!妈的,第一次遇到oj上不能允许某位有空格!!!
    • 这个错找了 25min !!气死了
  • 相关阅读:
    使用element-ui的table组件时,渲染为html格式
    vue-quill-editor富文本编辑器,添加了汉化样式却汉化不了
    MySQL版本问题导致的SQLException
    MySQL中 ORDER BY 与 LIMIT 的执行顺序
    MySQL 测试数据批量导入
    CentOS 7 安装 Maven
    CentOS 7 安装 Gradle
    CentOS 7 安装 RabbitMQ
    CentOS 7 安装 Tomcat 8.5.43
    CentOS 7 配置网络
  • 原文地址:https://www.cnblogs.com/Lamboofhome/p/16229514.html
Copyright © 2020-2023  润新知