做做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;
}



内容概要:本文详细介绍了基于C#的工业自动化通信开发库,涵盖了多种常见的通信协议和技术。首先讨论了串口通信的基础操作及其注意事项,如波特率设置和事件处理。接着深入探讨了TCP通信,特别是针对高并发场景下的粘包处理和性能优化。文中还详细讲解了Modbus协议的应用,包括RTU和TCP两种模式的具体实现和常见问题解决方法。此外,文章涉及了数据库操作的最佳实践,尤其是EF6与MySQL的配合使用,以及数据转换技巧,如字节序处理和布尔值提取。最后,简述了消息队列(如RabbitMQ)和CAN总线的使用场景和配置要点。每个部分都配有实际代码示例,帮助开发者更好地理解和应用这些技术。 适合人群:从事工业自动化领域的软件开发工程师,尤其是那些需要频繁处理通信协议和数据交互的技术人员。 使用场景及目标:适用于需要进行PLC通信、数据采集、监控系统集成等项目的开发人员。主要目标是提高开发效率,减少因协议复杂性和数据格式差异带来的困扰,确保系统的稳定性和可靠性。 其他说明:文章不仅提供了理论指导,还分享了许多实际项目中的经验和教训,强调了在真实环境中可能会遇到的问题及解决方案。对于初学者而言,可以作为入门指南;对于有一定经验的开发者,则可以作为参考手册,帮助他们优化现有系统并避免常见错误。
内容概要:本文档详细介绍了基于灰狼优化算法(GWO)优化逐次变分模态分解(SVMD)的MATLAB项目实例。项目旨在通过GWO优化SVMD中的关键参数(如模态数、惩罚因子等),提高信号分解的精度和效率,解决传统SVMD方法面临的参数选择和优化挑战。GWO算法通过模拟灰狼捕猎行为,实现全局搜索和局部搜索的平衡,增强了SVMD在处理非线性、非平稳和含噪信号时的能力。文档涵盖了项目背景、目标与意义、挑战及解决方案、特点与创新、应用领域、效果预测图程序设计及代码示例、模型架构、算法流程、目录结构设计、注意事项、扩展方向、部署与应用、未来改进方向、总结与结论以及详细的程序设计思路和具体代码实现。 适合人群:具备一定编程基础,特别是熟悉MATLAB和信号处理技术的研发人员,以及从事机械故障诊断、生物医学信号分析、地震信号处理、无线通信和金融市场分析等领域工作的工程师和研究人员。 使用场景及目标:①优化SVMD中的参数设置,提高信号分解的精度和效率;②处理非线性、非平稳和含噪信号,提取有用的特征;③应用于机械故障诊断、生物医学信号分析、地震信号处理、无线通信和金融市场分析等领域;④提供信号噪声抑制功能,减少噪声干扰,确保信号中的有用信息被充分提取;⑤拓宽算法的应用范围,为相关领域的信号处理提供高效、精确的工具。 其他说明:本项目不仅提供了详细的理论背景和技术实现,还附带了完整的代码示例和GUI设计,便于用户实践和调试。项目强调了数据质量和参数调整的重要性,同时对未来改进方向进行了展望,如引入深度学习技术、多模态信号融合、实时故障诊断功能、端到端加速、数据隐私保护与合规性、扩展到边缘计算平台、自动化模型训练与优化、系统的自我修复能力等。通过本项目的成功实现,可以为信号处理领域提供一种更加高效、精确、可靠的解决方案。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值