NOIP 2017 d2t2 70points
革命之路漫漫
第一次尝试 40points spfa
- #include <bits/stdc++.h>
- #define read read()
- using namespace std;
- inline int read
- {
- int x=,f=;char ch=getchar();
- while(ch<''||ch>'') {if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){x=*x+(ch-'');ch=getchar();}
- return x*f;
- }
- const int N = ;
- struct edge{
- int v,nxt,w;
- }e[N<<];
- int n,m;
- int head[N],size;
- int dis[N],vis[N],maxn = INT_MAX;
- void add(int u,int v,int w)
- {
- e[++size].v = v;
- e[size].w = w;
- e[size].nxt = head[u];
- head[u] = size;
- }
- queue<int>q;
- void spfa(int s)
- {
- memset(dis,0x3f,sizeof(dis));
- memset(head,,sizeof());
- memset(vis,,sizeof(vis));
- dis[s] = ;
- q.push(s);
- vis[s] = ;
- while(!q.empty())
- {
- int u = q.front(); q.pop(); vis[u] = ;
- for(int i = head[u]; i ; i = e[i].nxt)
- {
- int v = e[i].v, w = e[i].w;
- if(dis[v] > dis[u] + )
- {
- dis[v] = dis[u] + ;
- if(!vis[v])
- {
- q.push(v);
- vis[v] = ;
- }
- }
- }
- }
- }
- int main()
- {
- freopen("treasure.in","r",stdin);
- n = read; m = read;
- int u,v,w;
- for(int i = ; i <= m; i++)
- {
- u = read; v = read; w = read;
- add(u,v,w);
- add(v,u,w); }
- for(int i = ; i <= n; i++)
- {
- spfa(i);
- int ans = ;
- for(int i = ; i <= n; i++)
- {
- ans += dis[i] * w;
- }
- maxn = min(maxn , ans);
- }
- printf("%d",maxn);
- return ;
- }
第二次尝试 dfs
- #include <bits/stdc++.h>
- #define read read()
- using namespace std;
- const int N = ;
- int n,m;
- int cost[N][N],cnt[N];
- int head[N],size;
- int ans = INT_MAX, mincost;
- int read
- {
- int x = ; char ch = getchar();
- while(ch < || ch > ) ch = getchar();
- while(ch >= && ch <= ) { x = * x + ch - ; ch = getchar();}
- return x;
- }
- void dfs(int cur)//暴力枚举所有情况;
- {
- if(cur == n)
- {
- ans = min(ans,mincost);
- return;
- }
- if(mincost > ans) return;
- for(int i = ; i <= n; i++) //枚举出点;
- {
- if(!cnt[i]) continue; //还未连通的点不能当作出点;
- for(int j = ; j <= n; j++) //枚举入点;
- {
- if(i == j || cnt[j] || cost[i][j] == 0x3f3f3f3f) continue;
- mincost += cnt[i] * cost[i][j];
- cnt[j] = cnt[i] + ;
- dfs(cur + );
- mincost -= cnt[i] * cost[i][j];
- cnt[j] = ;
- }
- }
- }
- int main()
- {
- // freopen("treasure.in","r",stdin);
- n = read;m = read;
- memset(cost,0x3f,sizeof(cost));
- int u,v;
- for(int i = ; i <= m; i++)
- {
- u = read; v = read;
- cost[u][v] = cost[v][u] = min(read , cost[u][v]); //细节: u-v之间可能有多条路连接, 忽略其余选最短;
- }
- for(int i = ; i <= n; i++) //枚举起点;
- {
- cnt[i] = ;
- dfs();
- cnt[i] = ;
- }
- printf("%d",ans);
- return ;
- }
NOIP 2017 d2t2 70points的更多相关文章
- NOIP 2017 解题报告
---恢复内容开始--- NOIP 2017 的题真的很难啊,怪不得当年我这个萌新爆零了(当然现在也是萌新)越学越觉得自己什么都不会. 想要成为强者要把这些好题都弄懂弄透 至少现在6道题我都比较陌生 ...
- NOIP 2017 列队 - Splay - 树状数组
题目传送门 传送点I 传送点II 题目大意 (家喻户晓的题目应该不需要大意) (我之前咋把NOIP 2017打成了NOIP 2018,好绝望) Solution 1 Splay 每行一颗Splay,没 ...
- 【游记】NOIP 2017
时间:2017.11.11~2017.11.12 地点:广东省广州市第六中学 Day1 T1:看到题目,心想这种题目也能放在T1? 这个结论我之前遇到过至少3次,自己也简单证明过.初见是NOIP200 ...
- NOIP 2017 小凯的疑惑
# NOIP 2017 小凯的疑惑 思路 a,b 互质 求最大不能表示出来的数k 则k与 a,b 互质 这里有一个结论:(网上有证明)不过我是打表找的规律 若 x,y(设x<y) 互质 则 : ...
- 历年真题 未完成(Noip 2008 - Noip 2017)
Noip 2008 :全部 Noip 2009 :全部 Noip 2010 :AK Noip 2011 :AK Noip 2012 : Vigenère 密码,国王游戏,开车旅行 Noip 2013 ...
- 「NOIP 2017」列队
题目大意:给定一个 $n times m$ 的方阵,初始时第 $i$ 行第 $j$ 列的人的编号为 $(i-1) times m + j$,$q$ 次给出 $x,y$,让第 $x$ 行 $y$ 列的人 ...
- NOIP 2016 D2T2 蚯蚓](思维)
NOIP 2016 D2T2 蚯蚓 题目大意 本题中,我们将用符号 \(\lfloor c \rfloor⌊c⌋\) 表示对 \(c\) 向下取整,例如:\(\lfloor 3.0 \rfloor = ...
- 洛谷 P3951 NOIP 2017 小凯的疑惑
洛谷 P3951 NOIP 2017 小凯的疑惑 题目描述 小凯手中有两种面值的金币,两种面值均为正整数且彼此互素.每种金币小凯都有 无数个.在不找零的情况下,仅凭这两种金币,有些物品他是无法准确支付 ...
- NOIP 2017 提高组 day1t2 时间复杂度
P3952 时间复杂度 标签 NOIp提高组 2017 时空限制 1000ms / 128MB 小明正在学习一种新的编程语言 A++,刚学会循环语句的他激动地写了好多程序并 给出了他自己算出的时间复杂 ...
随机推荐
- eclipse中没有tomcat小猫
安装了tomcat,按网上的说明也使用了tomcatPluginV331 配置文件,还是没有小猫,后来我发现,网上的tomcatPluginV331 针对eclipse 4.4版本,所以应该是插件的版 ...
- WAS 常见报错
1) An error occurred while deleting the server. ADMG0011E: An unexpected exception occurred com.ibm. ...
- macOS 升级后重装命令行工具的问题
问题背景 最近升级个人macbook 从 10.13 到 10.14 在终端输入 git 不能用了,发现是重装操作系统后原来的 Command Line Tools 被自动卸载了, 采用 xcode- ...
- linux 备忘录
1. ps aux|grep 程序 -------->查看当前程序是否运行 ps aux|grep nginx 2. tar -zxvf 压缩包 ---------> 解压缩 tar -z ...
- Java遍历文件夹下的所以文件
利用Java递归遍历文件夹下的所以文件,然后对文件进行其他的操作.如:对文件进行重命名,对某一类文件进行重编码.可以对某一工程下的全部.java文件进行转码成utf-8等 代码如下,这里只对文件进行重 ...
- 从mysql导入及导出csv
csv导入: load data local infile 'D:/pcode/shu/data/a.csv' into table a fields terminated by ','; csv导出 ...
- Linux 任务管理 && 常用指令
A.linux死机 转自:https://www.deleak.com/blog/2010/10/20/sysrq/ linux死机了怎么办? 曾经啊,对着键盘上 Print Screen/SysRq ...
- Windows下PythonQt编译(vs2015+Qt5.11.2+PythonQt 3.2)
后记: 由于自己low,没有下载罪行的python3.2导致编译上遇到种种问题,后文可以参考,建议看: <Windows7 VS2015 下编译 PythonQt3.2> https:// ...
- c# 多个事件公用一个相应方法判断事件来源
假设下边的相应方法有多个事件共同使用.根据事件的sender 判断来源,做相应的处理 假设事件来源DataManSystem;private void OnSystemConnected(object ...
- 1C - A + B Problem II
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum o ...