做做2 贪心

1 / 6Problem GPOJ 2376Cleaning Shifts
1 / 2Problem HPOJ 1328Radar Installation
1 / 2Problem IPOJ 3190Stall Reservations
1 / 3Problem JPOJ 2393Yogurt factory
1 / 2Problem KPOJ 1017Packets
1 / 1Problem LPOJ 3040Allowance
1 / 1Problem MPOJ 1862Stripies
1 / 3Problem NPOJ 3262Protecting the Flowers

POJ 2376

#include<cstdio>
#include<algorithm>
using namespace std;

struct node{
  int x;
  int y;
};
bool cmp(node a, node b)
{
    if(a.x==b.x) return a.y>b.y;
    return a.x<b.x;
}
node a[25005];

int main()
{
    int n, t;
    while(~scanf("%d%d", &n, &t))
    {
        for(int i=0; i<n; i++)
            scanf("%d%d", &a[i].x, &a[i].y);
        sort(a, a+n, cmp);
        if(a[0].x>1)
        {
            printf("-1\n"); continue;
        }
        int id=a[0].y;
        int cnt=1;
        int temp=0;
        int max;
        for(int i=1; i<n; i++)
        {
            if(id>=t)
            {
              break;
            }
            if(a[i].y<=id) continue;
            if(a[i].x>id+1)
            {
                temp=1;
                break;
            }
            if(a[i].x<=id+1)
            {
               max=a[i].y;
               for(int j=i+1; j<n; j++)
               {
                   if(a[j].x>id+1)break;
                   if(a[j].y>max)
                   {
                       max=a[j].y;
                   }
               }
               id=max;
               cnt++;
            }

        }
        if(temp==1 || id<t)
            printf("-1\n");
        else
            printf("%d\n", cnt);
    }
    return 0;
}



POJ 1328    取圆与X轴交点,再贪心。

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

struct point{
  double x;
  double y;
};

bool cmp(point a, point b)
{
    return a.x<b.x;
}

point a[1005];
int n, d;



int main()
{
    int t=1;
    int xx, yy;
    while(~scanf("%d%d", &n, &d))
    {
        if(n==0 &&d==0) break;
        int tmp=0;
        for(int i=0; i<n; i++)
        {
            scanf("%d%d", &xx, &yy);
            if(yy>d || d<0)
            {
                tmp=1;
            }
            a[i].x=xx-sqrt(1.0*d*d-1.0*yy*yy);
            a[i].y=xx+sqrt(1.0*d*d-1.0*yy*yy);
        }
        if(tmp)
        {
            printf("Case %d: -1\n", t++);continue;
        }
        sort(a, a+n, cmp);
        int ans=1;
        double temp=a[0].y;
        for(int i=1; i<n; i++)
        {
            if(a[i].y<=temp)
                temp=a[i].y;
            else if(a[i].x>temp)
            {
                ans++;
                temp=a[i].y;
            }
        }
        printf("Case %d: %d\n", t++, ans);
        getchar();
    }


    return 0;
}



POJ 3190

#include<cstdio>
#include<algorithm>
#include<queue>

using namespace std;

struct cow{
  int st;
  int ed;
  int p;
};

cow a[50005];
int num[50005];
bool operator <(cow a, cow b)
{
    return a.ed>b.ed;
}

bool cmp(cow a, cow b)
{
    return a.st<b.st;
}
priority_queue<cow> q;
int n;

int main()
{
    while(~scanf("%d", &n))
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d%d", &a[i].st, &a[i].ed);
            a[i].p=i;
        }
        sort(a+1, a+1+n, cmp);
        int barn=1;
        while(!q.empty())q.pop();
        q.push(a[1]);
        num[a[1].p]=barn;
        for(int i=2; i<=n; i++)
        {
            cow temp = q.top();
            if(temp.ed<a[i].st)
            {
                q.pop();
                q.push(a[i]);
                num[a[i].p]=num[temp.p];
            }
            else
            {
                q.push(a[i]);
                num[a[i].p]=++barn;
            }

        }
        printf("%d\n", barn);
        for(int i=1; i<=n; i++)
            printf("%d\n", num[i]);

    }

    return 0;
}



POJ 2393

#include<cstdio>
#include<algorithm>
using namespace std;

int c[10005], y[10005];
int n, s;
long long ans;
int main()
{
    while(~scanf("%d%d", &n, &s))
    {
        for(int i=0; i<n; i++)
            scanf("%d%d", &c[i], &y[i]);
        for(int i=1; i<n; i++)
            c[i]=min(c[i-1]+s, c[i]);
        ans=0;
        for(int i=0; i<n; i++)
            ans+=c[i]*y[i];
        printf("%lld\n", ans);
    }

    return 0;
}



POJ 1017  手动模拟

#include<cstdio>
#include<algorithm>
using namespace std;

int main()
{
    int a[6], t, m;
    while(~scanf("%d%d%d%d%d%d", &a[0],&a[1],&a[2],&a[3],&a[4],&a[5]), a[0]|a[1]|a[2]|a[3]|a[4]|a[5])
    {
        int ans=0;
        t=0;
        ans+=a[3]+a[4]+a[5];
        a[0]=max(a[0]-a[4]*11, 0);
        t=a[3]*5-a[1];
        if(t>0)
        {
            a[1]=0;
            a[0]=max(a[0]-t*4, 0);
        }
        else
        {
            a[1]=a[1]-a[3]*5;
        }
        if(a[2]%4==0)
        {
            ans+=a[2]/4;
        }
        else
        {
            ans+=a[2]/4+1;
            t=a[2]%4;
            if(t==1)
            {
                 m=a[1]-5;
                if(m>=0)
                    a[1]-=5;
                else
                {
                    a[1]=0;
                    a[0]=max(a[0]+m*4,0);
                }
                a[0]=max(a[0]-7, 0);
            }
            else if(t==2)
            {
                m=a[1]-3;
                if(m>=0)
                    a[1]-=3;
                else
                {
                    a[1]=0;
                    a[0]=max(a[0]+m*4, 0);
                }
                a[0]=max(a[0]-6, 0);
            }
            else
            {
                m=a[1]-1;
                if(m>=0)
                    a[1]-=1;
                else
                {
                    a[1]=0;
                    a[0]=max(a[0]+4*m, 0);
                }
                a[0]=max(a[0]-5, 0);
            }
        }
        if(a[1]%9==0)
            ans+=a[1]/9;
        else
        {
            ans+=a[1]/9+1;
            t=a[1]%9;
            a[0]=max(a[0]-(9-t)*4, 0);
        }
        if(a[0]%36==0)
            ans+=a[0]/36;
        else
            ans+=a[0]/36+1;
        printf("%d\n", ans);
    }
    return 0;
}



POJ 3040  求出当前最佳方案

#include<cstdio>
#include<string.h>
#include<algorithm>
using namespace std;

struct state{
  int v;
  int b;
};
bool cmp(state a, state b)
{
    return a.v<b.v;
}
state a[21];
int need[21];
int main()
{
    int n, c;

    while(~scanf("%d%d", &n, &c))
    {
        for(int i=0; i<n; i++)
            scanf("%d%d", &a[i].v, &a[i].b);
        sort(a, a+n, cmp);
        int ans=0, lim=-1;
        for(int i=n-1; i>=0; i--)
            if(a[i].v>=c) ans+=a[i].b;
            else
              {
                  lim=i;
                  break;
              }
        while(1)
        {
            memset(need, 0, sizeof(need));
            int res=c, ti;
            for(int i=lim; i>=0; i--)
            {
                if(!a[i].b||!res) continue;
                ti=res/a[i].v;
                ti=min(ti,a[i].b);
                need[i]=ti;
                res-=ti*a[i].v;
            }
            if(res)
            {
                for(int i=0; i<=lim; i++)
                {
                    if(a[i].v>=res && (a[i].b>need[i]))
                    {
                        need[i]++;
                        res=0;
                        break;
                    }
                }
                if(res) break;
            }
            int day=99999999;
            for(int i=0; i<=lim; i++)
                if(need[i])
                day=min(day, a[i].b/need[i]);
            ans+=day;
            for(int i=0; i<=lim; i++)
                a[i].b-=day*need[i];
        }
        printf("%d\n", ans);
    }

}


POJ 1862  给出2种思路, 一种是利用直接求出的公式W=2sqrt(2sqrt(...)) ( (m1m2)^(0.5^(n-1))m3^(0.5^(n-2))...mn^0.5)

                                                                                                            n-1

,另外一种是暴力

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

bool cmp(int a, int b)
{
    return a>b;
}

int main()
{
    int n;
    double a[105];
    while(~scanf("%d", &n))
    {
        for(int i=0; i<n; i++)
            scanf("%lf", &a[i]);
        if(n==1)
        {
            printf("%.3lf\n", a[0]);
            continue;
        }
        double ans=2;
        sort(a, a+n, cmp);
        for(int i=2; i<n; i++)
        {
            ans=sqrt(ans);
            ans*=2;
        }
        a[0]=pow(a[0], pow(0.5, n-1));
        for(int i=1; i<n; i++)
            a[i]=pow(a[i], pow(0.5, n-i));
        for(int i=0; i<n; i++)
            ans*=a[i];
        printf("%.3lf\n", ans);
    }

    return 0;
}

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

bool cmp(int a, int b)
{
    return a>b;
}

int main()
{
    int n;
    double a[105];
    while(~scanf("%d", &n))
    {
        for(int i=0; i<n; i++)
            scanf("%lf", &a[i]);
        if(n==1)
        {
            printf("%.3lf\n", a[0]);
            continue;
        }
        double ans=1;
        sort(a, a+n, cmp);
        a[1]=2*sqrt(a[0]*a[1]);
        for(int i=2; i<n; i++)
            a[i]=2*sqrt(a[i]*a[i-1]);

        printf("%.3lf\n", a[n-1]);
    }

    return 0;
}



POJ 3262

选择策略,
1 在二个中间选择之中,能根据time/eat小的那个为最优解
证明:
二个牛中 A,B,属性分别为分别为eatA,timeA,eatB,timeB
选A的时候损失timeA*eatB
选B的时候损失timeB*eatA
双方同除以eatA*eatB.
令time/eat为一个羊的比率x
可以证明x小的那个为最优解.

 

#include<cstdio>
#include<algorithm>
using namespace std;

struct cow{
  int d;
  int t;
  double p;
};
bool cmp(cow a, cow b)
{
    return a.p<b.p;
}

cow a[100005];
long long time[100005];

int main()
{
    int n;
    while(~scanf("%d", &n))
    {
        for(int i=0; i<n; i++)
        {
            scanf("%d%d", &a[i].t, &a[i].d);
            a[i].p=a[i].t*1.0/a[i].d;
        }

        sort(a, a+n, cmp);
        long long ans=0;
        time[0]=0;
        for(int i=1; i<n; i++)
            time[i]=2*a[i-1].t+time[i-1];
        for(int i=0; i<n; i++)
            ans+=a[i].d*time[i];
        printf("%lld\n", ans);
    }

    return 0;
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值