栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 3266 Cow School

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 3266 Cow School

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn=5e4+9;double high[maxn],low[maxn];long long sumt[maxn],sump[maxn];struct D{    long long t,p;    bool operator <(const D & xx) const    {        return t*xx.p>xx.t*p;    }}test[maxn];int que[maxn];bool chk(int i,int j,int t,int s){    long long a=(test[i].t-test[j].t)*(test[t].p-test[s].p);    long long b=(test[t].t-test[s].t)*(test[i].p-test[j].p);    return a>b;}bool chk2(int i,int j,long long t,long long p){    long long a=(test[i].t-test[j].t)*p;    long long b=t*(test[i].p-test[j].p);    return a>b;}int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        for(int i=1;i<=n;i++)        scanf("%lld %lld",&test[i].t,&test[i].p);        sort(test+1,test+1+n);        for(int i=1;i<=n;i++)        { sumt[i]=sumt[i-1]+test[i].t; sump[i]=sump[i-1]+test[i].p;        }        int front=1,end=0;        for(int i=1;i<=n;i++)        { while(end>=front&&test[i].p>=test[que[end]].p) end--; while(end>front&&chk(que[end],i,que[end-1],que[end])) end--; que[++end]=i; while(front<end&&chk2(que[front],que[front+1],sumt[i],sump[i])==1) front++; int u=que[front]; low[i]=test[u].t-(double)sumt[i]/sump[i]*test[u].p;        }        int top=0;        for(int i=n;i>=1;i--)        { while(top>0&&test[i].p<=test[que[top]].p) top--; while(top>1&&chk(i,que[top],que[top],que[top-1])) top--; que[++top]=i; while(top>1&&chk2(que[top],que[top-1],sumt[i-1],sump[i-1])==0) top--; int u=que[top]; high[i]=test[u].t-(double)sumt[i-1]/sump[i-1]*test[u].p;        }        int ans=0;        for(int i=1;i<n;i++)        if(high[i+1]>low[i])        ans++;        cout<<ans<<endl;        for(int i=n-1;i>=1;i--)        if(high[i+1]>low[i])        printf("%dn",n-i);    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/367496.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号