marathon如何使用JSON脚本启动docker容器实现docker run -u

marathon如何使用JSON脚本启动docker容器实现docker run -u

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
mesos和marathon搭配使用,marathon无法启动

下面是版本信息: mesos version : mesos-0.25.0-0.2.70.centos701406.x86_64 marathon version : marathon-0.11.1-1.0.432.el7.x86_64 chronos version : chronos-2.4.0-0.1.20151007110204.el7.x86_64 zookeeper version: mesosphere-zookeeper-3.4.6-0.1.20141204175332.centos7.x86_64 我通过下面命令在 Centos7上装了mesos,zookeeper,marathon等. sudo rpm -Uvh http://repos.mesosphere.io/el/7/noarch/RPMS/mesosphere-el-repo-7-1.noarch.rpm sudo yum install mesos marathon chronos mesosphere-zookeeper 我配置了2个master, ip分别是192.168.253.129 and 192.168.253.130.我也在 [/etc/marathon/conf]目录下创建了master,zk,hostname文件.下面是这3个文件的详情 1.master>>zk://192.168.253.129:2181,192.168.253.130:2181/mesos 2.zk>>zk://192.168.253.129:2181,192.168.253.130:2181/marathon 3.hostname>>192.168.253.129 启动mesoso-master服务之后,我可以访问 url [http://192.168.253.129:5050] and http://192.168.253.130:5050,并且看到leader master被成功选举出来. 但是却无法打开marathon的url[http://192.168.253.129:8080]。 下面是我 [service marathon status -l] 我查看marathon的状态 +++++++++++++++++++++++++++++++++++++++++++++++++++++#localhost]# service marathon status -l Redirecting to /bin/systemctl status -l marathon.service marathon.service - Marathon Loaded: loaded (/usr/lib/systemd/system/marathon.service; enabled) Active: activating (auto-restart) (Result: exit-code) since Sun 2015-10-25 03:03:44 PDT; 1s ago Process: 6777 ExecStart=/usr/bin/marathon (code=exited, status=1/FAILURE) Main PID: 6777 (code=exited, status=1/FAILURE) Oct 25 03:03:44 develop-mesos-master1 #localhost.localdomain systemd[1]: marathon.service: main process exited, code=exited, status=1/FAILURE Oct 25 03:03:44 develop-mesos-master1 #localhost.localdomain systemd[1]: Unit marathon.service entered failed state. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 下面是我用命令 [journalctl -o verbose _PID=6777] 查看marathon进程的详细信息。 +++++++++++++++++++++++++++++++++++++++++++++++++++++ #localhost conf]# journalctl -o verbose _PID=6777 -- Logs begin at Sun 2015-10-25 02:48:41 PDT, end at Sun 2015-10-25 03:18:55 PDT. -- Sun 2015-10-25 03:03:44.168930 PDT [s=5827ad02b7164cdeb1947da2c9a80cc6;i=208c;b=8cdffcc7c1c849b887266e94d8cbe621;m=36175ff3;t=522eaf5bed3e2; PRIORITY=6 _UID=0 _GID=0 _SYSTEMD_SLICE=system.slice _BOOT_ID=8cdffcc7c1c849b887266e94d8cbe621 _MACHINE_ID=e485efeafe934ce99407be78a4ed3aac SYSLOG_FACILITY=3 _CAP_EFFECTIVE=1fffffffff _TRANSPORT=stdout _EXE=/usr/bin/bash _HOSTNAME=develop-mesos-master1 #localhost.localdomain SYSLOG_IDENTIFIER=marathon MESSAGE=run_jar --master zk://192.168.253.129:2181,192.168.253.130:2181/mesos --zk zk://192.168.253.129:2181,192.168.253.130:2181/marath _COMM=marathon _CMDLINE=/bin/bash /usr/bin/marathon _SYSTEMD_CGROUP=/system.slice/marathon.service _SYSTEMD_UNIT=marathon.service _PID=6777 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 有高手能给解答一下吗?

无法使用docker查看STDERR输出

<div class="post-text" itemprop="text"> <p>I'm running a php docker image (php:5.6-apache) which has apache's error and access logs redirected to STDERR and STDOUT respectively using symbolic links.</p> <p>When I run the docker image in the foreground or access the docker container logs, I can see the STDOUT output. But I don't see any errors (even when I generate php errors).</p> <p>Any idea why that is and how I can fix it?</p> <p>I'm running docker for Mac (but I don't think this makes any difference)</p> <p>Thanks</p> <pre><code>access.log -&gt; /dev/stdout error.log -&gt; /dev/stderr other_vhosts_access.log -&gt; /dev/stdout </code></pre> <p><strong>Edit / Solved:</strong> As @BMitch mentions and proves below, the STDERR redirection works fine. The problem was with PHP configuration. If I logged an error with <code>error_log()</code>, it would get output to the log. But if I had a php error, like calling an undefined function, the error would never appear in the log. This seems a little inconsistent. In any case, ...</p> <p>I had to create a <code>php.ini</code> file in <code>/usr/local/etc/php/</code> and add these two parameters:</p> <pre><code>log_errors = On error_log = /var/log/apache2/error.log </code></pre> <p>and then restart the docker container. This caused all PHP errors to be logged and output to STDERR. See @German's answer for an example.</p> </div>

mesos slave failed to create a docker container

when i start a docker containner on mesos-slave the mesos-slave log shows that: ``` I1223 15:38:40.822557 258486272 docker.cpp:761] Starting container 'ea1ed2fa-c2e3-469a-bcc4-142e0a6c624d' for task '2-1.2fb839ea-a948-11e5-9c42-2e7bf2aa25a6' (and executor '2-1.2fb839ea-a948-11e5-9c42-2e7bf2aa25a6') of framework '13165a00-8e58-4d80-b84d-fe4652022a3e-0000' E1223 15:38:41.219044 254730240 slave.cpp:3342] Container 'ea1ed2fa-c2e3-469a-bcc4-142e0a6c624d' for executor '2-1.2fb839ea-a948-11e5-9c42-2e7bf2aa25a6' of framework '13165a00-8e58-4d80-b84d-fe4652022a3e-0000' failed to start: Failed to 'docker -H unix:///var/run/docker.sock pull python:3': exit status = exited with status 1 stderr = An error occurred trying to connect: Post https:///var/run/docker.sock/v1.19/images/create?fromImage=python%3A3: dial unix /var/run/docker.sock: no such file or directory ``` from that, i can see mesos-slave excute docker -H unix:///var/run/docker.sock pull python:3 to download images. but I use Mac OSX, And the docker is running in the vm , So there is no docker.sock file in my slave but the vm. How cuold i solve the issue on Mac OSX? please help me ,thanks!

apache marathon项目执行shell的相对路径是如何实现的

在marathon项目中,上传的app如下图, 效果就是,先在本地下载一个war包,和tomcat的压缩包,在解压压缩包,然后将war包放到tomcat/webapp目录下,再将端口号改成8001,最后再启动tomcat ![图片说明](https://img-ask.csdn.net/upload/201507/02/1435829537_98604.png) 对此,我有一些疑问,请教一下大家, ![图片说明](https://img-ask.csdn.net/upload/201507/02/1435829673_783364.png) 如上图, job开始running后,marathon将需要的file都下载到了当前task的log的存放地址下,但是我新增app的时候输入的conmand,并没有 cd 到 log的路径,所以应该是marathon在后台,默认给command添加了 cd log_dir的shell , 但是 在进入 mesos 的 localhost:5050查看该job 执行的 shell,结果如下 ![图片说明](https://img-ask.csdn.net/upload/201507/02/1435836230_124190.png) 并没有我想象中的$cd log_dir, 请问marathon的相对路径是如何实现的呢?

使用Marathon / Mesos进行Prometheus动态端口服务发现

<div class="post-text" itemprop="text"> <p>I've been unable to find an answer to this after days of Googling. I have a service running in Marathon/Mesos. I have a Prometheus cluster scraping metrics. My Marathon metrics port config looks like this:</p> <pre><code>{ "containerPort": 8081, "hostPort": 0, "servicePort": 31301, "protocol": "tcp", "labels": { "metrics": "/metrics" } } </code></pre> <p>Prometheus, configured with just a boilerplate marathon-sd config, successfully finds this target, but it then listens for metrics on: <code>__address__ = [NodeIP]:31301</code>; so it's listening on the host's IP with the service port, rather than the dynamically assigned host port, while the service port only matters for Marathon-LB. </p> <p>I know that Marathon defines the environment variable <code>$PORT0</code> in the container to be the host port, however I can't figure out how to access this from the Prometheus SD config, nor how to access other fields dynamically configured by Marathon like <code>Endpoints</code>. Does anyone have any suggestions? I can't/don't want to assign a static <code>hostPort</code> because I have more containers than there are physical nodes in the cluster, as is sort of the point with container orchestration. </p> </div>

marathon,codis invalid xauth

在ubuntu下载marathon,部署codis,通过json文件启动dashboard服务,然后启动codis-fe,在页面创建group等操作时,都会提示“invalid xauth”错误,用f12查看时,显示,status code 800,这是什么原因,请指教

marathon注册mesos如何配置role

如题,mesos上运行marathon,如何配置marathon的role,尝试过在/etc/marathon/ conf/下写mesos_role文件,但是没有成功

如何在Go中解析以下JSON结构

<div class="post-text" itemprop="text"> <p>In Go, how can I parse the following JSON? I know to use <code>struct</code> to parse, but the keys are different for each entry, also they are not fixed, they can be more or less. </p> <pre><code>{ "consul": [], "docker": [], "etcd": ["etcd"], "kubernetes": ["secure"], "mantl-api": [], "marathon": ["marathon"], "mesos": ["agent", "follower", "leader", "master"], "mesos-consul": [], "zookeeper": ["mantl"] } </code></pre> <p>Thanks for help! </p> </div>

Changsha Marathon

Problem Description   Changsha is a beautiful city surrounded by mountains and rivers, forming a charming scenery. There are many tourist attractions in Changsha: Yuelu Academy, the predecessor of Hunan University, which is one of the four most famous academies in China. It was established in 976A.D. in Northern Song Dynasty. Juzizhou Island (Orange Isle) is the world's longest inland river isle which lies in Xiangjiang River and it is famous for the famous poet Qinyuanchun-Changsha written by Chairman Mao. Mawangdui is a famous archaeological site that contains the tombs of three people from the Western Han Dynasty. The tomb of Xin Zhui is best preserved among the three with a complete cosmetic set, lacquered pieces and finely woven silk garments. Huogongdian represents the Huxiang culture and Chuwu culture, Hunan’s geography culture and Hunan’s distinctive food culture. Tourists can have a taste of typical Hunan cuisine in it.   Every year the city holds a marathon. When planning the route, the organizers wish to go pass some tourist attractions to make it more enjoyable to attract more athletes and audience. Changsha can be treated as a graph consisted of N intersections and many bidirectional roads. A road connects two intersections i and j with length Wi,j. However, to reduce the impact to the daily traffic, only N-1 roads specified by the local government which can connect all N intersections are allowed to be used as the route. And the intersections with only one adjacent intersection are on the west bank of Xiangjiang River and there are ferries only at these intersections. The marathon starts at the intersection called Red East Square (marked as S) in Hunan University by convention. The organizers do not want the route pass any road twice, so the marathon has to be separated into two sections, the first section and the second section. Two different points have to be selected from intersections on the bank to act as the half end point S1 and the half starting point S2. The first section starts from S and end in S1. The second section starts from S2 and end in S. The organizer will use ferryboats to transport athletes from S1 to S2 as required by the government.   Considering the safety, some supply points are to be set on some intersections on each half section and there must be a supply point set on S, S1 and S2. According to scientific research, the most suitable distance between two adjacent supply points is L and the organizers want to minimize the evaluation of the route. For each section, the evaluation from the starting point to rest point i is marked as Ei, and where j is the previous supply point on the route,  means the sum of the roads’ length on the route from intersection j to i. The evaluation of the starting point is zero. The evaluation of a section equals to the evaluation from its starting point to end point.   Your task is to select S1, S2, and the supply points to minimize the total evaluation of both sections. Input   There are multiple test cases.   For each test case the first line contains two integers, N, L. (1<=N<=20000, 1<=L<=109)   The next N-1 lines with 3 integers, U, V, W, describes that a bidirectional road connects intersection U and V with distance W. (1<=U, V<=N, 1<=W<=103) Red East Square (S) is always numbered 1. The input will finish with the end of file. Output   For each case the output contains only one line, the evaluation of the best plan rounded to the second digit after the decimal point. If there is no solution, output -1. Sample Input 7 4 1 2 2 1 3 7 1 4 3 2 5 6 2 6 5 3 7 8 Sample Output 7.00

Changsha Marathon 马拉松问题

Problem Description   Changsha is a beautiful city surrounded by mountains and rivers, forming a charming scenery. There are many tourist attractions in Changsha: Yuelu Academy, the predecessor of Hunan University, which is one of the four most famous academies in China. It was established in 976A.D. in Northern Song Dynasty. Juzizhou Island (Orange Isle) is the world's longest inland river isle which lies in Xiangjiang River and it is famous for the famous poet Qinyuanchun-Changsha written by Chairman Mao. Mawangdui is a famous archaeological site that contains the tombs of three people from the Western Han Dynasty. The tomb of Xin Zhui is best preserved among the three with a complete cosmetic set, lacquered pieces and finely woven silk garments. Huogongdian represents the Huxiang culture and Chuwu culture, Hunan’s geography culture and Hunan’s distinctive food culture. Tourists can have a taste of typical Hunan cuisine in it.   Every year the city holds a marathon. When planning the route, the organizers wish to go pass some tourist attractions to make it more enjoyable to attract more athletes and audience. Changsha can be treated as a graph consisted of N intersections and many bidirectional roads. A road connects two intersections i and j with length Wi,j. However, to reduce the impact to the daily traffic, only N-1 roads specified by the local government which can connect all N intersections are allowed to be used as the route. And the intersections with only one adjacent intersection are on the west bank of Xiangjiang River and there are ferries only at these intersections. The marathon starts at the intersection called Red East Square (marked as S) in Hunan University by convention. The organizers do not want the route pass any road twice, so the marathon has to be separated into two sections, the first section and the second section. Two different points have to be selected from intersections on the bank to act as the half end point S1 and the half starting point S2. The first section starts from S and end in S1. The second section starts from S2 and end in S. The organizer will use ferryboats to transport athletes from S1 to S2 as required by the government.   Considering the safety, some supply points are to be set on some intersections on each half section and there must be a supply point set on S, S1 and S2. According to scientific research, the most suitable distance between two adjacent supply points is L and the organizers want to minimize the evaluation of the route. For each section, the evaluation from the starting point to rest point i is marked as Ei, and where j is the previous supply point on the route,  means the sum of the roads’ length on the route from intersection j to i. The evaluation of the starting point is zero. The evaluation of a section equals to the evaluation from its starting point to end point.   Your task is to select S1, S2, and the supply points to minimize the total evaluation of both sections. Input   There are multiple test cases.   For each test case the first line contains two integers, N, L. (1<=N<=20000, 1<=L<=109)   The next N-1 lines with 3 integers, U, V, W, describes that a bidirectional road connects intersection U and V with distance W. (1<=U, V<=N, 1<=W<=103) Red East Square (S) is always numbered 1. The input will finish with the end of file. Output   For each case the output contains only one line, the evaluation of the best plan rounded to the second digit after the decimal point. If there is no solution, output -1. Sample Input 7 4 1 2 2 1 3 7 1 4 3 2 5 6 2 6 5 3 7 8 Sample Output 7.00

使用boltdb后端启动traefik时出现恐慌

<div class="post-text" itemprop="text"> <p>I'm trying to start traefik with the boltdb backend. Sadly I always get a panic. Following my setup and the terminal output.</p> <h3>Start Command</h3> <pre><code>./traefik_darwin-amd64 -d -c config.toml </code></pre> <h3>config.toml</h3> <pre><code>debug = true defaultEntryPoints = ["http"] [entryPoints] [entryPoints.http] address = ":8081" [web] address = ":8082" [boltdb] endpoint = "/Users/tochti/Tmp/traefik.db" watch = true prefix = "/traefik" </code></pre> <h3>Terminal Output</h3> <p>After a long time of waiting the following panic is displayed</p> <p><a href="https://pastebin.com/1vUXbgTU" rel="nofollow noreferrer">https://pastebin.com/1vUXbgTU</a></p> <h3>Output of <code>traefik version</code>: (<em>What version of Traefik are you using?</em>)</h3> <pre><code>Version: v1.3.1 Codename: raclette Go version: go1.8.3 Built: 2017-06-16_11:00:34AM OS/Arch: darwin/amd64 </code></pre> <h3>What is your environment &amp; configuration (arguments, toml, provider, platform, ...)?</h3> <pre><code>{ "GraceTimeOut": 10000000000, "Debug": true, "CheckNewVersion": true, "AccessLogsFile": "", "TraefikLogsFile": "", "LogLevel": "ERROR", "EntryPoints": { "http": { "Network": "", "Address": ":8081", "TLS": null, "Redirect": null, "Auth": null, "Compress": false } }, "Cluster": null, "Constraints": [], "ACME": null, "DefaultEntryPoints": [ "http" ], "ProvidersThrottleDuration": 2000000000, "MaxIdleConnsPerHost": 200, "IdleTimeout": 180000000000, "InsecureSkipVerify": false, "Retry": null, "HealthCheck": { "Interval": 30000000000 }, "Docker": null, "File": null, "Web": { "Address": ":8082", "CertFile": "", "KeyFile": "", "ReadOnly": false, "Statistics": null, "Metrics": null, "Path": "", "Auth": null }, "Marathon": null, "Consul": null, "ConsulCatalog": null, "Etcd": null, "Zookeeper": null, "Boltdb": { "Watch": true, "Filename": "", "Constraints": [], "Endpoint": "/Users/tochti/Tmp/traefik.db", "Prefix": "/traefik", "TLS": null, "Username": "", "Password": "" }, "Kubernetes": null, "Mesos": null, "Eureka": null, "ECS": null, "Rancher": null, "DynamoDB": null, "ConfigFile": "/Users/tochti/Tmp/traefik_test/config.toml" } </code></pre> <h3>Bolt "traefik" Bucket Items</h3> <pre><code>/traefik/backends/srv1_example_com/servers/server_1/url http://127.0.0.1:32001 /traefik/frontends/srv1_example_com/backend srv1_example_com /traefik/frontends/srv1_example_com/routes/test_1/rule Host:srv1.example.com </code></pre> <p>Thanks for help!</p> </div>

mesos master报错:Processing DECLINE call for offers?

MESOS master报错: ``` master.cpp:9445] Sending offers [ ce2fd812-b02c-473a-977f-c868e23b6367-O38, ce2fd812-b02c-473a-977f-c868e23b6367-O39 ] to framework cc289df0-a5be-43dd-98e5-798411f81915-0000 (marathon) at scheduler-0e550772-c11c-4dab-aa70-d51d62b534b0@172.17.0.3:46822 master.cpp:5837] Processing DECLINE call for offers: [ ce2fd812-b02c-473a-977f-c868e23b6367-O38 ] for framework cc289df0-a5be-43dd-98e5-798411f81915-0000 (marathon) at scheduler-0e550772-c11c-4dab-aa70-d51d62b534b0@172.17.0.3:46822 master.cpp:11439] Removing offer ce2fd812-b02c-473a-977f-c868e23b6367-O38 master.cpp:5837] Processing DECLINE call for offers: [ ce2fd812-b02c-473a-977f-c868e23b6367-O39 ] for framework cc289df0-a5be-43dd-98e5-798411f81915-0000 (marathon) at scheduler-0e550772-c11c-4dab-aa70-d51d62b534b0@172.17.0.3:46822 master.cpp:11439] Removing offer ce2fd812-b02c-473a-977f-c868e23b6367-O39 ``` Marathon报错: ``` [2018-12-29 08:49:28,394] INFO Processing offer: offerId ce2fd812-b02c-473a-977f-c868e23b6367-O38, agentId ce2fd812-b02c-473a-977f-c868e23b6367-S0 (mesosphere.marathon.core.launcher.impl.OfferProcessorImpl:Thread-172) [2018-12-29 08:49:28,395] INFO Processing offer: offerId ce2fd812-b02c-473a-977f-c868e23b6367-O39, agentId ce2fd812-b02c-473a-977f-c868e23b6367-S1 (mesosphere.marathon.core.launcher.impl.OfferProcessorImpl:Thread-172) [2018-12-29 08:49:28,395] INFO No match for:ce2fd812-b02c-473a-977f-c868e23b6367-O38 from:173.0.20.106 reason:No offers wanted (mesosphere.marathon.core.matcher.manager.impl.OfferMatcherManagerActor:marathon-akka.actor.default-dispatcher-20) [2018-12-29 08:49:28,395] INFO No match for:ce2fd812-b02c-473a-977f-c868e23b6367-O39 from:173.0.20.105 reason:No offers wanted (mesosphere.marathon.core.matcher.manager.impl.OfferMatcherManagerActor:marathon-akka.actor.default-dispatcher-20) ```

如何将mesos修改为https方式访问?

我是使用docker+marathon+mesos+zookeeper的框架 ,由于公司需求将marathon修改为了https访问方式,但是会出现marathon与mesos 交互时出现错误,所以需要将mesos也修改为https访问方式,我在mesos官网上看见有对ssl的支持,就是添加三个环境变量,但我按它的办法做了后并没有生效,请问有懂这方面的道友知道如何解决吗?

配置文件掩码

<div class="post-text" itemprop="text"> <p>We deploy services as docker containers using Marathon. The containers include a base config file, Marathon pulls an environment config file (which has a subset of the base keys) at deployment time so when the app starts it has;</p> <ul> <li>environment.toml</li> <li>config.toml</li> </ul> <p>when reading the config we need to conflate the values in both files to a single set, effectively masking/shadowing the values present in both files with those in the environment file.</p> <p>I didn't find this functionality in the Viper docs. Unless I have missed something it seems my options are;</p> <ul> <li>Write a package that uses Viper to read both files and perform the conflation.</li> <li>Extend Viper</li> </ul> <p>Before I start writing code, is there already a mechanism for doing this?</p> </div>

输出可能的领先的选手数量的算法,怎么使用C语言的程序编写的过程的方式去实现的程序编写

Problem Description Since members of Wuhan University ACM Team are lack of exercise, they plan to participate in a ten-thousand-people Marathon. It is common that the athletes run very fast at first but slow down later on. Start from this moment, we can assume that everyone is moving forward in a constant speed. ACMers love algorithms, so they want to know not only the result but also who may be in the leading position. Now we know all athletes' position and speed at a specific moment. The problem is, starting from this moment, how many athletes may be the leader. Please notice that there's no leader if two or more athletes are at the leading position at the same time. No two athletes may have the same speed. Input The input consists of several test cases. The first line of input consists of an integer T, indicating the number of test cases. The first line of each test case consists of an integer N, indicating the number of athletes. Each of the following N lines consists of two integers: p, v, indicating an athlete's position and speed. Technical Specification 1. T ≤ 20 2. 0 < N ≤ 50000 3. 0 < p, v ≤ 2000,000,000 4. An athlete's position is the distant between him/her and the start line. 5. The Marathon is so long that you can assume there's no finishline. Output For each test case, output the number of possible leaders on a separate line. Sample Input 1 3 1 1 2 3 3 2 Sample Output 2

Convert Kilometers to Miles 单位的转换的问题的实现

Problem Description This year, Bruce Force spends his vacation in Flagstaff, Arizona, where he wants to practice for his next half marathon (a race over 21 km). At his first training he runs to his friend Greedy Gonzales' home which is 21 miles away from Flagstaff. Arriving there, he is very tired and realizes that 21 miles are much more than 21 km. Greedy Gonzales tells him that 21 km equals 13 miles. 21, 13? Bruce realizes immediately that there must be a deeper relation! Both, 13 and 21 are Fibonacci numbers! Fibonacci numbers can be defined as follows: F1 = 1 F2 = 2 Fn+1 = Fn+Fn-1 for n>1. Bruce has just learned about the Fibonacci number system at his university. Each positive integer x can be written as the sum of different Fibonacci numbers, so this means that there exists numbers k and b1, b2, ..., bk such that x = ∑i=1..k bi * Fi, where bk = 1 and bi (1 ≤ i < k) is either 0 or 1. In short, we can write the representation as: b(x) = (bk, bk-1, ..., b1). To make the representation unique, we require that bi * bi-1 = 0 for all i > 1. For example 21 can be represented as (1,0,0,0,0,0,0) and 13 as (1,0,0,0,0,0) in the Fibonacci system. Bruce notices that one can convert a distance x in kilometers into a corresponding distance y to miles as follows: First, write down x in its Fibonacci system representation b(x). Second, shift the bits of b(x) one position to the right (the last bit is deleted) and get b(y). Third, calculate y from b(y) by evaluating the sum given above. For example, the number 42 written in the Fibonacci system is (1,0,0,1,0,0,0,0). In step two we would shift the bits one position to the right and get (1,0,0,1,0,0,0). In the third step, we would calculate 0*1 + 0*2 + 0*3 + 1*5 + 0*8 + 0*13 + 1*21 = 26. Now it's your turn to write a program for Bruce that converts kilometers into miles according to Bruce's algorithm. Input The first line of the input contains t, the number of distances Bruce wants to convert from kilometers to miles (0<t<25000). Each of the next t lines contains an integer distance x (2 < x < 25000) in kilometers. Output For each distance x in kilometers output the distance y in miles calculated according to Bruce's algorithm. Sample Input 5 42 100 180 300 360 Sample Output 26 62 111 185 222

关于遍历一个树的问题,怎么从一个叶子节点跳转到另一个,采用C语言完成

Problem Description   Changsha is a beautiful city surrounded by mountains and rivers, forming a charming scenery. There are many tourist attractions in Changsha: Yuelu Academy, the predecessor of Hunan University, which is one of the four most famous academies in China. It was established in 976A.D. in Northern Song Dynasty. Juzizhou Island (Orange Isle) is the world's longest inland river isle which lies in Xiangjiang River and it is famous for the famous poet Qinyuanchun-Changsha written by Chairman Mao. Mawangdui is a famous archaeological site that contains the tombs of three people from the Western Han Dynasty. The tomb of Xin Zhui is best preserved among the three with a complete cosmetic set, lacquered pieces and finely woven silk garments. Huogongdian represents the Huxiang culture and Chuwu culture, Hunan’s geography culture and Hunan’s distinctive food culture. Tourists can have a taste of typical Hunan cuisine in it.   Every year the city holds a marathon. When planning the route, the organizers wish to go pass some tourist attractions to make it more enjoyable to attract more athletes and audience. Changsha can be treated as a graph consisted of N intersections and many bidirectional roads. A road connects two intersections i and j with length Wi,j. However, to reduce the impact to the daily traffic, only N-1 roads specified by the local government which can connect all N intersections are allowed to be used as the route. And the intersections with only one adjacent intersection are on the west bank of Xiangjiang River and there are ferries only at these intersections. The marathon starts at the intersection called Red East Square (marked as S) in Hunan University by convention. The organizers do not want the route pass any road twice, so the marathon has to be separated into two sections, the first section and the second section. Two different points have to be selected from intersections on the bank to act as the half end point S1 and the half starting point S2. The first section starts from S and end in S1. The second section starts from S2 and end in S. The organizer will use ferryboats to transport athletes from S1 to S2 as required by the government.   Considering the safety, some supply points are to be set on some intersections on each half section and there must be a supply point set on S, S1 and S2. According to scientific research, the most suitable distance between two adjacent supply points is L and the organizers want to minimize the evaluation of the route. For each section, the evaluation from the starting point to rest point i is marked as Ei, and where j is the previous supply point on the route,  means the sum of the roads’ length on the route from intersection j to i. The evaluation of the starting point is zero. The evaluation of a section equals to the evaluation from its starting point to end point.   Your task is to select S1, S2, and the supply points to minimize the total evaluation of both sections. Input   There are multiple test cases.   For each test case the first line contains two integers, N, L. (1<=N<=20000, 1<=L<=109)   The next N-1 lines with 3 integers, U, V, W, describes that a bidirectional road connects intersection U and V with distance W. (1<=U, V<=N, 1<=W<=103) Red East Square (S) is always numbered 1. The input will finish with the end of file. Output   For each case the output contains only one line, the evaluation of the best plan rounded to the second digit after the decimal point. If there is no solution, output -1. Sample Input 7 4 1 2 2 1 3 7 1 4 3 2 5 6 2 6 5 3 7 8 Sample Output 7.00

使用反射获取接口的值

<div class="post-text" itemprop="text"> <p>I'm trying to get a value from <a href="https://github.com/gambol99/go-marathon/blob/master/events.go#L107" rel="nofollow noreferrer">an interface</a> (it should be a pointer to another struct, <a href="https://github.com/gambol99/go-marathon/blob/master/events.go#L356" rel="nofollow noreferrer">see</a>). Actually, I have to know the type of the pointer to access to the data it and it bother me. That's why I would like to use <a href="https://golang.org/pkg/reflect/" rel="nofollow noreferrer">reflect package</a> to do it better.</p> <p>Actually, I can display the type using <code>reflect.TypeOf(event.Event).String()</code> but I don't understand how to change <a href="https://github.com/gambol99/go-marathon/blob/master/examples/events_sse_transport/main.go#L73" rel="nofollow noreferrer">this line</a> in the example without specifying with something like <code>.(*marathon.EventDeploymentStepSuccess)</code></p> </div>

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

点沙成金:英特尔芯片制造全过程揭密

“亚马逊丛林里的蝴蝶扇动几下翅膀就可能引起两周后美国德州的一次飓风……” 这句人人皆知的话最初用来描述非线性系统中微小参数的变化所引起的系统极大变化。 而在更长的时间尺度内,我们所生活的这个世界就是这样一个异常复杂的非线性系统…… 水泥、穹顶、透视——关于时间与技艺的蝴蝶效应 公元前3000年,古埃及人将尼罗河中挖出的泥浆与纳特龙盐湖中的矿物盐混合,再掺入煅烧石灰石制成的石灰,由此得来了人...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

我说我不会算法,阿里把我挂了。

不说了,字节跳动也反手把我挂了。

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

你打算用Java 8一辈子都不打算升级到Java 14,真香

我们程序员应该抱着尝鲜、猎奇的心态,否则就容易固步自封,技术停滞不前。

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《经典算法案例》01-08:如何使用质数设计扫雷(Minesweeper)游戏

我们都玩过Windows操作系统中的经典游戏扫雷(Minesweeper),如果把质数当作一颗雷,那么,表格中红色的数字哪些是雷(质数)?您能找出多少个呢?文中用列表的方式罗列了10000以内的自然数、质数(素数),6的倍数等,方便大家观察质数的分布规律及特性,以便对算法求解有指导意义。另外,判断质数是初学算法,理解算法重要性的一个非常好的案例。

《Oracle Java SE编程自学与面试指南》最佳学习路线图(2020最新版)

正确选择比瞎努力更重要!

一文带你入门Java Stream流,太强了

两个星期以前,就有读者强烈要求我写一篇 Java Stream 流的文章,我说市面上不是已经有很多了吗,结果你猜他怎么说:“就想看你写的啊!”你看你看,多么苍白的喜欢啊。那就“勉为其难”写一篇吧,嘻嘻。 单从“Stream”这个单词上来看,它似乎和 java.io 包下的 InputStream 和 OutputStream 有些关系。实际上呢,没毛关系。Java 8 新增的 Stream 是为...

都前后端分离了,咱就别做页面跳转了!统统 JSON 交互

文章目录1. 无状态登录1.1 什么是有状态1.2 什么是无状态1.3 如何实现无状态1.4 各自优缺点2. 登录交互2.1 前后端分离的数据交互2.2 登录成功2.3 登录失败3. 未认证处理方案4. 注销登录 这是本系列的第四篇,有小伙伴找不到之前文章,松哥给大家列一个索引出来: 挖一个大坑,Spring Security 开搞! 松哥手把手带你入门 Spring Security,别再问密...

立即提问
相关内容推荐