ZOJ1025 Wooden Sticks

低电压高效率能源管理芯片BQ25570的基本用法及应用电路实例 BQ25570是一款低电压、高效率、集成了可编程功率追踪(MPPT)功能、BOOST升压功能和BUCK降压功能的综合型能源管理电路。冷启动工作电压为330mV,热启动工作电压为100mV。主要应用于温差发电片TEG、压电、摩擦发电和太阳能板的能量收集,也可以用于人体可穿戴自取能传感设备的能量管理。本文主要介绍了BQ25570相关参数计算、MPPT功能验证、工作逻辑和应用场景,并设计了一版测试电路,给出了不同应用需求的电路配置建议。 阅读详情

题目:

Description
There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called setup time, for the machine to prepare processing a stick. The setup times are associated with cleaning operations and changing tools and shapes in the machine. The setup times of the woodworking machine are given as follows:

(a) The setup time for the first wooden stick is 1 minute.
(b) Right after processing a stick of length l and weight w , the machine will need no setup time for a stick of length l’ and weight w’ if l<=l’ and w<=w’. Otherwise, it will need 1 minute for setup.

You are to find the minimum setup time to process a given pile of n wooden sticks. For example, if you have five sticks whose pairs of length and weight are (4,9), (5,2), (2,1), (3,5), and (1,4), then the minimum setup time should be 2 minutes since there is a sequence of pairs (1,4), (3,5), (4,9), (2,1), (5,2).

Input

The input consists of T test cases. The number of test cases (T) is given in the first line of the input file. Each test case consists of two lines: The first line has an integer n , 1<=n<=5000, that represents the number of wooden sticks in the test case, and the second line contains n 2 positive integers l1, w1, l2, w2, …, ln, wn, each of magnitude at most 10000 , where li and wi are the length and weight of the i th wooden stick, respectively. The 2n integers are delimited by one or more spaces.

Output

The output should contain the minimum setup time in minutes, one per line.

Sample Input

3
5
4 9 5 2 2 1 3 5 1 4
3
2 2 1 1 2 2
3
1 3 2 2 3 1

Output for the Sample Input

2
1
3

思路:

题意大概是锯木桩,每次小于前面开过机的长和厚不用建立,大于的话就得重新发动,发动时间为1,为求最小发动时间。其实就是求最少组的非递减子序列。

第一种动态规划吧,相当于是最长不下降子序列长度问题。嗯,先对l.w升序排,先排长度,长度相等时在按重量的升序排。再求重量的最长下降子序列长度L,即为所求。然而我并不会证。

第二种贪心吧,一边找一边标记找过了。

代码:

DP

#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
using namespace std;
struct node
{
    int l, w;
};
bool cmp(const node& a,const node& b){
    if (a.l == b.l){
        return a.w < b.w;
    }
    return a.l < b.l;
}
node sticks[5005];
int main()
{
    int T,n;
    scanf("%d",&T);
    while (T--){
        scanf("%d",&n);
        memset(sticks,0,sizeof(sticks));
        for (int i = 0; i < n; i++){
            scanf("%d%d",&sticks[i].l,&sticks[i].w);
        }
        sort(sticks,sticks+n,cmp);
        vector<int> dp(n, 1);
        int longest = 1;    
        for (int i = 1; i < n; i++){
            for (int j = 0; j < i; j++){
                if (sticks[i].w < sticks[j].w){
                    dp[i] = max(dp[i],dp[j]+1);
                }
            }
            longest = max(longest,dp[i]);
        }
        printf("%d\n",longest);
    }
    return 0;
}

贪心:

#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
struct node{
    int l, w;
    bool flag;
    node() :l(0), w(0), flag(false){

    }
};
bool cmp(const node& a,const node& b){
    if (a.l == b.l){
        return a.w < b.w;
    }
    return a.l < b.l;
}
int main()
{
    int T, n;
    scanf("%d",&T);
    while (T--){
        scanf("%d",&n);
        node* sticks = new node[n];
        for (int i = 0; i < n;i++){
            scanf("%d%d",&sticks[i].l,&sticks[i].w);
        }
        sort(sticks,sticks+n,cmp);
        int res=0;
        for (int i = 0; i < n; i++){
            if (sticks[i].flag){
                continue;
            }
            res++;
            int tmp = sticks[i].w;
            for (int j = i; j < n; j++){
                if (tmp <= sticks[j].w && !sticks[j].flag){
                    sticks[j].flag = true;
                    tmp = sticks[j].w;
                }
            }
        }
        printf("%d\n",res);
    }
    return 0;
}
【超详细】C#的单例模式 本文详细介绍了C#中的单例设计模式,包括两种实现方式:普通类泛型单例(Singleton<T>)和基于MonoBehaviour的组件单例(MonoSingleton<T>)。单例模式通过私有构造、静态私有实例和公共访问入口确保全局唯一实例,具有节省资源、保证数据一致性等优势。文章分别阐述了两者的核心原理、代码实现、使用场景及注意事项,并提供了日志管理器和音效管理器的具体应用示例。特别强调了多线程安全、初始化时机和避免过度使用等重要原则,为Unity开发中合理运用单例模式提供了全面指导。 阅读详情

相关推荐

告别死记硬背!用业务场景驱动理解SAP PS OPSA参数文件配置

本文通过制造业新产品研发项目案例,详细解析SAP PS模块中OPSA参数文件配置的实际应用。从项目立项、WBS分解到研发物料管理,系统讲解关键配置项的业务价值,帮助用户告别死记硬背,实现业务场景驱动的参数配置学习。特别适合制造业项目管理人员提升SAP PS配置效率。

weixin_30415113的博客 483

zoj 1025 wooden sticks

最近在不忙的时候做做zoj上的题,感觉还是挺好玩的。 下面是对1025这道题的分析。 首先,这道题是一条比较简单的题,核心是求最长非递减子序列的值。 这道题每个case的输入是n个stick的l和w,首先按照l和w进行降序排序(l优先级高于w)。 然后对排序结果求最长非递减序列的长度,就是问题的结果,代码如下。 #include #include #include usi

u010674227的博客 356

金蝶EAS uploadlogo漏洞实战:如何快速检测你的系统是否受影响

本文详细解析了金蝶EAS uploadlogo任意文件上传漏洞的检测与防护方法,帮助企业安全团队快速识别系统风险。通过资产发现、漏洞验证和应急响应方案,有效防范财务数据泄露和系统入侵风险,提升企业整体安全防护能力。

weixin_29322553的博客 398

【算法】ZOJ1025-Wooden Sticks

描述 现有n根木棒,已知它们的长度和重量。要用一部木工机一根一根地加工这些木棒。该机器在加工过程中需要一定的准备时间,是用于清洗机器,调整工具和模版的。 木工机需要的准备时间如下: (1)第一根木棒需要1min的准备时间; (2)在加工了一根长为l ,重为w的木棒之后,接着加工一根长为l ’ (l ≤ l’ ),重为 w’ ( w≤w’)的木棒是不需要任何准备时间的,否则需要一分钟的准备时间。 给...

SuperSources的博客 464

CANoe的安装教程

CANoe的安装教程

weixin_59090531的博客 1万+

Python+ArcGIS实战:5步搞定土壤类型预测(附随机森林模型配置技巧)

本文详细介绍了如何结合Python与ArcGIS,利用随机森林模型进行土壤类型预测。通过5个核心步骤——数据预处理、样本创建、模型构建、空间预测与精度验证,构建了一套自动化、高精度的空间预测工作流,并提供了关键的模型配置与调参技巧,助力GIS开发者高效完成土壤制图任务。

weixin_29227585的博客 402

ZOJ1025-Wooden Sticks

完整程序: #include<bits/stdc++.h> using namespace std; //ZOJ1025-Wooden Sticks贪心算法 #define maxN 5001 struct stick { int l; //木棒的长度 int w; //木棒的重量 }; stick data[maxN]; //存放所有...

kt1776133839的博客 320

[PCIE5.0] 4.2.3.2 Encoding of Presets

• 发射器预设:发射器预设值用4位二进制编码,表示不同的预设设置(P0 到 P10),这些设置定义了信号的传输特性。• 接收器预设提示:接收器预设提示是通过3位二进制编码告诉接收器建议的增益值,用于调整接收器的灵敏度(适用于8.0 GT/s数据速率)。

系统固件工程师 586

[zoj]1025

题意:给你n个棒子,每个棒子有两个属性(l,w),现在要加工棒子,求加工的最短时间 思路:求不同的最长不降子序列的总个数 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typ...

weixin_30732825的博客 258

2026年CSP-J初赛真题及答案解析

2026年CSP-J初赛真题及题解

王老师青少年编程 1703

【CASS精品教程】032:CASS11台阶画法案例大全

一、普通无边台阶 二、普通有边台阶 三、普通圆弧无边台阶 四、U型台阶 五、曲线U型台阶 六、L型台阶

智慧空间实验室 7517

zoj1025

zoj1025

zzu-hust-madd 427

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

zoj 1025 Wooden Sticks

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=25   引用cc98 watashi 大牛的话: 其实题目的意思就是把所有元素分为最少的堆数,每堆有l可以证明不下降序列完全覆盖数就是最长下降子列的长度(记为L): 显然覆盖数不能比L小,否则由抽屉原理,必然有下降子列中两元素(a 于是先将数列按照l,w的

/0 1330

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Zoj 1025 Wooden Sticks

There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called

Magic__ 1160

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

ZOJ1025-Wooden Sticks 加工木棒问题

ZOJ1025-Wooden Sticks 加工木棒问题 【问题描述】 现有n根木棒,已知它们的长度和重量。要用一部木工机一根一根地加工这些木棒。该机器在加工过程中需要一定的准备时间用于清洗机器、调整工具和模板。 木工机需要的准备时间如下: (1) 第一根木棒需要1min的准备时间; (2) 在加工了一根长为l,重为w的木棒后,接着加工一根长为l’(l≤l’), 重为w’(w≤...

sinat_38432876的博客 597

ZOJ - 1025 Wooden Sticks 【贪心】

Description There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some...

一定要站在自己热爱的生活里闪闪发光 3万+

ZOJ 1025 Wooden Sticks

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=25 题目大意:锯木桩,每次小于前面开过机的长和厚不用建立,大于的话就得重新发动,发动时间为1,为求最小发动世界。 先快排(从大到小),在求下降子序列。 先快排(从小到大),再求有几个连续上升子序列,下面代码按这种做法做 代码: #inclu

老子(道家) 555

ZOJ 1025:Wooden Sticks

Wooden Sticks Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a

小坏蛋_千千 583

[ZOJ - 1025] Wooden Sticks (贪心)

链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1025 题意 给你nnn个(l,w)(l,w)(l,w),你排列它们,你尽可能地想使得li−1&lt;=li and wi−1&lt;=wil_{i-1}&lt;=l_i\ and\ w_{i-1}&lt;=w_ili...

梧桐 256

ZOJ 1025 Wooden Sticks【非DP做法】

//2629969 2011-08-16 16:36:14 Accepted 1025 C 10 200 ylwh@Unknown #include #include #include #define N 5001 struct node { int l,

我辈皆愚 586
上一篇: LeetCode131. Palindrome Partitioning
下一篇: LeetCode55. Jump Game
_IanXiao
博客等级 码龄12年 84粉丝 241原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址