• The 2019 Asia Nanchang First Round Online Programming Contest


    B Fire-Fighting Hero(最短路 Dijkstra)

    This is an era of team success, but also an era of heroes. Throughout the ages, there have been numerous examples of using the few to defeat the many. There are V (Numbers 1 to V) fire-fighting points in ACM city. These fire-fighting points have E roads to communicate with each other. Among them, there is a fire-fighting hero in the SSS fire-fighting point, and the fire-fighting team is distributed in K fire-fighting points. If a fire-fighting point needs to be put out, the fire-fighting hero or the fire-fighting team must arrive as soon as possible, that is, to choose the shortest route to arrive.

    Today, our fire-fighting heroes want to challenge the fire-fighting team. The challenge is to: The maximum value of the shortest path for a fire-fighting hero to go to others fire-fighting points is compared with the maximum value of the shortest path for a fire-fighting team to go to others fire-fighting points from any point in their fire-fighting points. Because firefighting heroes are different and run faster, the maximum value of the shortest path they get should be discounted first, that is, multiplied by a coefficient of C/1​, and then compared. The smaller one wins. Who is the real firefighter in this situation?

    Who is the real firefighter in this situation?

    Input

    The first line contains a positive integer T(1≤T≤10), which indicates that there are T cases of test data.

    The format of each case of test data is as follows:

    In the next E line, three positive integers i,j(1≤i,j≤V) and L(1≤L≤10000) per line. Represents a path, i,j as the endpoint (fire-fighting point), LLL as the length of the path.

    Output

    Each case of test data outputs one line, which is a integer. That is, the maximum value of the shortest path of the winner (If the fire hero wins, the maximum value before the discount should be output). A draw is also a victory for fire-fighting hero.

    样例输入

    1
    4 7 3 2 2
    1 4
    1 2 7
    1 3 2
    1 4 6 
    2 1 1
    2 4 1
    3 2 1
    3 4 3

    样例输出

    2

    题意分析:

    一个消防员和多个队伍比赛,比较所有地方的最短路的最大值,消防员最后的值要乘1/C,求胜利的一方的最短路的最大值是多少。

    解题思路:

    跑两遍Dijkstra即可,注意双向边。

    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    const int N = 1020;
    using namespace std;
    int dis[N], k[N], e[N][N], V, E, S, K, C, inf=0x3f3f3f3f;
    bool book[N];
    int Dijkstra()
    {
    	int u, mini;
    	
    	for(int i=1; i<V; i++)
    	{
    		mini=inf;
    		for(int j=1; j<=V; j++)
    		{
    			if(dis[j] < mini && book[j]==false)
    			{
    				u=j;
    				mini = dis[j];
    			}
    		}
    		book[u] = true;
    		if(mini == inf)	
    			break;
    		for(int v=1; v<=V; v++)
    		{
    			if(dis[v] > dis[u] + e[u][v])
    				dis[v] = dis[u] + e[u][v];
    		}	
    	}
    	int ans=dis[1];
    	for(int i=2; i<=V; i++)
    		ans=max(ans, dis[i]);
    	return ans;
    } 
    void init()
    {
    	memset(book, false, sizeof(book));
    	for(int i=1; i<=V; i++)
    		for(int j=1; j<=V; j++)
    			if(i==j)
    				e[i][j]=0;
    			else e[i][j]=inf;
    }
    int main()
    {
    	int t, u, v, w;
    	scanf("%d", &t);
    	while(t--)
    	{
    		scanf("%d%d%d%d%d", &V, &E, &S, &K, &C);
    		
    		init();
    		for(int i=1; i<=V; i++)
    			dis[i] = inf;
    		for(int i=1; i<=K; i++)
    		{
    			scanf("%d", &k[i]);
    			dis[k[i]]=0;
    			book[k[i]]=true;
    		}
    		
    		for(int i=1; i<=E; i++)
    		{
    			scanf("%d%d%d", &u, &v, &w);
    			e[u][v] = e[v][u] = min(e[u][v], w);
    		}
    		for(int i=1; i<=V; i++) {
    			for(int j=1; j<=K; j++)
    				dis[i]=min(dis[i], e[k[j]][i]);
    		}
    			
    		int ans1 = Dijkstra();
    		memset(book, false, sizeof(book));
    		for(int i=1; i<=V; i++)
    			dis[i] = e[S][i];
    		book[S] = true;
    		dis[S] = 0;
    		int ans2 = Dijkstra();
    		if(ans2*1.0/C <= ans1)
    			printf("%d
    ", ans2);
    		else printf("%d
    ", ans1);
    	}
    	return 0;
    }
    

    E Magic Master(队列模拟)

    John is not only a magic master but also a shuffling master.  

    Famous though he is, he likes interacting with his fans by playing a game with his fantastic shuffling skills. 

    The game shows as follows: 

    He first shows a deck of pokers contains N cards indexed 1,2,…,Nand all the cards are the same. He notes that the side contains numbers as the front side and the other side as the back. Later he selects one of his fans to choose a positive integer MMM that is not greater than 10. After that, he will shuffle the cards purposefully and put it on the desktop. Note that at this moment the front sides of the cards are facing to the desk. 

    Then, the selected fans should perform the following steps until there is no card on the desk. 

    1. Place the card on the top of the piles to John's hand. If there are already some cards in his hand, put it on the top of them. 
    2. If there remain cards on the desk:

    (a) Put a card from the top of the piles to the bottom of it.

    (b) Execute the step (a) of M times.

    (c) Go to step 1.

    Next, it is time to witness the miracle.  

    John will continually overturn the cards on his hand top to bottom, and we will find that the cards are always in decreasing order. 

    One day, one of John's fans, Tom, a smart JBer, understands the key to this magic. He turns to you and comments that the key to that magic is the shuffling John did previously. For any number M, he will turn the cards in a specific order after the shuffling. As you are not as smart as Tom, you should find the index of the KKKth cards from the top of the piles after the shuffling.

    Input

    The first line contain a positive integer T(1≤T≤10)– the number of test cases.

    For each test cases, the first line contain a positive integer N(1≤N≤40000000) , indicating the numberof cards.

    The second line contain a positive integer M(1≤M≤10) – the number the fans select.

    The third line contain an integer Q(1≤Q≤100) – indicating that there are Q questions.

    Next, there are Q lines, each with an integer K(1≤K≤N) – representing a query.

    Output

    For each query, you should output the index of the KKKth cards from the top of the piles after the shuffling.

    样例输入

    1
    5
    1
    2
    2
    3
    

    样例输出

    5
    2

    样例解释

    Sample description - The indexs of the cards after the shuffling are: 1 5 2 4 3 (Left is top)

    题意分析:

    有一副牌,从上到下取,规则:

    (1)把最上面取出一张牌放在手上,如果手上有牌,放在最上面。

    (2)a:把桌子上最上面的牌拿出一张放到最下面,

             b:进行m次a步骤

             c:返回步骤1

    最后手上的牌是依次递减的,求最开始牌的排列。

    解题思路:

    既然知道最后牌的排列,那么可以反向模拟从手上拿牌放到桌面上,最后把排列出队即可。

    #include <stdio.h>
    #include <queue>
    const int N = 4e7+20;
    using namespace std;
    queue<int>s;
    int ans[N];
    int main()
    {
    	int t, n, m, q, k;
    	scanf("%d", &t);
    	while(t--)
    	{
    		scanf("%d%d%d", &n, &m, &q);
    		for(int i=n; i>=1; i--)
    		{
    			s.push(i);
    			int x=m;
    			if(i>1)
    			{
    				while(x--)
    				{
    					int a=s.front();
    					s.pop();
    					s.push(a);
    				}
    			}
    			
    		}
    		for(int i=1; i<=n; i++){
    			ans[i]=s.front();
    			s.pop(); 
    		}
    		while(q--)
    		{
    			scanf("%d", &k);
    			printf("%d
    ", ans[n-k+1]);
    		}		
    	}
    	return 0;
    }
    

    G Pangu Separates Heaven and Earth(签到题)

    Long long ago, the sky and the earth were not separated, and the universe was chaotic. There was a giant named Pangu who slept for eighteen thousand years in this chaos.

    One day, Pangu woke up suddenly. When he saw the darkness around him, he took up his axe and slammed into the darkness in front of him. Just listen to a loud noise, chaotic things gradually separated. Light and clear things rise slowly and become heaven; heavy and turbid things fall slowly and become earth.

    After the separation of heaven and earth, Pangu feared that they would still be together. He put his head on the heaven and pedaled the earth with his feet. Every day, Pangu rose by a tenth, and the longer Pangu grew, the higher Pangu grew. In this way, I do not know how many years, the sky and the earth gradually formed, Pangu also fell tired.Pangu's body changed dramatically after his fall. His breath became the wind of the seasons and the floating clouds; his voice turned into a rumbling thunder. His eyes became the sun and the moon; his limbs became the east, west, South and North four poles of the earth; his skin became the vast land; his blood became the running rivers; his sweat became the rain that moistened all things...

    Input

    The first line has a positive integer T(1≤T≤10), which indicates that there are T cases of test data.

    Each case of test data input takes up one line and is a positive integer N(1≤N≤100000000).

    Output

    Each case of test data output takes up one line, which is an integer.

    When input is 1, output Pangu sleeping years, that is: 18000

    When input is others, output zero, that is: 0

    样例输入

    2
    1
    2

    样例输出

    18000
    0

    题意分析:

    输入是1时输出18000,否则输出0.

    #include <stdio.h>
    int main()
    {
    	int t, n;
    	scanf("%d", &t);
    	while(t--)
    	{
    		scanf("%d", &n);
    		if(n==1)
    			printf("18000
    ");
    		else printf("0
    ");
    	}
    	return 0;
    } 
  • 相关阅读:
    IE6-IE11兼容性问题列表及解决办法
    EJB--事务管理 .
    JDBC批处理---(java 对数据库的回滚) .
    redisb并发访问慢出现的问题
    redis其他问题
    多线程实现服务器端接收连接
    序列化作用
    redis的key过期时间
    nginx负载均衡和反向代理有什么区别
    nginx的负载均衡和反响代理配置
  • 原文地址:https://www.cnblogs.com/zyq1758043090/p/11852500.html
Copyright © 2020-2023  润新知