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.
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; }
后记:
- !!!妈的,第一次遇到oj上不能允许某位有空格!!!
- 这个错找了 25min !!气死了