zoukankan      html  css  js  c++  java
  • 洛谷:P1038 神经网络

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cmath>
     4 using namespace std;
     5 int n,p;
     6 class nerve{public:
     7     int C,U,lnum,chnum;
     8     nerve * next[102];
     9     int w[102],charge[102];
    10     nerve(){
    11         C=U=lnum=chnum=0;
    12         next[0]=0;
    13         memset(next,NULL,102*4);
    14         memset(w,0,102*4);
    15         memset(charge,0,102*4);
    16     }
    17 }nerves[102];
    18 
    19 void show(){
    20     nerve *t;
    21     for(int i=0;i<n;i++){
    22         t=nerves+i;
    23         cout<<"nerve "<<i<<":C="<<t->C<<" U="<<t->U<<"  ";
    24         for(int ii=0;ii<t->chnum;ii++)cout<<t->charge[ii]<<" ";
    25         cout<<endl;
    26     }
    27 }
    28 
    29 int main() {
    30 
    31     cin>>n>>p;
    32     for(int i=0;i<n;i++){
    33         cin>>nerves[i].C>>nerves[i].U;
    34     }
    35     int a,b,c;
    36     nerve *tn,*t0;
    37     for(int i=0;i<p;i++){
    38         cin>>a>>b>>c;a--;b--;
    39         tn=nerves+a;
    40         tn->next[tn->lnum]=nerves+b;
    41         tn->w[tn->lnum]=c;
    42         tn->lnum++;
    43     }
    44     int flag=1;
    45     for(int i=0;i<n;i++){
    46         //计算C
    47         tn=nerves+i;
    48         int temp=0;
    49         for(int ii=0;ii<tn->chnum;ii++){
    50             temp+=tn->charge[ii];
    51         }//总和充能度
    52         if(temp> tn->U)
    53             tn->C+=temp - tn->U;
    54         
    55         for(int ii=0;ii<tn->lnum && tn->C>0;ii++){
    56             t0=tn->next[ii];
    57             t0->charge[t0->chnum++]=tn->C * tn->w[ii];
    58         }//为下一个充能
    59         //cout<<i<<" : ";show();cout<<endl;
    60         if(tn->lnum==0 && tn->C>0){flag=0;
    61             cout<<i+1<<" "<<tn->C<<endl;
    62         }
    63     }
    64     if(flag)cout<<"NULL"<<endl;
    65 
    66     return 0;
    67 }

    https://www.luogu.com.cn/problem/P1038

  • 相关阅读:
    kvm基本原理
    RAID分类
    监控MySQL主从脚本
    MySQL优化
    查看某个ip地址接在交换机的哪个接口
    rsync+inotify脚本
    docker工作流程
    雅礼集训【Day6-1】字符串
    【模拟试题】困难重重
    Loj #6069. 「2017 山东一轮集训 Day4」塔
  • 原文地址:https://www.cnblogs.com/forwhat00/p/13261975.html
Copyright © 2011-2022 走看看