uvalive5818 uva12376 As Long as I Learn, I Live

题意:给出一个又向图每个图有权值和编号(正方形里的是编号),从第0号节点开始每次向当前节点所连的点中权值最大的节点移动(不会存在权值相同的节点),问最后所在的节点编号和经过的节点的权值之和。

解:模拟就好~

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<vector>
 6
 7 using namespace std;
 8
 9 int T;
10 int n,m;
11 int f[107];
12 vector <int> G[107];
13
14 int main(){
15     scanf("%d",&T);
16     for (int cas=1;cas<=T;cas++){
17             scanf("%d%d",&n,&m);
18             for (int i=0;i<n;i++){
19                     scanf("%d",&f[i]);
20                     G[i].clear();
21             }
22             for (int i=0;i<m;i++){
23                     int x,y;
24                     scanf("%d%d",&x,&y);
25                     G[x].push_back(y);
26             }
27             int now=0;
28             int totv=0;
29             while (1){
30             //        printf("%d %d\n",now,totv);
31                     int to=0;
32                     int tov=0;
33                     for (int i=0;i<G[now].size();i++){
34                             if (f[G[now][i]]>tov){
35                                     to=G[now][i];
36                                     tov=f[G[now][i]];
37                             }
38                     }
39                     if (to==0) break;
40                     totv+=tov;
41                     now=to;
42             }
43             printf("Case %d: %d %d\n",cas,totv,now);
44     }
45     return 0;
46 }
47 /*
48 2
49 6 6
50 0 8 9 2 7 5
51 5 4
52 5 3
53 1 5
54 0 1
55 0 2
56 2 1
57 6 6
58 0 8 9 2 6 5
59 5 4
60 5 3
61 1 5
62 0 1
63 0 2
64 2 1
65 */

时间: 2024-10-27 05:51:28

uvalive5818 uva12376 As Long as I Learn, I Live的相关文章

【Machine Learn】决策树案例:基于python的商品购买能力预测系统

决策树在商品购买能力预测案例中的算法实现 作者:白宁超 2016年12月24日22:05:42 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本系列文章是作者结合视频学习和书籍基础的笔记所得.本系列文章将采用理论结合实践方式编写.首先介绍机器学习和深度学习的范畴,然后介绍关于训练集.测试集等介绍.接着分别介绍机器学习常用算法,分别是监督学习之分类(决策树.临近取样.支持向量机.神经网络算法)监督学习之回归(线性回归.非线性回归)非监督学习(

TF.Learn

TF.Learn 手写文字识别 转载请注明作者:梦里风林Google Machine Learning Recipes 7官方中文博客 - 视频地址Github工程地址 https://github.com/ahangchen/GoogleML欢迎Star,也欢迎到Issue区讨论 mnist问题 计算机视觉领域的Hello world 给定55000个图片,处理成28*28的二维矩阵,矩阵中每个值表示一个像素点的灰度,作为feature 给定每张图片对应的字符,作为label,总共有10个la

Is it too late to learn to code?

Erin Parker, Founder Spitfire Athlete, iOS Engineer 9k upvotes by Francis Chen, Gaurav Baheti, Yue-Wing Yau, Maria Guryanova,(more) It's never too late. So much can happen in a year, it can amaze you. I majored in Economics. When I was about 23, I ra

Learn Python the Hard Way--Exercise 46

0. 缘起 <Learn Python the Hard Way>Exercise 46 要求安装四个python package pip, distribute, nose, virtualenv,(原书作者特别提醒: Do not just donwload these packages and install them by hand. Instead see how other people recommend you install these packages and use th

教程 1:让我们通过例子来学习(Tutorial 1: Let’s learn by example)

通过这第一个教程,我们将引导您从基础完成创建简单的带有注册表单的应用. 我们也将解释框架行为的基本方面.如果您对Phalcon的自动代码生成工具有兴趣, 您可以查看 developer tools. 确认安装(Checking your installation)? We'll assume you have Phalcon installed already. Check your phpinfo() output for a section referencing "Phalcon"

Learn Python From &#39;Head First Python&#39; [3](2) : Pickle

1.the use of 'with open... as ...' 2.the use of pickle(dump and load) for Step1: the 'with open ... as...' is the short format of 'try...except...finally' for Step2: you can store a list with pickle.dump() and get the content again with pickle.load()

Learn Docker

Learn Docker A Container is to VM today, what VM was to Physical Servers a while ago. The workload seems to shifting towards containers, and fast! In case you haven’t started ramping on it yet, you may find it a bit overwhelming to begin with. I thou

Java-集合(没做出来)第四题 (List)写一个函数reverseList,该函数能够接受一个List,然后把该List 倒序排列。 例如: List list = new ArrayList(); list.add(“Hello”); list.add(“World”); list.add(“Learn”); //此时list 为Hello World Learn reverseL

没做出来 第四题 (List)写一个函数reverseList,该函数能够接受一个List,然后把该List 倒序排列. 例如: List list = new ArrayList(); list.add(“Hello”); list.add(“World”); list.add(“Learn”); //此时list 为Hello World Learn reverseList(list); //调用reverseList 方法之后,list 为Learn World Hello package

快速入门:十分钟学会PythonTutorial - Learn Python in 10 minutes

This tutorial is available as a short ebook. The e-book features extra content from follow-up posts on various Python best practices, all in a convenient, self-contained format. All future updates are free for people who purchase it. Preliminary fluf