ZOJ1025 Wooden Sticks

高德地图JS API私有化部署实战:从数据爬取到内网集成 本文详细介绍了高德地图JS API私有化部署的完整流程,涵盖从地图瓦片数据爬取、JS API离线化改造到内网项目集成的实战步骤。重点解决了在封闭内网环境中实现地图功能的核心难题,并提供了Vue.js项目中的具体集成代码与调试技巧,帮助开发者在离线环境下构建稳定可靠的地图应用。 阅读详情

题目:

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;
}
Halcon: 获取仿射矩形-rectangle2的四个顶点、四条边的中点 Halcon 工业应用实用教程中的一个例子: * CenterY : 仿射矩形中心y * CenterX: 仿射矩形中心x * Phi: 仿射矩形角度 * Len1: 仿射矩形宽的一半 * Len2: 仿射矩形高的一半 * CornerY: 仿射矩形端点y * CornerX: 仿射矩形端点x * LineCenterY: 仿射矩形边中点y * LineCenterx: 仿射矩形边中点x * 矩... 阅读详情

相关推荐

Vivado时序违约小结

目录1. setup time违约1.1 逻辑级数太高1.2 Fanout太大2. hold time 违约2.1 异步信号处理导致hold time违约 1. setup time违约 建立时间是工程设计中最常遇到的问题了。一般说来,导致建立时间违例主要有两个原因:逻辑级数太大或者扇出太大,当然也可以尝试通过降频来解决建立时间违约。 1.1 逻辑级数太高 Levels指的是逻辑级数logic level,一个logic level的延迟对应的是一个LUT和一个Net的延迟,对于不同的器件,不同频率的设计能

mu_guang_的博客 7155

zoj 1025 wooden sticks

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

u010674227的博客 356

PSIM+PIL+CCS三剑客:手把手教你搞定DSP28335的软硬件联合调试

本文详细介绍了如何利用PSIM、PIL与CCS三款工具,实现DSP28335的软硬件联合调试。通过搭建兼容环境、从PSIM仿真生成PIL代码,再到实战联合调试与问题诊断,手把手指导开发者构建从虚拟模型到实际硬件的完整验证闭环,有效提升电力电子与电机驱动等领域的开发效率与可靠性。

weixin_29183637的博客 185

【算法】ZOJ1025-Wooden Sticks

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

SuperSources的博客 462

读《认知科学导论》(萨伽德) 总结

1. 作者的写作思路 本书是建立在对心智的理解采用表征与计算的方式。对心智表征-计算的理解方式是与计算机的本质相联系。计算机本质上是一个符号系统,符号系统包含两个部分,一个是符号,另一个是建立在符号上的操作。对心智采用表征-计算的方式理解,很容易与计算机建立起类比关系。同时人们在探索人工智能领域采用表征-计算方式已经取得了无数辉煌的成就,故表征-计算式现在研究的主流方法。 本书的有两个部分组成

xiaoqiangXX的专栏 3450

[AI] 企业内网部署大模型的三种常见方案:从“能用”到“好用”的技术选型指南

企业内网部署大模型的三种方案解析:本地模型安全但门槛高,平台方案(如Dify)最平衡推荐,混合架构适合进阶需求。关键路径是渐进式演进,从快速验证到平台化建设,核心在于流程优化而非单纯选模型。数据安全、成本可控和工程落地能力是决策重点。

技术小甜甜:传播可落地技术,帮助个人和企业降低解决真实场景问题的成本 770

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

redhawk:STA timing data file解析

我正在「拾陆楼」和朋友们讨论有趣的话题,你⼀起来吧?STA timing data file分为以下几个部分:• Header• Name Map• Footer这部分报告设计的基本信息,例如文件类型,设计名称,分隔符等。...

m0_61544122的博客 1153

[zoj]1025

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

weixin_30732825的博客 257

VTK API 详解(134):vtkOBJWriter - 写入 OBJ 模型

是 VTK 中用于将数据写入 Wavefront OBJ 文件格式的类。OBJ 格式是广泛支持的 3D 网格模型格式,支持顶点、面和基本几何信息的保存,便于模型在多种三维软件间交换。

yumeiguo的博客 140

基于STM32的智能手环心率血氧体温监测系统(完整设计)

本文设计了一款基于STM32单片机的多功能智能手环系统,集成心率、血氧、体温实时监测功能,并支持运动数据管理与健康预警。系统采用MAX30102传感器实现心率血氧监测,DS18B20检测体温,ADXL345进行步数统计,通过OLED屏幕显示数据。研究通过低功耗硬件选型与模块化软件架构设计,实现了多参数同步采集、阈值预警及蓝牙数据传输功能。测试结果表明,系统在健康监测精度、续航能力及用户交互体验上均达到预期目标,为个人健康管理提供了实用解决方案。

3254968421的博客 701

zoj1025

zoj1025

zzu-hust-madd 426

Python爬虫-爬取猫眼演出数据

本文是该专栏的第53篇,后面会持续分享python爬虫干货知识。猫眼平台除了有影院信息之外,它还涵盖了演出信息,比如说“演唱会,音乐节,话剧音乐剧,脱口秀,音乐会,戏曲艺术,相声”等等各种演出相关信息。而本文,笔者将以猫眼平台为例,基于Python爬虫实现获取各种演出信息的数据。废话不多说,具体细节部分以及详细思路逻辑,笔者将在正文结合完整代码进行详细说明。(附带完整代码)

Python进阶专栏《爬虫实战进阶》,《Pyppeteer从入门到精通》原创作者 568

zoj 1025 Wooden Sticks

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

/0 1329

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

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__ 1158

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

ZOJ1025-Wooden Sticks 加工木棒问题

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

sinat_38432876的博客 597

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

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

老子(道家) 554

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

小坏蛋_千千 579

[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、付费专栏及课程。

余额充值