2017.1.20总结

今天写了p1226

主要考察知识点是拓扑排序以及一些零碎的细节

具体做法没什么特别的,就是细节有点多,比如判断输出层,公式运算等

代码如下:

 1 //2017.1.20 Earl_WR
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <string>
 6 #include <algorithm>
 7 using namespace std;
 8 long long n;
 9 long long map[500][500]={};
10 bool flag=0;
11 struct p
12 {
13     long long d;
14     long long v;
15     long long c;
16     long long cost;
17     long long chudu;
18 }id[500];
19 long long q;
20 long long queue[500],tail=0,head=1;
21 long long read()
22 {
23     long long x=0,f=1;char ch=getchar();
24     while (ch<'0' || ch>'9'){if (ch=='-')f=-1;ch=getchar();}
25     while (ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
26     return x*f;
27 }
28 void in()
29 {
30     n=read();q=read();
31     for (int i=1;i<=n;i++)
32     {
33         id[i].d=i;
34         id[i].c=read();id[i].cost=read();
35         id[i].v=0;
36         id[i].chudu=0;
37     }
38     for (int i=1;i<=q;i++)
39     {
40         int x,y,z;
41         x=read();y=read();z=read();
42         map[x][y]=z;
43         id[y].v++;
44         id[x].chudu++;
45     }
46 }
47 int main()
48 {
49     //freopen ("test.in","r",stdin);
50     //freopen ("test.out","w",stdout);
51     in();
52     for (int i=1;i<=n;i++)
53     {
54         if (id[i].v==0)
55         {
56             queue[++tail]=id[i].d;
57         }
58     }
59     for (head=1;head<=tail;head++)
60     {
61         for (int i=1;i<=n;i++)
62         {
63             if (map[queue[head]][i])
64             {
65                 id[i].v--;
66                 id[i].c+=map[queue[head]][i]*id[queue[head]].c;
67                 if (id[i].v==0)
68                 {
69                     queue[++tail]=i;
70                     id[queue[tail]].c-=id[queue[tail]].cost;
71                 }
72             }
73         }
74     }80     for (int i=1;i<=n;i++)
81     {
82         //cout<<id[i].d<<' '<<id[i].c<<endl;
83         if (id[i].chudu==0 && id[i].c>0)
84         {
85             flag=1;
86             cout<<id[i].d<<' '<<id[i].c<<endl;
87         }
88     }
89     if (!flag) cout<<"NULL"<<endl;
90     return 0;
91 }

今天切题数量只有一道,主要是因为今天上午讲课下午也是讲课,再加上中午午休,思路被打断了很多次,而且做这道题的时候也出现过很多低级错误,拖延了时间。

以后要提升代码能力,争取少犯低级错误

2017.1.20 结束,以上

转载于:https://www.cnblogs.com/Earl-WR/p/6323221.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值