UESTC第十届ACM趣味程序设计竞赛第三场(正式赛)个人解题记录

网址https://lutece.xyz/contest/detail/8/

以前都没打过比赛,也没认真学过算法,这次算是一个开始吧,也许我就在这条路上越走越远也说不定x)

B 摩天乐

没什么好说的,一开始没考虑同楼层的情况导致WA

#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int T;
	long n, m, L, R, a, b, c, d;
	cin >> T;
	for (int i = 0; i < T; ++i) { cin >> n >> m >> L >> R >> a >> b >> c >> d;
		if (b > L && b < R)
		{
			if (a != c)
			{
				cout << abs(a - c) + min( ( abs(b - L) + abs(d - L) ), ( abs(b - R) + abs(d - R))) << endl;
			}
			else
			{
				cout << abs(b - d) << endl;
			}
		}
		else
		{
			cout << abs(a - c) + abs(b - d) << endl;
		}
	}
	return 0;
}

D 强哥打电话

这题我比较傻逼,没有想到转化成秒,然后傻傻的写了struct和对应的加法和比较函数

写了一个半小时左右吧,写到自闭,交上去后WA,第四个点过不去

然后就不想写了

比赛结束后,在群里聊天才发现,第四个点的N是0。题目条件有说,但是我没注意

……改了一下代码,加了个0的特例,交上去,AC

自闭

代码:

#include <stdio.h>
struct time
{
	int h;
	int m;
	int s;
};
time plus(time a, time b)
{
	time res;
	res.h = a.h + b.h;
	res.m = a.m + b.m;
	res.s = a.s + b.s;
	if (res.s >= 60)
	{
		res.s -= 60;
		res.m++;
	}
	if (res.m >= 60)
	{
		res.m -= 60;
		res.h++;
	}
	return res;
}
int compare(time a, time b)
{
	if (a.h > b.h)
	{
		return 1;
	}
	else if (a.h < b.h)
	{
		return -1;
	}
	else
	{
		if (a.m > b.m)
		{
			return 1;
		}
		else if (a.m < b.m)
		{
			return -1;
		}
		else
		{
			if (a.s > b.s)
			{
				return 1;
			}
			else if (a.s < b.s)
			{
				return -1;
			}
			else
			{
				return 0;
			}
		}
	}
}
int main()
{
	int N;
	time time1[20];
	time time2[20];
	time stime, gap, wait;
	int yesorno = 1;
	time what;
	time day;
	day.h = 23; day.m = 59; day.s = 59;
	scanf("%d0", &N);
	for (int i = 0; i < N; ++i)
	{
		scanf("%d:%d:%d", &time1[i].h, &time1[i].m, &time1[i].s);
		scanf("%d:%d:%d", &time2[i].h, &time2[i].m, &time2[i].s);
	}
	scanf("%d:%d:%d", &stime.h, &stime.m, &stime.s);
	scanf("%d:%d:%d", &gap.h, &gap.m, &gap.s);
	scanf("%d:%d:%d", &wait.h, &wait.m, &wait.s);
	what = stime;
	for (int i1 = 0; i1 < N; ++i1)
	{
		if (compare(what, time1[i1]) == -1)
		{
			yesorno = 0; break;
		}
		else
		{
			while (compare(time2[i1], plus(what, wait)) == 1)
			{
				what = plus(what, gap);
			}
			if (compare(what, day) == 1)break;
			if (i1 < N - 1)
			{
				if (compare(what, time1[i1 + 1]) == 1 || compare(what, time1[i1 + 1]) == 0)continue;
				if (compare(what, time2[i1]) == 1)
				{
					yesorno = 0;
					break;
				}
				else
				{
					what = time2[i1];
					yesorno = 0;
					break;
				}
			}
			else
			{
				if (compare(what, time2[i1]) == 1)
				{
					yesorno = 0;
					break;
				}
				else
				{
					what = time2[i1];
					yesorno = 0;
					break;
				}
			}
		}
	}
	if (N == 0)
	{
		yesorno = 0;
		what = stime;
	}
	if (yesorno == 1)
	{
		printf("%d", -yesorno);
	}
	else
	{
		printf("%02d:%02d:%02d", what.h, what.m, what.s);
	}
	return 0;
}

A 秦皇炒饭

没做出来,当时看题目确实没想到这么简单,真的是智商捉急了,后来看了题解

偶数都要单独一组

代码:

#include<stdio.h>
int main()
{
    long a;
    scanf("%d",&a);
    if(a>1)a /=2;
    for(int i=0;i<a;i++)
    {
        printf("Wed.Strong");
    }
    return 0;
}

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注