2021/2/17 Simulation Tournament

T1 volume adjustment

Insert picture description here
Look at this data range, isn't it dfs?

#include <bits/stdc++.h>
using namespace std;
int a[6666],n,beg,maxx,ans=-1;
bool flag[601][1110];
void dfs(int x,int y)//x记录音量,y记录唱到第几首
{
    
    
	if(flag[y][x]==1)//如果该状态出现过,就return
	{
    
    
		return ;
	}
	flag[y][x]=1;//记录这个状态
	if(x>maxx)//音量过高就return
		return ;
	if(x<0)//音量过低就return
		return ;
	if(y>n)//如果活着唱完
	{
    
    
		ans=max(ans,x);//记录是不是最高音
		return ;
	}
	dfs(x+a[y],y+1);//音量增加a[y]
	dfs(x-a[y],y+1);//减少
	return ;
}
int main()
{
    
    
	cin>>n>>beg>>maxx;//输入唱几首歌开始音量和最高音量
	for(int i=1;i<=n;i++)
		cin>>a[i];
	dfs(beg,1);//初始音量和第一首歌
	cout<<ans;
	return 0;
}

Reluctantly count as a memory search. At first, the flag was not defined. Later, it was found that you can record the volume of each song when you sing it according to the "not repetitive and not leaking" due to the DP, which greatly avoids repetition, and dfs It is not easy to leak by itself.
I didn't pay attention when handing in

	if(flag[y][x]==1)//如果该状态出现过,就return
	{
    
    
		return ;
	}
	flag[y][x]=1;//记录这个状态

Written as

	if(flag[x][y]==1)//如果该状态出现过,就return
	{
    
    
		return ;
	}
	flag[x][y]=1;//记录这个状态

The array is out of bounds, only 10 points.
Only 50 points after it came out, I looked at the error and then looked at the question, and found that the question was wrong
Insert picture description here

It was the maximum volume in the process, which was outrageous. It was still 50 points. After the
Insert picture description here
change, it became the same as it is now, and finally AC happily.
What's even more outrageous is that in Luogu, you can see that the
Insert picture description here
difficulty of Henan Province election is popular-

T2

After reading it, I found that it was pressing DP, but I immediately jumped without thinking.

T3 Replenishment

General idea

When playing Dota, teammate Lao Lu grabs your pawn line. When you play Spectre, you attack first. Each time you can hit one pawn with a drop of blood, Lao Lu reduces all the pawns by one drop and asks how many pawns you can make up.
When I play the game, I still can't make up the pawns. Can I make up the pawns if I write this? ? ?
I still don’t have a correct idea, so I want to fight violence and record the number of pawns with HP i. If the number is greater than 2 and i is greater than 3, then hit the pawn to make the pawn’s HP staggered as much as possible, but first Kill the creeps with 1 HP first.

#include <bits/stdc++.h>
using namespace std;
const int N=1010;
int zuida,t,b[N],a,n,ans;
void init()//输入数据
{
    
    
	ans=0;
	memset(b,0,sizeof b);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
    
    
		cin>>a;
		b[a]++;
		zuida=max(zuida,a);
	}
}
void work(int x)//看补兵,x记录血量最多的兵的血量
{
    
    
	if(x<=0)//都死了
	{
    
    
		return ;
	}
	if(b[1])//如果有小兵血量为1
	{
    
    
		ans++;//为答案贡献1
		for(int i=1;i<=x;i++)//老鹿AOE小兵每个减少1滴血
		{
    
    
			b[i]=b[i+1];
		}
		x--;//最大的血量比原来少1
		work(x);
		return ;
	}
	for(int i=3;i<=x;i++)//想办法让小兵血量错开
	{
    
    
		if(b[i]>1)
		{
    
    
			b[i]--;
			b[i-1]++;
		}
	}
	for(int i=1;i<=x;i++)
	{
    
    
		b[i]=b[i+1];
	}
	x--;
	work(x);
	return ;	
}
int main()
{
    
    
	cin>>t;
	while(t--)
	{
    
    
		init();
		work(zuida);
		cout<<ans<<endl;
	}
	return 0;
}

When I wrote it, I felt like I had done a similar question, but I couldn’t figure it out all the time. I finally lied to 10 points. There is no higher in this game...

Correct answer

Insert picture description here

T4 CF111C Petya and Spiders

I double clicked the DP again, but it can
Insert picture description here
be seen in the PDF given by the teacher. Only 50% of the score is good. I think it’s great.
So I write and draw on the paper. It feels that the three are connected together, and the two left and right are moved to The middle grid has the greatest benefit.

#include <bits/stdc++.h>
using namespace std;
int a,b,m,n,ans;
void work1()
{
    
    
	a=m/3;
	b=m%3;
	if(b==0)
	{
    
    
		ans+=2*a;
	}
	if(b==1)
	{
    
    
		ans+=2*a;
	}
	if(b==2)
	{
    
    
		ans+=a*2;
		ans+=1;
	}
}
void work2()
{
    
    
	a=m/3;
	b=m%3;
	if(b==0)
	{
    
    
		ans+=(m/3)*2*n;
	}
	if(b==1)
	{
    
    
		ans+=(m/3)*2*n;
		ans+=1;
	}
	if(b==2)
	{
    
    
		ans+=a*2*n;
		ans+=2;
	}
}
void workn3()
{
    
    
	a=n/3;
	ans+=m*2*a;
}
void workm3()
{
    
    
	a=m/3;
	ans+=2*n*a;
}
void work()
{
    
    
	a=n/3;
	b=n%3;
	ans+=m*2*a;
	m=b;
	if(n==1) work1();
	else if(n==2) work2();
}
int main()
{
    
    
	cin>>n>>m;
	if(m<n)
		swap(m,n);
	int rp;
	rp++;
	if(n%3==0)	workn3();
	else if(m%3==0)	workm3();
	else if(n==1) work1();
	else if(n==2) work2();
	else work();
	cout<<ans;
	return 0;
}

I wrote about it in sections, and finally felt that if I disassembled the big data and wrote it might be able to lose AC, so I wrote work(), so I happily took 30. After the score came out, no one really got 50. After the teacher raised some points, yes. A better method is to ensure that n is the smaller number of m and n, and it can be obtained by m*n≤40. At this time, the maximum value of n is 6, 6×6=36, and the data must be an integer. This line of thought should also count a lot of points.

T5 Big Cow Gathering

Title description

Bessie is planning an annual big cow rally, and cows from all over the country will participate in this rally in the future. Of course, she will choose the most convenient location to hold this gathering.

Each cow lives in one of N farms, which are connected by N−1 roads, and can reach another farm from any farm. Road i connects farms Ai and Bi with a length of Li. The rally can be held at any of the N farms. In addition, Ci cows live in each cowshed.

When choosing the venue for the gathering, Bessie hopes to maximize convenience (that is, minimize inconvenience). For example, if the Xth farm is selected as the meeting place, its inconvenience is the sum of the distance traveled by each cow in the other cowshed to participate in the meeting (for example, if the distance from farm ii to farm X is 20, then the total distance is Ci ×20). Help Bessie find the most convenient place to hold a big gathering.

Input format

An integer N in the first line.

Lines 2 to N+1: Line i+1 has an integer Ci.

Line N+2 to Line 2N: Line i+N+1 has 3 integers: Ai, Bi and Li.

Output format

One integer per line represents the smallest inconvenience value.

Analysis process:

1. First of all, this is USACO's question
2. It feels like a tree-shaped DP
3. Can Floyd be water
4. It's almost time, check if there are any other problems.


So put a bottom

Insert picture description here

Guess you like

Origin blog.csdn.net/ydsrwex/article/details/113833882