九度OJ 1082 代理服务器 -- 贪心算法

C++一本通题库1001 Hello,World! 时间限制: 1000 ms         内存限制: 65536 KB 提交数: 4025     通过数: 1737  【题目描述】 编写一个能够输出“Hello,World!”的程序,这个程序常常作为一个初学者接触一门新的编程语言所写的第一个程序,也经常用来测试开发、编译环境是否能够正常工作。 【输入】 无 【输出】 Hello,Worl 阅读详情

题目地址:http://ac.jobdu.com/problem.php?pid=1082

题目描述:

    使用代理服务器能够在一定程度上隐藏客户端信息,从而保护用户在互联网上的隐私。我们知道n个代理服务器的IP地址,现在要用它们去访问m个服务器。这 m 个服务器的 IP 地址和访问顺序也已经给出。系统在同一时刻只能使用一个代理服务器,并要求不能用代理服务器去访问和它 IP地址相同的服务器(不然客户端信息很有可能就会被泄露)。在这样的条件下,找到一种使用代理服务器的方案,使得代理服务器切换的次数尽可能得少。

输入:

    每个测试数据包括 n + m + 2 行。
    第 1 行只包含一个整数 n,表示代理服务器的个数。
    第 2行至第n + 1行每行是一个字符串,表示代理服务器的 IP地址。这n个 IP地址两两不相同。
    第 n + 2 行只包含一个整数 m,表示要访问的服务器的个数。
    第 n + 3 行至第 n + m + 2 行每行是一个字符串,表示要访问的服务器的 IP 地址,按照访问的顺序给出。
    每个字符串都是合法的IP地址,形式为“xxx.yyy.zzz.www”,其中任何一部分均是0–255之间的整数。输入数据的任何一行都不包含空格字符。

     其中,1<=n<=1000,1<=m<=5000。

输出:

    可能有多组测试数据,对于每组输入数据, 输出数据只有一行,包含一个整数s,表示按照要求访问服务器的过程中切换代理服务器的最少次数。第一次使用的代理服务器不计入切换次数中。若没有符合要求的安排方式,则输出-1。

样例输入:
3
166.111.4.100
162.105.131.113
202.112.128.69
6
72.14.235.104
166.111.4.100
207.46.19.190
202.112.128.69
162.105.131.113
118.214.226.52
样例输出:
1
#include <stdio.h>
#include <string.h>
 
int main(void){
    int m, n;
    char server[5000][16];
    char agency[1000][16];
    int i;
    int result, max, index, flag, start;
 
    while (scanf ("%d", &n) != EOF){
        for (i=0; i<n; ++i)
            scanf ("%s", agency[i]);
        scanf ("%d", &m);
        for (i=0; i<m; ++i)
            scanf ("%s", server[i]);
        if (n == 1){
            for (i=0; i<m && (strcmp (agency[0], server[i])!=0); ++i)
                continue;
            if (i < m) printf ("-1\n");
            else printf ("0\n");
        }
        else{
            flag = 1;
            result = start = 0;
            while (flag){
                max = -1;
                flag = 0;
                for (i=0; i<n; ++i){
                    index = start;
                    while (index < m && (strcmp (agency[i], server[index]) != 0))
                        ++index;
                    if (index > max)
                        max = index;
                }
                if (max != m){
                    flag = 1;
                    ++result;
                }
                start = max+1;
            }
            printf ("%d\n", result);
        }
    }
    return 0;
}


华为OD机考双机位C卷 - 斗地主之顺子 (Java & Python& JS & C/C++ & GO ) 华为OD机考双机位C卷 - 斗地主之顺子(OD上机考试双机位C卷)。提供在线OJ刷题。Java、C++、Python、GO语言、C语言、JavaScript题解,并提供完整思路讲解。 阅读详情

相关推荐

PC微信逆向) 读取内存联系人链表

首先从一些网络上搜索到的信息可以得出联系人列表是保存在内存里的,并且是全局变量不会被释放,所以我们可以通过搜索某个联系人的信息来定位

Qwertyuiop2016的博客 2919

代理服务器

代理服务器的基本行为就是接收客户端发送的请求后转发给其他服务器。代理不改变请求 URI,会直接发送给前方持有资源的目标服务器。 持有资源实体的服务器被称为源服务器。从源服务器返回的响应经过代理服务器后再传给客户端。 在 HTTP 通信过程中,可级联多台代理服务器。请求和响应的转发会经过数台类似锁链一样连接起来的代理服务器。转发时,需要附加Via 首部字段以标记出经过的主机信息。 使用代理服务器的理由 利用缓存技术(稍后讲解)减少网络带宽的流量,组织内部针对特定网站的访问控制,以获取访问日志为主要目的,.

xinbaiyu的博客 2296

糖尿病预测(深度学习pytorch实现-最新)

本次做的项目是糖尿病的预测,也是来自kaggle上面的一个小项目。根据一个人的怀孕次数、血糖、血压、皮肤厚度、胰岛素指标、身体质量指数、糖尿病谱系指数、年龄等身体参数来预测一个人是否患有糖尿病。

NangoGreen的博客 5358

贪心算法_题目1082:代理服务器

时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:910 解决:272 题目描述:     使用代理服务器能够在一定程度上隐藏客户端信息,从而保护用户在互联网上的隐私。我们知道n个代理服务器的IP地址,现在要用它们去访问m个服务器。这 m 个服务器的 IP 地址和访问顺序也已经给出。系统在同一时刻只能使用一个代理服务器,并要求不能用代理服务器

Denallo的专栏 3949

持续集成介绍及Jenkins自动化测试部署

学习持续集成及jenkins的自动化测试部署

ouihsiad的博客 4576

AI人工智能领域多模态大模型的数字孪生应用

本文旨在系统性地介绍多模态大模型在数字孪生领域的最新应用进展,探讨其技术原理、实现方法和应用价值。内容范围涵盖从基础概念到前沿技术,从理论分析到实践案例。文章首先介绍多模态大模型和数字孪生的基本概念,然后深入分析两者的结合点,接着通过具体案例展示应用实践,最后探讨未来发展趋势和挑战。多模态大模型:能够同时处理和融合多种数据模态(如文本、图像、视频、音频等)的大型人工智能模型数字孪生:物理实体或系统的虚拟副本,通过实时数据同步实现虚实交互跨模态融合:将不同数据模态的信息进行有效整合和关联的技术。

AI云原生与云计算技术学院 1325

代理服务器详解(proxy server)

代理服务器(Proxy Server)是一个中间服务器,位于客户端和目标服务器之间。客户端请求:客户端(如浏览器)向代理服务器发送请求,例如请求访问一个网站。请求转发:代理服务器接收到客户端的请求后,会将该请求转发给目标服务器。目标服务器响应:目标服务器处理请求并将响应数据发送回代理服务器。响应转发:代理服务器接收到目标服务器的响应后,将其转发回客户端。代理服务器在提供隐私保护、内容过滤、性能优化和负载均衡等方面具有显著优势,但也存在单点故障、性能瓶颈、配置复杂性和隐私安全风险等缺点。

三两肉的博客 1万+

摩尔线程GPU实战:5分钟搞定AI模型部署(含Docker避坑指南)

本文详细介绍了摩尔线程GPU在AI模型部署中的实战应用,包括环境配置、Docker避坑指南及性能优化技巧。通过5分钟快速部署指南,帮助开发者高效利用摩尔线程GPU进行AI模型推理,特别针对常见兼容性问题提供解决方案,显著提升部署效率。

weixin_28736335的博客 454

P1610 鸿山洞的灯(贪心算法)C++

P1610 鸿山洞的灯 第一盏和最后一盏等必须亮着,所以不找。 我们使用递推优化。其本质是关灯时把前一盏灯移到当前这一盏灯的位置上,防止下次计算时寻找前一盏灯。有类似链表删除的作用。 #include<bits/stdc++.h> using namespace std; int n,dist,a[100002],sum; int main() { cin>>n>>dist; for(int i=1; i<=n; i++) cin>>a[i];

深巷 546

【WB32库开发】第9章 TIM1高级定时器——输出多路PWM

PWM(Pulse Width Modulation)意为脉冲宽度调制,简称脉宽调制 。在工控行业,PWM信号可以用来调节电机转速、调节变频器以及BLDC电机驱动等;在LED照明行业,可以通过PWM来控制LED的亮暗变化;还可以通过PWM信号来控制无源蜂鸣器发出简单的声音等。 WB32也可输出PWM,需配置WB32上的定时器。 在WB32中有4个定时器,其中TIM1为高级定时器,TIMx(2-4)为通用定时器,这四个定时器均挂载在APB1总线上,每个定时器都可以输出4路PWM。 本章需要使用固件库TIM例程

北海村夫的博客 4637

【1】Java 部分笔试题解析

解析A.abstract关键字应该放在class关键字之前。C.抽象方法不能有方法体。D缺少了class关键字。

博客 3941

【学相伴】Nginx最新教程通俗易懂-狂神说

Nginx - 学相伴 分享人:秦疆(遇见狂神说) 公司产品出现瓶颈? 我们公司项目刚刚上线的时候,并发量小,用户使用的少,所以在低并发的情况下,一个jar包启动应用就够了,然后内部tomcat返回内容给用户。 但是慢慢的,使用我们平台的用户越来越多了,并发量慢慢增大了,这时候一台服务器满足不了我们的需求了。 于是我们横向扩展,又增加了服务器。这个时候几个项目启动在不同的服务器上,用户要访问,就需要增加一个代理服务器了,通过代理服务器来帮我们转发和处理请求。 我们希望这个代理服务器可以帮助我们接

狂神说 1万+

SWC_RTE01-AutoSAR架构【AutoSAR架构设计概述】

1 基于AutoSAR架构的概述 1.1架构层面:功能可以细分子功能,各个子功能需要交互。 -大功能可以通过Autosar组件Composition去表示; -各个子功能一般具有不可分割性,可以通过Autosar原子组件Component去表示; -各个子功能的交互可以通过接口去通信和交互; -各个子功能的行为可以通过内部行为去表示;具体表现为Runnable的设计;架构设计的时候不考虑具体的逻辑实现;只会关注Ruannble的触发事件或周期;数据访问的一致性问题;具体逻辑设计可通过模版c文件实现或通过基于

8451

九度 oj 题目1082:代理服务器

http://ac.jobdu.com/problem.php?pid=1082 因为每个proxy都可以用多次,所以使用贪心算法,局部最优迭代得到全局最优。  #include #include int main(){ //freopen("in/1082.in","r",stdin); char proxy[1002][16]; char

guojiaqi007的专栏 445

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

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

九度OJ 题目1082:代理服务器

清华大学2009年机试题目: 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1516 解决:443 题目描述:     使用代理服务器能够在一定程度上隐藏客户端信息,从而保护用户在互联网上的隐私。我们知道n个代理服务器的IP地址,现在要用它们去访问m个服务器。这 m 个服务器的 IP 地址和访问顺序也已经给出。系统在同一时刻只能使用一个

alice707的专栏 1219

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

九度OJ 1082:代理服务器 (DP)

时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1871 解决:574 题目描述:     使用代理服务器能够在一定程度上隐藏客户端信息,从而保护用户在互联网上的隐私。我们知道n个代理服务器的IP地址,现在要用它们去访问m个服务器。这 m 个服务器的 IP 地址和访问顺序也已经给出。系统在同一时刻只能使用一个代理服务器,并要求不能用代理服务器去

梁山伯的专栏 522

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

九度Oj题解

一、动态规划专题 1205 N阶楼梯上楼问题 dp[i]表示到达i阶的方法数,状态转移方程:dp[i] = dp[i-1]+dp[i-2],值很大要用long long. 1451 不容易系列之一 dp[i]表示总共i个数时的错排方案数,状态转移方程:dp[i] = (i - 1) * dp[i-1] + (i - 2) * dp[i-2]; 1420 Jobdu MM分水果 01背包变形。

314

九度oj 代理服务器

九度oj 代理服务器

My block 407

使用 nginx 搭建代理服务器(正向代理 https 网站)指南

使用 nginx 搭建代理服务器(正向代理 https 网站)指南

墨鸦的博客 3万+

数字游戏

点击打开链接   数字游戏 Time Limit: 1000MS    Memory limit: 65536K 题目描述         在现实生活中,我们常常会面对数字,而当给定一系列数字的时候,将他们采用不同的顺序排列在一起,是会找到一个最大值的,比如 数字13 和数字 81 ,他们两个和在一起形成的最大值是8113. 输入       输入一个整数n(n 输出

代码改变世界,keep coding。 1162

详解代理服务器及Squid

代理服务器英文全称为ProxyServer,其主要功能代理网络用户获取网络信息,起到内网和Internet的桥梁作用。代理服务器得到广泛的应用,它的作用主要表现在:、共享 网络、提高访问速度、防止攻击、起到防火墙的作用。

zhangxueyi的专栏 1289

代理服务器的主要功能

5. 节省IP开销:代理服务器允许使用大量的伪IP地址,节约网上资源,即用代理服务器可以减少对IP地址的需求,对于使用局域网方式接入Internet ,如果为局域网(LAN)内的每一个用户都申请一个IP地址,其费用可想而知。通常代理服务器都设置一个较大的硬盘缓冲区(可能高达几个GB或更大),当有外界的信息通过时,同时也将其保存到缓冲区中,当其他用户再访问相同的信息时,则直接由缓冲区中取出信息,传给用户,以提高访问速度。同时可以设置IP地址过滤,限制内部网对外部的访问权限。6. 监控和限制用户的上网行为。

weixin_73134956的博客 610
上一篇: 九度OJ 1081 递推数列 -- 矩阵二分乘法
下一篇: 九度OJ 1433 FatMouse -- 贪心算法
JDPlus
博客等级 码龄15年 221粉丝 125原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值