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\n", ans2);
		else printf("%d\n", 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\n", 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\n");
		else printf("0\n");
	}
	return 0;
} 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张宜强

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值