FZU 2077 the tallest trees
来源:互联网 发布:免费邮件群发软件 编辑:程序博客网 时间:2024/06/06 12:54
题目
做题思路:按每天生长速度排序,再按高度排序,每次遍历找到最靠左的且最高的那个记录idx,排序的话是生长速度是第一序 高度按第二序。这样就可以直接暴力水过了。在群里别人告诉我的思路
#include<stdio.h>#include<algorithm>#include<iostream>#include<math.h>#include<string.h>using namespace std; #define maxn 100006struct node{int h,v;}num[maxn];struct Que{int val;int ID;int ans;}Q[maxn];bool cmp1(node a,node b){return ( a.v>b.v )||( a.v==b.v && a.h>b.h);}bool cmp2(Que a,Que b){return a.val < b.val;}bool cmp3(Que a,Que b){return a.ID < b.ID; }int main(){int n,m;int i,j;int MAX;int id;int tmp;int iid;while(scanf("%d%d",&n,&m)!=EOF){for(i=0;i<n;i++){scanf("%d%d",&num[i].h,&num[i].v);}sort(num,num+n,cmp1);MAX=-1;for(i=0;i<n;i++){if(num[i].h>MAX){MAX=num[i].h;id=i;}}////////离线算法///////////for(i=0;i<m;i++){scanf("%d",&Q[i].val);Q[i].ID=i;}sort(Q,Q+m,cmp2);for(i=0;i<m;i++){MAX=-1;for(j=0;j<=id;j++){tmp=Q[i].val*num[j].v+num[j].h;if(MAX<tmp){MAX=tmp;iid=j;}}Q[i].ans=MAX;id=iid;}sort(Q,Q+m,cmp3);for(i=0;i<m;i++)printf("%d\n",Q[i].ans);}return 0; }
- FZU 2077 the tallest trees
- TOJ 4349: The Tallest in the Class
- Q9.10 To build the tallest stack
- the globe's tallest store shopping
- FZU -- 2157 ProgramCaicai's Trees
- Fzu 2157 ProgramCaicai's Trees【树型dp】
- The Longest Straight FZU
- 1392 Surround the Trees
- Surround the Trees
- 10562 - Undraw the Trees***
- UVa10007 - Count the Trees
- Surround the Trees
- UVA10562Undraw the Trees
- 10562 - Undraw the Trees
- UVA10562 - Undraw the Trees
- UVaOJ10562---Undraw the Trees
- Query on The Trees
- Eat the Trees hdoj1693
- 一个关于hello word的思考.
- java基础视频25days(毕老师)学习日志(day04、day05、day06) .
- 计算机编码
- ubuntu下安装gnuplot
- 修复hbase region hole问题流程
- FZU 2077 the tallest trees
- word生成目录
- 图像处理
- 弹出自定义提示框
- javascript 经典技巧
- C++求最大公约数与最小公倍数
- java基础视频25days(毕老师)学习日志(day01、day02、day03)
- 利用DelayLoad来优化应用程序的性能,拦截API.
- 超级转霸破解版