zoukankan      html  css  js  c++  java
  • csp 201912-4区块链 80分


    思路

    直接利用优先队列,将每一次会对外传播的节点当前的状态记住,同时也存储这次传播会到达的时间
    每次产生和输出之前先更新就可以,但是因为一个节点可能在同一时间生成多个块,会被卡时间,只能得到80分,后续优化懒得做了
    附赠一组测试数据


    15 13
    1 2
    2 3
    3 4
    4 5
    1 6
    6 7
    7 8
    8 9
    1 10
    10 11
    11 12
    12 13
    14 15
    6 28
    1 1 1
    1 2 2
    1 6
    2 7
    13 7
    9 7
    5 7
    3 14
    8 14
    5 14
    11 14
    9 25
    5 25
    13 25
    9 29 3
    5 29 4
    13 29 5
    1 53
    2 59 6
    2 59
    1 1000
    3 1000
    8 1000
    9 1000
    10 1000
    13 1000
    14 1000
    15 1000


    输出

    3 0 1 2
    2 0 1
    1 0
    1 0
    1 0
    3 0 1 2
    1 0
    1 0
    3 0 1 2
    2 0 1
    2 0 1
    2 0 1
    4 0 1 2 3
    5 0 1 2 3 6
    5 0 1 2 3 6
    5 0 1 2 3 6
    5 0 1 2 3 6
    5 0 1 2 3 6
    5 0 1 2 3 6
    5 0 1 2 3 6
    1 0
    1 0


    代码

    #include<bits/stdc++.h>
    using namespace std;
    struct event_bro
    {
    	int id;
    	int t;
    	vector<int> gg;
    	event_bro(int id,int t):id(id),t(t){
    	}
    	bool operator<(const event_bro&a) const
    	{
    		return t>a.t;
    	}
    };
    vector<int> temp[505];
    vector<int> Graph[505];
    priority_queue<event_bro> pq;
    void handler(int t,int gap){ 
    	while(!pq.empty()&&pq.top().t<=t){
    		event_bro he = pq.top();
    		pq.pop();
    		for(auto &i:Graph[he.id]){
    			if(temp[i].size()<he.gg.size()||
    				temp[i].size()==he.gg.size()&&
    				temp[i][temp[i].size()-1]>he.gg[he.gg.size()-1]){
    				temp[i]=he.gg;
    				event_bro __(0,0);
    				__.id=i;
    				__.t=he.t+gap;
    				__.gg = he.gg;
    				pq.push(__);
    			}
    		}
    	}
    }
    void query(int a,int b,int t){
    	handler(b,t);
    	cout<<temp[a].size()<<" ";
    	for(auto &i:temp[a])
    		cout<<i<<" ";
    	cout<<endl;
    }
    void update(int a,int b,int c,int t){
    	handler(b,t);
    	temp[a].push_back(c);
    	event_bro help(a,b+t);
    	help.gg=temp[a]; 
    	pq.push(help);
    }
    int main(int argc, char const *argv[])
    {
    	freopen("1.dat","r",stdin);
    	freopen("ans.dat","w",stdout);
    	int m,n;
    	cin>>m>>n;
    	int a,b,c;
    	for (int i = 0; i < 502; ++i)
    		temp[i].push_back(0);
    	for (int i = 0; i < n; ++i)
    	{
    		cin>>a>>b;
    		Graph[a].push_back(b);
    		Graph[b].push_back(a);
    	}
    	int t,k;
    	cin>>t>>k;
    	while(k--){
    		cin>>a>>b;
    		// char ______=getchar();
    		if(getchar()=='
    '||cin.eof()){
    			query(a,b,t);
    		}else{
    			cin>>c;
    			update(a,b,c,t);
    		}
    	}
    	return 0;
    }
    
  • 相关阅读:
    单选框radio 选择问题
    用户名、密码等15个常用的js正则表达式
    mysql创建远程用户并授权
    JS,Jquery获取屏幕的宽度和高度
    ThinkPHP模版时间显示
    composer启用国内镜像网站的配置更改办法
    tp6 使用全局中间件配置验证器
    tp3.2查询当前时间大于已有时间三分钟
    jquery判断手机端或者pc端
    html页面引入公共的页首和导航栏
  • 原文地址:https://www.cnblogs.com/Crossea/p/12797958.html
Copyright © 2011-2022 走看看