2020 年百度之星·程序设计大赛 - 初赛三

1001 Discount

#include
using namespace std;

int t,n;
double a,b;

int main()
{
	scanf("%d",&t);
	while(t--)
	{
		double ans = 0;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			scanf("%lf%lf",&a,&b);
			ans = max(ans, (1 - b) / (a + 1 - b));
		}
		printf("%.5lf\n",ans);
	}
	return 0;
}

1002 Game

#include
using namespace std;

int t;
double a;

int main()
{
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lf",&a);
		if(a <= 1.0) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

1003 Permutation

#include
using namespace std;

int t;
long long n,m;

int main()
{
	scanf("%d",&t);
	while(t--)
	{
		long long ans = 0;
		scanf("%lld%lld",&n,&m);
		if(n == 1)
		{
			printf("0\n");
			continue;
		}
		if(m >= n / 2) ans = 1ll * (n - 1) * n / 2;
		else
		{
			long long temp1,temp2;
			temp1 = temp2 = n;
			temp2--;
			temp1 -= 2 * m;
			ans = 1ll * (temp1 + temp2) * 2 * m / 2;
		}
		printf("%lld\n",ans);
	}
	return 0;
}

1004 Intersection

分析一下左车道的车先到右车道再进入东边是可以节省时间的,所以分析一下什么时候左车道上的车可以进入右车道;在左车道的时间大于右车道的时间时,可以在不浪费时间的情况下,让右车道的车等待左车道的车先拐弯。

#include
using namespace std;

int t,n;
int car[3][100007];
int ta,tb;
vector<int> b;

int main()
{
	scanf("%d",&t);
	while(t--)
	{
		//init()
		memset(car,0,sizeof(car));
		b.clear();
		ta = tb = 0;
		
		scanf("%d",&n);
		int x,y;
		for(int i=1;i<=n;i++)
		{
			scanf("%d%d",&x,&y);
			car[x][y] = 1;
			if(x == 2)
			{
				b.push_back(y);
				tb = max(tb, y + 3);
			}
			else
			{
				ta = max(ta, y + 1);
			}
		}
		for(int i=0;i<b.size();i++)
		{
			int yy = b[i];
			if(car[1][yy + 1] == 0) tb--;
			else
			{
				if(tb > ta) tb--, ta++;
			}
		}
		int ans = max(ta, tb);
		printf("%d\n",ans);
	}
	return 0;
}

1007 Fight

这题数据不大,可以用暴力

#include
using namespace std;

int t;
int x,y,z;
int ans;
int a,b,c,aa,bb,cc;

int main()
{
	scanf("%d",&t);
	while(t--)
	{
		int i,j;
		ans = 999999999;
		scanf("%d%d%d",&x,&y,&z);
		for(i=0;i<=1000;i++)
		{
			a = 1000 - i * y;
			b = 1000 - i * x;
			for(j=0;j<=1000;j++)
			{
				bb = cc = 9999999;
				int tb = 0,tc;
				aa = 1000 - i * y - j * z;
				c = 1000 - j * x;
				if(b > 0 && c > 0)
				{
					if(b % z == 0) tb = b / z;
					else tb = b / z + 1;
					if(c % y == 0) tc = c / y;
					else tc = c / y + 1;
					tb = min(tb, tc);
					bb = 1000 - i * x - tb * z;
					cc = 1000 - j * x - tb * y;
				}
				else bb = b, cc = c;
				if((aa <= 0) + (bb <= 0) + (cc <= 0) >= 2) ans = min(ans, i + j + tb);
				if(aa <= 0 || c <= 0) break;
			}
			if(a <= 0 || b <= 0) break;
		}
		printf("%d\n",ans);
	}
	return 0;
}

你可能感兴趣的:(题解,程序设计,算法,c语言,c++)