Simple simulation - Toto pick apples (upgrade version)

· Today konjac brain pumping again. . . This question actually transferred over an hour! ! ! ! ? ? ? (I joke funny). . . This is not wrong and that wrong. . . Careless to burst table. . . Desperate konjac. . .

· Konjac I tell you the truth - I really do not want to put this road garbage problem - but in order to keep track of my brain pumping - or put. . .

 

Lowe valley entrance: P1478

·topic:

It is a year when the autumn, Tao Tao home apple trees bear the fruit of n. Tao Tao ran to pick apples, this time she had a centimeter of a chair. When he hands out of reach, he will stand on a chair to try again.

The popularity of the group and NOIp2005 the first question is different: to move stool before Tao Tao, the effort is only a s. Of course, every time I have to pick apples with some effort. Tao Tao to pick up to want to know how many apples before s <0.

Now known apple reaches a height xi n the ground, the height of the chair a, the maximum length of Tao Tao hand straight b, Tao Tao remaining strength s, Tao Tao needs to pick an apple effort yi, seeking to pick up to Tao Tao how many apple.

• Code content:

#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=5005;
int n,s,a,b;
struct node
{
	int c;
	int z;
}x[maxn];
int main()
{
	cin>>n>>s;
	cin>>a>>b;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i].c;
		cin>>x[i].z;
		}
	int h;h=a+b;
	int ans;ans=0;
//核心!!!
	for(int i=n-1;i>=1;i--)
	for(int j=1;j<=i;j++)
	{
		if(x[j].z>x[j+1].z)
		{
			swap(x[j].c,x[j+1].c);
			swap(x[j].z,x[j+1].z);
		}
		}
//结构体排序!!!
	for(int i=1;i<=n;i++)
	{
		if(x[i].c<=h)
		{
			s-=x[i].z;
			if(s<0)break;
			else ans++;
		
		}
	}
		cout<<ans<<endl;
	return 0;
}

Guess you like

Origin www.cnblogs.com/konglingyi/p/11291212.html