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;
    }
    
  • 相关阅读:
    NOIP2017 时间复杂度 大模拟
    【Python】CV2的一些基本操作
    【Python】类、对象、self
    【Ubuntu18.04】清空回收站
    小飞机可以解决git clone没有返回的问题吗?
    sqlserver2005 远程服务器数据 完全拷贝 到本地数据库
    Microsoft Visual Studio 2005 多线程时 解决不是该线程创建的来访问
    MS SqL2000 数据库置疑状态的解决方法[转]
    vue 函数配置项watch以及函数 $watch 源码分享
    Vue生命周期之beforeCreate vue 生命周期详解
  • 原文地址:https://www.cnblogs.com/Crossea/p/12797958.html
Copyright © 2011-2022 走看看