洛谷P1038神经网络
传送门啦
一个拓扑排序的题,感觉题目好难懂。。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 105;
inline int read(){char ch = getchar();int f = 1 , x = 0;while(ch > '9' || ch < '0'){if(ch == '-')f = -1;ch = getchar();}while(ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + ch - '0';ch = getchar();}return x * f;}
int n,p,c[maxn],u[maxn],x,y,z;
int head[maxn],tot;
int in[maxn],out[maxn];
bool vis[maxn],flag;
struct Edge{
int from,to,val,next;
}edge[maxn << 1];
void add(int u,int v,int w){
edge[++tot].from = u;
edge[tot].to = v;
edge[tot].val = w;
edge[tot].next = head[u];
head[u] = tot;
}
void dfs(int x){
for(int i=head[x];i;i=edge[i].next){
int v = edge[i].to;
c[v] += edge[i].val * c[x];
in[v]--;
if(!in[v] && c[v] - u[v] > 0){
c[v] -= u[v];
dfs(v);
}
}
}
int main(){
n = read(); p = read();
for(int i=1;i<=n;i++) {
c[i] = read(); u[i] = read();
if(c[i] > 0) vis[i] = true;
}
for(int i=1;i<=p;i++){
x = read(); y = read(); z = read();
add(x , y , z);
in[y]++; out[x]++;
}
for(int i=1;i<=n;i++)
if(vis[i]) dfs(i);
for(int i=1;i<=n;i++)
if(out[i] == 0 && c[i] > 0){
printf("%d %d\n",i,c[i]);
flag = true;
}
if(!flag) printf("NULL\n");
return 0;
}
洛谷P1038神经网络的更多相关文章
- 洛谷P1038 神经网络==codevs1088 神经网络
P1038 神经网络 题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸多领域有广泛的应用.对神 ...
- 洛谷P1038 神经网络
P1038 神经网络 题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸多领域有广泛的应用.对神 ...
- 洛谷——P1038 神经网络
P1038 神经网络 题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸多领域有广泛的应用.对神 ...
- 洛谷 P1038 神经网络 Label:拓扑排序 && 坑 60分待查
题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸多领域有广泛的应用.对神经网络的研究一直是当今 ...
- 洛谷P1038 神经网络(bfs,模拟,拓扑)
题目背景 人工神经网络(Artificial Neural NetworkArtificialNeuralNetwork)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸 ...
- 洛谷 P1038 神经网络
题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸多领域有广泛的应用.对神经网络的研究一直是当今 ...
- [NOIP2003] 提高组 洛谷P1038 神经网络
题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸多领域有广泛的应用.对神经网络的研究一直是当今 ...
- 洛谷P1038神经网络题解
题目 这个题不得不说是一道大坑题,为什么这么说呢,这题目不仅难懂,还非常适合那种被生物奥赛刷下来而来到信息奥赛的学生. 因此我们先分析一下题目的坑点. 1: 题目的图分为输入层,输出层,以及中间层. ...
- 洛谷P1038 神经网络题解
注意如果是 \(if(c[i])\) 这条语句并没有说明c[i]不为负数,所以说最好老老实实的写 #include<cstdio> #define _ 0 using namespace ...
随机推荐
- android中的style部分属性值介绍 --zz
Android平台定义的主题样式: android:theme="@android:style/Theme.Dialog" 将一个Activity显示为对话框模式 •andro ...
- MVC中使用RadioButtonFor
http://shw3588.blog.163.com/blog/static/6507576201321395845538/ 1 进行初始化 <%=Html.RadioButtonFor(mo ...
- 使用 python 将 "\r\n" 转换为 "\n"
众所周知, Linux 下没有 "\r\n", 而 windows 下文本工具默认打开文件时使用 t 模式, 使得写入一行结尾的换行符为 "\r\n", 这样造 ...
- 【Asp.net入门5-01】SportsStore:一个真实的应用程序
- python的dict()字典数据类型的方法详解以及案例使用
一.之前的回顾 # int 数字 # str 字符串 # list 列表 # tuple 元组 # dict 字典 字典中最重要的方法 keys() values() items() get upd ...
- TOML 详解
TOML的由来 配置文件的使用由来已久,从.ini.XML.JSON.YAML再到TOML,语言的表达能力越来越强,同时书写便捷性也在不断提升. TOML是前GitHub CEO, Tom Prest ...
- IOS取消performSelector警告
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks&quo ...
- 科学计算三维可视化---TVTK库可视化实例
一:TVTK库可视化实例 Plot3D文件知识:PLOT3D 数据格式 PLOT3D文件分为网格文件(XYZ 文件), 空气动力学结果文件 (Q 文件)和通用结果文件(函数文件 + 函数名称文件).网 ...
- redhat6下安装centos的yum源
因为redhat中的yum是收费的,未注册时不允许使用的,下面是挂载光盘后的情况,未挂载是没有yum命令.但是下面即便挂载了也是需要验证的 [root@localhost /]# yum instal ...
- 动态规划:POJ No 2385 Apple Catching
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> ...