USACO 6.2.2 Packing Rectangles 暴力模拟

别再瞎改注册表了!实测Win10/Win11远程桌面60帧的正确姿势(附ToDesk对比) 本文深入解析Windows远程桌面60帧优化的科学方法,揭示常见误区并提供实测有效的解决方案。从版本差异到硬件加速,再到第三方工具对比(如ToDesk),帮助用户避开无效的注册表修改,实现流畅的远程桌面体验。 阅读详情

http://train.usaco.org/usacoprob2?a=Hfv8bxVT1Ac&S=packrec

题目大意:给四个矩形(用长和宽表示),求能够将他们全部包起来的最小矩形面积和边长(按照较短边升序输出)

※给了四个矩形的六种基本摆放方法:


原本以为又是什么巧妙的构造法,但是看他给了六种基本摆放方法再估算一下所有的可能性感觉可以直接模拟,事实确实如此

现在只留下了两个问题:1、图四和图五有什么区别 2、图六的外围矩形面积该如何计算

1、图四和图五没有任何区别

2、图六的计算我想了很久,一开始想用左右两组的高度确定高度,用上下两组的宽度确定宽度,但尝试之后发现可能会有斜对角矩形碰撞的问题

void form6()
{
    int width, height;
    width = max(cur[0].width+cur[1].width, cur[2].width+cur[3].width);
    height = max(cur[0].height+cur[2].height, cur[1].height+cur[3].height);
    judge(width, height);

    width = max(cur[0].width+cur[3].width, cur[1].width+cur[2].width);
    height = max(cur[0].height+cur[1].height, cur[3].height+cur[2].height);
    judge(width, height);

    width = max(cur[0].width+cur[3].width, cur[2].width+cur[1].width);
    height = max(cur[0].height+cur[2].height, cur[3].height+cur[1].height);
    judge(width, height);
}

后来想通过平移使上下两组被一条水平线分割,但在有些情况下这样求得的不是最小矩形(但是能过前2/3样例)

特殊情况(上左5*5,上右3*6,下左4*4,下右4*3)

void form6()
{
    int width, height;
    for(int i = 0; i < 4; ++i){
        for(int k = 0; k < 4; ++k){
            if(k == i) continue;
            width = 0; height = 0;
            for(int j = 0; j < 4; ++j){
                if(j == i || j == k) continue;
                width += cur[j].width;
                height = max(height, cur[j].height);
            }
            width = max(width, (cur[k].width)+cur[i].width);
            height += max(cur[k].height, cur[i].height);
            judge(width, height);
        }
    }
}

看了题解才恍然大悟,我之前太拘泥于整体性的考虑,想要得到一个普适的几何公式,这样就要考虑很多种碰撞的可能性,简直就是庸人自扰。题目给的提示已经很明显了,将方块分为左右两组,以左侧为参照,根据右侧两块的高低,会有不同的两两碰撞情况,通过分类讨论的方式就只需要解决一些简单明了的情况了

参考:http://blog.sina.com.cn/s/blog_5f5ada1a0100qhjr.html

※注意:即使在某一块不和其他块碰撞的情况下,它的宽度也应该被纳入计算

void form6()
{
    int width, height;
    for(int i = 0; i < 4; ++i){
        for(int k = 0; k < 4; ++k){
            if(k == i) continue;
            width = 0; height = 0;
            for(int j = 0; j < 4; ++j){
                if(j == i || j == k) continue;
                int l = 6-i-j-k;
                height = max(cur[i].height+cur[k].height, cur[j].height+cur[l].height);
                /*
                i   j
                k   l
                */
                if(cur[j].height+cur[l].height <= cur[k].height) width = max(cur[i].width, max(cur[j].width, cur[l].width)+cur[k].width);
                else if(cur[j].height+cur[l].height > cur[k].height && cur[l].height < cur[k].height) width = max(cur[l].width+cur[k].width, max(cur[i].width, cur[k].width)+cur[j].width);
                else if(cur[l].height >= cur[k].height && cur[l].height < cur[k].height + cur[i].height) width = max(cur[j].width+cur[i].width, max(cur[i].width, cur[k].width)+cur[l].width);
                else if(cur[l].height >= cur[k].height + cur[i].height) width = max(cur[j].width, max(cur[i].width, cur[k].width)+cur[l].width);
                judge(width, height);
            }
        }
    }
}


全部代码如下:

/*
ID: frontie1
TASK: packrec
LANG: C++
*/
#include <iostream>
#include <cstdio>

using namespace std;

const int INFI = 0x3f3f3f3f;

struct rectangle
{
    int width;
    int height;

    rectangle rota()
    {
        rectangle output;
        output.width = height;
        output.height = width;
        return output;
    }

    bool operator<=(rectangle &obj)
    {
        return (width <= obj.width);
    }

    bool operator==(rectangle &obj)
    {
        return (width == obj.width);
    }
    void print()
    {
        if(width > height) return;
        cout << width << ' ' << height << endl;
    }
};

rectangle ori[4], cur[4];
int output_area = INFI;
rectangle output[100];
int cnt = 0;

void judge(int w, int h)
{
    if(w*h <= output_area){
        if(w*h < output_area){
            output_area = w*h;
            cnt = 0;
        }
        output[cnt].width = min(w, h);
        output[cnt].height = max(w, h);
        ++cnt;
    }
}

void makeposition(int num)
{
    for(int i = 0; i < 4; ++i){
        if((num >> i) & 1) cur[i] = ori[i].rota();
        else cur[i] = ori[i];
    }
}

void form1()
{
    int width = 0, height = 0;
    for(int i = 0; i < 4; ++i){
        width += cur[i].width;
        height = max(height, cur[i].height);
    }
    judge(width, height);
}

void form2()
{
    int width, height;
    for(int i = 0; i < 4; ++i){
        width = 0; height = 0;
        for(int k = 0; k < 4; ++k){
            if(k == i) continue;
            width += cur[k].width;
            height = max(height, cur[k].height);
        }
        width = max(width, cur[i].width);
        height += cur[i].height;
        judge(width, height);
    }
}

void form3()
{
    int width, height;
    for(int i = 0; i < 4; ++i){
        for(int k = 0; k < 4; ++k){
            if(k == i) continue;
            width = 0; height = 0;
            for(int j = 0; j < 4; ++j){
                if(j == i || j == k) continue;
                width += cur[j].width;
                height = max(height, cur[j].height);
            }
            width = max(width, cur[k].width);
            height += cur[k].height;
            width += cur[i].width;
            height = max(height, cur[i].height);
            judge(width, height);
        }
    }
}

void form4()
{
    int width, height;
    for(int i = 0; i < 4; ++i){
        for(int k = 0; k < 4; ++k){
            if(k == i) continue;
            width = 0; height = 0;
            for(int j = 0; j < 4; ++j){
                if(j == i || j == k) continue;
                height += cur[j].height;
                width = max(width, cur[j].width);
            }
            height = max(height, cur[k].height);
            width += cur[k].width;
            width += cur[i].width;
            height = max(height, cur[i].height);
            judge(width, height);
        }
    }
}

void form6()
{
    int width, height;
    for(int i = 0; i < 4; ++i){
        for(int k = 0; k < 4; ++k){
            if(k == i) continue;
            width = 0; height = 0;
            for(int j = 0; j < 4; ++j){
                if(j == i || j == k) continue;
                int l = 6-i-j-k;
                height = max(cur[i].height+cur[k].height, cur[j].height+cur[l].height);
                /*
                i   j
                k   l
                */
                if(cur[j].height+cur[l].height <= cur[k].height) width = max(cur[i].width, max(cur[j].width, cur[l].width)+cur[k].width);
                else if(cur[j].height+cur[l].height > cur[k].height && cur[l].height < cur[k].height) width = max(cur[l].width+cur[k].width, max(cur[i].width, cur[k].width)+cur[j].width);
                else if(cur[l].height >= cur[k].height && cur[l].height < cur[k].height + cur[i].height) width = max(cur[j].width+cur[i].width, max(cur[i].width, cur[k].width)+cur[l].width);
                else if(cur[l].height >= cur[k].height + cur[i].height) width = max(cur[j].width, max(cur[i].width, cur[k].width)+cur[l].width);
                judge(width, height);
            }
        }
    }
}

void quicksort(int st, int ed)
{
    if(st >= ed) return;
    int lo = st, hi = ed;
    rectangle tem = output[lo];
    while(lo < hi){
        while(lo < hi && tem <= output[hi]) --hi;
        output[lo] = output[hi];
        while(lo < hi && output[lo] <= tem) ++lo;
        output[hi] = output[lo];
    }
    output[lo] = tem;
    quicksort(st, lo-1);
    quicksort(lo+1, ed);
}

int main()
{
    freopen("packrec.in", "r", stdin);
    freopen("packrec.out", "w", stdout);

    for(int i = 0; i < 4; ++i){
        cin >> ori[i].width >> ori[i].height;
    }

    for(int i = 0; i < 16; ++i){
        makeposition(i);
        form1();
        form2();
        form3();
        form4();
        form6();
    }

    cout << output_area << endl;
    quicksort(0, cnt-1);

    output[0].print();
    for(int i = 1; i < cnt; ++i){
        if(output[i] == output[i-1]) continue;
        else output[i].print();
    }

    return 0;
}

备注:可以注意到我在打印结果的时候加了一条(width < height)的判断,其实是多余的,因为在judge()函数里已经保证了这个性质,但是如果没有这条语句我会在第二个样例中发生错误,更诡异的是在本地跑的时候不会有这样的问题,实在是令人头大




RSA算法详解:万字文章详解RSA的加密与解密 为了彻彻底底的研究明白RSA算法,真的是。。煞(lei)费(si)苦(wo)心(le),首先我希望自己前前后后、彻彻底底的琢磨明白,其次我也希望我把他分享出来以后,大家都能读得懂,这篇文章真的是我迄今为止写的又臭又长的一篇文章了,但是我能保证的是,你读完了以后,绝对不会再问RSA是啥玩意儿了。。 阅读详情

相关推荐

onnx入门教程(一):解决模型部署中的难题

直接使用 PyTorch 模型的话,我们修改几行代码就能实现模型输入的动态化。但在模型部署中,我们要花数倍的时间来设法解决这一问题。现在,让我们顺着解决问题的思路,体验一下模型部署的困难,并学习使用自定义算子的方式,解决超分辨率模型的动态化问题。刚刚的报错是因为 PyTorch 模型在导出到 ONNX 模型时,模型的输入参数的类型必须全部是 torch.Tensor。而实际上我们传入的第二个参数" 3 "是一个整形变量。这不符合 PyTorch 转 ONNX 的规定。我们必须要修改一下原来的模型的输入。

图像学习之旅 1128

Transformations(模拟)(USACO)

Transformations(模拟)(USACO)

Ema1997的博客 615

东方财富网股票API逆向分析:手把手教你破解动态参数(2024最新版)

本文详细解析了2024年东方财富网股票API的动态参数生成机制,包括回调函数、身份验证和时效控制参数的逆向工程方法。通过实战代码演示,帮助开发者破解动态参数,实现高效稳定的股票数据爬取,适用于金融数据分析和量化交易场景。

weixin_29091105的博客 1025

2021.08.16【NOIP提高B组】模拟 USACO 2021 February Contest, Gold】Problem 2 Modern Art 3

思路: 区间DP,a[l]=a[r]时求l~r就是l+1到r或l到r-1 codecodecode #include<iostream> #include<cstdio> #include<cstring> using namespace std; int f[1010][1010]; int a[1010], n; int main() { scanf("%d", &n); for(int i=1; i<=n; i++) scanf(..

ha 200

32位ALU设计(verilog实现)

32位ALU设计 ​ 算术逻辑单元(arithmetic and logic unit) 是能实现多组算术运算和逻辑运算的组合逻辑电路,简称ALU。算术逻辑单元是中央处理器(CPU)的执行单元,是所有中央处理器的核心组成部分,由"And Gate"(与门) 和"Or Gate"(或门)构成的算术逻辑单元,主要功能是进行二位元的算术运算,如加减乘(不包括整数除法)。基本上,在所有现代CPU体系结构中,二进制都以补码的形式来表示。 设计思路 设计实现 仿真测试 文章目录32位ALU设计一、设计

Destiny的博客 4万+

NX二次开发点通过云配准获取相同体

先找到体的参考方向(这个参考方向对于相同体重合之后是相同的),这个时候我们的思路是三个不共线的点确定一个坐标系,然后和绝对方向求转换矩阵。然后获取体的所有边的几何中心,把这些点通过转换矩阵转换之后存起来,再和另外一个体转换之后的点数据作对比,在误差范围内配对点的数量等于体获取点的数量就是相同体

qq_39541524的博客 1645

USACO 2024年1月铜组 CANNONBALL(模拟)

USACO 2024年1月比赛 铜组 CANNONBALL

超哥聊信奥 982

DCMTK编译

dcmtk-3.6.4 使用Unicode?dcmtk的编译选项里没有关于Unicode的选项,OFString的接口里明确使用了OFString(char*)作为构造函数参数,所以,我们可以假设不能够自己擅自在CMakeList.txt里增加一行 add_definitions(-DUNICODE -D_UNICODE) 来强制使用Unicode编码。 亲测:加了之后编译不过 void...

C++ 爱好者 make_it_simple888 1733

2021.08.14【NOIP提高B组】模拟 【USACO 2021 US Open, Gold】United Cows of Farmer John

思路: 维护一个数上一次出现的位置,用树状数组,然后每次累加答案 codecodecode #include<iostream> #include<cstdio> using namespace std; long long n, a[1010000], c[1001000], f[1001000]; long long lowbit(long long x) { return x&(-x); } long long ask(long long x) { l..

ha 400

寻路最终版哦

相信大家用unity3d寻路的时候,一定会碰到多人

yxriyin的专栏 6954

YOLOv11改进策略【独家融合改进】| MobileNetV4+BiFPN,轻松实现降参涨点,适用专栏内所有的骨干替换

可扩展的高效物体检测BiFPN(加权双向特征金字塔网络)

Limiiiing的博客 2360

USACO 1.4.1 Packing Rectangles —— 暴力+ 模拟

Packing Rectangles IOI 95   The six basic layouts of four rectangles Four rectangles are given. Find the smallest enclosing (new) rectangle into which these four may be fitted without overlapping.

XMzhou的专栏 2113

YOLO26全网首发:CVPR2026 MixerCSeg | DEGConv方向引导边缘门控,破解细长裂缝检测难题

DEGConv通过方向先验嵌入、边缘增强卷积和动态门控三大机制,针对性解决了YOLO在处理裂缝类细长、多方向、低对比度目标时的特征提取不足问题,显著提升了裂缝检测的精度与鲁棒性。

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 1034

USACO Section 1.4 题解

这一节开始涉及搜索了,   练练很好,还好以前做过,要不然又要被猥琐到了,不过做这一节也花的时间比前面多很多     ----------------------------------------------------------美丽的分界线--------------

淡泊明志,灵静致远。 625

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

USACO 6.3.1 Fence Rails 01多背包问题(BS+IDDFS)

http://train.usaco.org/usacoprob2?a=NaWWtjt80VA&amp;S=fence8题目大意:有N(1-50)块原木,要切成R(1-1023)块长度(1-128)可重复的木板,并不一定所有的木板都能被切出来,求能够交货的最大木板数量错误想法:我一开始正着想觉得有种网络流的感觉,把每个原木看作一个有限容量的节点,和每个木板结点以无限容量的管道连接,木板结点在和汇点...

Frontier_Setter的博客 730

深度学习工具包 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")

USACO 6.1.1 Postal Vans 特例dp

http://train.usaco.org/usacoprob2?a=iHzQON4VeJX&amp;S=vans题目大意:由4条横线,N条纵线划划分的网络,要求一条路线经过每个网点一次且仅一次,求共有多少条这样的路径想法一:枚举,不可能,其实到第五章之后的题目好像都不太能枚举了想法二:相当于先有一个最外层的大矩形轮廓,然后逐步“下凹”,只要下凹的那一格在当前外表面轮廓组成中只有一条边就不会使最...

Frontier_Setter的博客 548

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

USACO 6.2.1 Calf Flac 马拉车算法(Manacher's Algorithm)

http://train.usaco.org/usacoprob2?a=Hfv8bxVT1Ac&amp;S=calfflac题目大意:一串字符串(不超过200000个字符),求最长回文子串(不考虑非字母字符),并输出这一段(要包含非字母字符,包括换行符)裸的最大回文子串题,直接用马拉车算法可解:※马拉车算法讲解可参考:https://www.cnblogs.com/grandyang/p/4475...

Frontier_Setter的博客 530

【存疑】USACO 6.5.1 All Latin Squares 打表

http://train.usaco.org/usacoprob2?a=gGSgZ020xrV&amp;S=latin题目大意:N*N的矩阵,要求每一行每一列都出现1-N的数字各一次且不重复,第一行必须是1-N递增顺序,求所有可能情况的总数我原本按照Prime那道题的做法,求出了1-N的全排列,再逐行枚举,按照列的重复性剪枝,失败然后我把枚举按照开头数字分类,逐列枚举,还是失败参考资料:http:...

Frontier_Setter的博客 489

USACO 5.4 Character Recognition

Frontier_Setter的博客 483

USACO 6.5.3 Betsy's Tour 搜索剪枝

http://train.usaco.org/usacoprob2?a=BI4LEPNXcEa&amp;S=betsy题目大意:一个N*N的方阵(N&lt;=7),求从左上角出发到左下角结束经过每个格子一次且仅一次的路径总数听说标准的做法是在左侧补两列然后作为等效的哈密顿回路用插头dp的方法求解,但是我实在是看不懂,所以我学了搜索剪枝的方法,没想到过的绰绰有余,搜索真是其乐无穷啊参考资料:http...

Frontier_Setter的博客 477

USACO 6.1.2 A Rectangular Barn 单调栈

http://train.usaco.org/usacoprob2?S=rectbarn&amp;a=iHzQON4VeJX题目大意:一个R*C的方格阵,有P个无效格,求不包含无效格的矩形的最大面积错误想法一:①对每个位置求出离他最近的左侧无效格到他的距离 ②遍历每个格子,向上伸展直到遇到无效格,在这个过程中计算以该长条为边的矩形的面积时间复杂度是N^3的,而且需要一个R*C的数组,在这道题里是3...

Frontier_Setter的博客 476

USACO 6.5.5 Checker Challenge 回溯

http://train.usaco.org/usacoprob2?a=BI4LEPNXcEa&amp;S=checker题目大意:在一个N*N的棋盘上放棋子,要求每一行每一列都有一个,每一个对角线不超过一个(不仅仅主对角线),要求输出前三个答案(每一行的棋子所在的列号)以及摆放方法总数USACO最后一题,再加上题目里宣扬的种种紧张氛围,还给了整整五个提示,我还以为会是一道巨坑,没想到就是简单的回...

Frontier_Setter的博客 462

USACO 5.5.3 Twofive 记忆式搜索+枚举

http://train.usaco.org/usacoprob2?a=qNexyVCSx2z&amp;S=twofive题目大意:给一个5*5的字符方阵(A-Z),阅读顺序为从上到下逐行从左到右念下来,要求每一个位置的字母比它上方与左侧的字母要大。题目有两个要求:1、给一个方阵求它在所有可能的方阵中排第几个(按字典序升序排列)2、给序号,求出方阵1、要枚举的话有25!种情况,肯定不是这么搞的2、...

Frontier_Setter的博客 450

USACO 6.4.2 Electric Fences 三分算法

http://train.usaco.org/usacoprob2?a=gY0nBCREMEt&amp;S=fence3题目大意:用两点坐标形式给出平面内F条线段(平面为(0,0)到(100,100), F小于等于150),求出平面内一点使得从该点连向所有线段的距离最小(可以和线段上任意一点相连)且平面内的各种线可以任意交叉解题思路:一开始查到了模拟退火的解法,吓了我一跳,后来查到了这个亲民的解法...

Frontier_Setter的博客 445

USACO 6.5.4 The Clocks BFS

http://train.usaco.org/usacoprob2?a=BI4LEPNXcEa&amp;S=clocks题目大意:给九个钟的初始状态,指针只可能指向3,6,9,12,有九种操作,每种操作拨动一个固定组合的种顺时针45°,求最少操作能够把所有钟拨到12的情况(操作数相同时,要操作的数字小),按顺序输出一开始觉得每次有九种选择的可能性,又要输出操作数最少的情况,就想到了用IDDFS,但...

Frontier_Setter的博客 418

USACO 6.3.3 Cowcycles 暴力

http://train.usaco.org/usacoprob2?a=lQZ5UB8ZNRK&amp;S=cowcycle题目大意:选出两组齿轮(数量分别不超过5个和10个),设前后轮齿数比为传动比,要求:1、最大传动比至少要是最小传动比的三倍    2、将传动比排序后相邻两者差(difference)的方差要最小USACO总是出人意料,我原本以为会是一道超难的数学题或者构造题,再不济也得有个很...

Frontier_Setter的博客 396
上一篇: USACO 6.2.1 Calf Flac 马拉车算法(Manacher's Algorithm)
下一篇: USACO 6.2.3 Shaping Regions
Frontier_Setter
博客等级 码龄10年 2粉丝 123原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值