Week10 限时模拟

A - 签到题

TT有一个A×B×C的长方体。这个长方体是由A×B×C个1×1×1的小正方体组成的。
现在TT想给每个小正方体涂上颜色。
需要满以下三点条件:
每个小正方体要么涂成红色,要么涂成蓝色。
所有红色的小正方体组成一个长方体。
所有蓝色的小正方体组成一个长方体。
现在TT想知道红色小正方体的数量和蓝色小正方体的数量的差异。
你需要找到红色正方体的数量与蓝色正方体的数量差值的绝对值的最小值。
即min{|红色正方体数量 - 蓝色正方体数量|}。

Input

输入仅一行,三个数A B C (2≤A,B,C≤10^9)。

Output

输出一个数字。
即差值绝对值的最小值。

Example Input

3 3 3

Example Output

9

题意:
将一个正方体中的小正方体按照一定规则涂上两种颜色,求出两种颜色的小正方体的数目之差。

分析:
先判断A,B和C是否有偶数,有的话直接输出0,否则输出两个较小的数的乘积,唯一要注意的坑,要使用long long。

代码如下:

#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	long long int a, b, c, ans;
	cin >> a >> b >> c;
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0)
		cout << 0;
	else
	{
		if (a >= b && a >= c)
				ans = b * c;
		else if (b >= a && b >= c)
				ans = a * c;
		else if (c >= a && c >= b)
				ans = a * b;
		cout << ans;
	}
	return 0;
}

B - 团 队 聚 会 (不支持C++11)

TA团队每周都会有很多任务,有的可以单独完成,有的则需要所有人聚到一起,开过会之后才能去做。但TA团队的每个成员都有各自的事情,找到所有人都有空的时间段并不是一件容易的事情。
给出每位助教的各项事情的时间表,你的任务是找出所有可以用来开会的时间段。

Input

第一行一个数T(T≤100),表示数据组数。
对于每组数据,第一行一个数m(2 ≤ m ≤ 20),表示TA的数量。
对于每位TA,首先是一个数n(0≤ n≤100),表示该TA的任务数。接下来n行,表示各个任务的信息,格式如下
YYYY MM DD hh mm ss YYYY MM DD hh mm ss “some string here”
每一行描述的信息为:开始时间的年、月、日、时、分、秒;结束时间的年、月、日、时、分、秒,以及一些字符串,描述任务的信息。
数据约定:
所有的数据信息均为固定位数,位数不足的在在前面补前导0,数据之间由空格隔开。
描述信息的字符串中间可能包含空格,且总长度不超过100。
所有的日期时间均在1800年1月1日00:00:00到2200年1月1日00:00:00之间。
为了简化问题,我们假定所有的月份(甚至2月)均是30天的,数据保证不含有不合法的日期。
注意每件事务的结束时间点也即是该成员可以开始参与开会的时间点。

Output

对于每一组数据,首先输出一行"Scenario #i:",i即表明是第i组数据。
接下来对于所有可以用来开会的时间段,每一个时间段输出一行。
需要满足如下规则:
在该时间段的任何时间点,都应该有至少两人在场。
在该时间段的任何时间点,至多有一位成员缺席。
该时间段的时间长度至少应该1h。
所有的成员都乐意一天24h进行工作。
举个例子,假如现在TA团队有3位成员,TT、zjm、hrz。
那么这样的时间段是合法的:会议开始之初只有TT和zjm,后来hrz加入了,hrz加入之后TT离开了,此后直到会议结束,hrz和zjm一直在场。
要求:
输出满足条件的所有的时间段,尽管某一段可能有400年那么长。
时间点的格式为MM/DD/YYYY hh:mm:ss。
时间段的输出格式为"appointment possible from T0 to T1",其中T0和T1均应满足时间点的格式。
严格按照格式进行匹配,如果长度不够则在前面补前导0。
按时间的先后顺序输出各个时间段。
如果没有合适的时间段,输出一行"no appointment possible"。
每组数据末尾须打印额外的一行空行。

Example Input

2
3
3
2020 06 28 15 00 00 2020 06 28 18 00 00 TT study
2020 06 29 10 00 00 2020 06 29 15 00 00 TT solving problems
2020 11 15 15 00 00 2020 11 17 23 00 00 TT play with his magic cat
4
2020 06 25 13 30 00 2020 06 25 15 30 00 hrz play
2020 06 26 13 30 00 2020 06 26 15 30 00 hrz study
2020 06 29 13 00 00 2020 06 29 15 00 00 hrz debug
2020 06 30 13 00 00 2020 06 30 15 00 00 hrz play
1
2020 06 01 00 00 00 2020 06 29 18 00 00 zjm study
2
1
1800 01 01 00 00 00 2200 01 01 00 00 00 sleep
0

Example Output

Scenario #1:
appointment possible from 01/01/1800 00:00:00 to 06/25/2020 13:30:00
appointment possible from 06/25/2020 15:30:00 to 06/26/2020 13:30:00
appointment possible from 06/26/2020 15:30:00 to 06/28/2020 15:00:00
appointment possible from 06/28/2020 18:00:00 to 06/29/2020 10:00:00
appointment possible from 06/29/2020 15:00:00 to 01/01/2200 00:00:00
Scenario #2:
no appointment possible

题意:
一个区间问题,求出助教们的共同时间。

分析:
一道很复杂的题,尤其是对数据的处理。这里将时间节点这一数据类型用c++里的结构体来表示,为了后面处理起来方便,在结构体内重载了= < > <= >= == !=这几个运算符:

struct node_time
{
	int year, month, day, hour, minute, second;
	node_time operator = (const node_time& b)
	{
		year = b.year; month = b.month; day = b.day;
		hour = b.hour; minute = b.minute; second = b.second;
	}
	bool operator < (const node_time& b)const
	{
		if (year != b.year)return year < b.year;
		if (month != b.month)return month < b.month;
		if (day != b.day)return day < b.day;
		if (hour != b.hour)return hour < b.hour;
		if (minute != b.minute)return minute < b.minute;
		return second < b.second;
	}
	bool operator > (const node_time& b)const { return b < *this; }
	bool operator <= (const node_time& b)const { return !(b < *this); }
	bool operator >= (const node_time& b)const { return !(*this < b); }
	bool operator == (const node_time& b)const { return !(b < *this || *this < b); }
	bool operator != (const node_time& b)const { return b < *this || *this < b; }
}s[25][150], e[25][151], t[4080];

主要的算法思路比较简单,将所有出现的时间节点全部投射到时间轴上,按时间顺序枚举所有的小区间,对于每个小区间,判断其是否合法。对于前后连续的合法区间,对这些区间进行合并。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

struct node_time
{
	int year, month, day, hour, minute, second;
	node_time operator = (const node_time& b)
	{
		year = b.year; month = b.month; day = b.day;
		hour = b.hour; minute = b.minute; second = b.second;
	}
	bool operator < (const node_time& b)const
	{
		if (year != b.year)return year < b.year;
		if (month != b.month)return month < b.month;
		if (day != b.day)return day < b.day;
		if (hour != b.hour)return hour < b.hour;
		if (minute != b.minute)return minute < b.minute;
		return second < b.second;
	}
	bool operator > (const node_time& b)const { return b < *this; }
	bool operator <= (const node_time& b)const { return !(b < *this); }
	bool operator >= (const node_time& b)const { return !(*this < b); }
	bool operator == (const node_time& b)const { return !(b < *this || *this < b); }
	bool operator != (const node_time& b)const { return b < *this || *this < b; }
}s[25][150], e[25][151], t[4080];

int num[25], cnt, n;
char c[1001];
node_time t_begin, t_end;          //起始时间和终止时间 
bool can_left(int pos);           //验证是否可作选取区段的左端点 
bool can_right(int pos);
bool can_len(int left, int right); //验证时间是否大于1小时 
bool ok = 0;
void check(int left, int right);  //选好后验证并输出 
void print(int l);       //输出函数 

bool can_left(int pos)
{
	if (pos == cnt)return 0;
	int tot = 0;
	for (int i = 1; i <= n; i++)
	{
		if (num[i] == 0) { tot++; continue; }
		if (t[pos] < s[i][1])
		{
			tot++;
			continue;
		}
		if (t[pos] >= e[i][num[i]] && t[pos] < t_end)
		{
			tot++;
			continue;
		}
		for (int j = 1; j <= num[i]; j++)
		{
			if (t[pos] >= s[i][j] && t[pos] < e[i][j])break;
			if (j + 1 <= num[i] && t[pos] >= e[i][j] && t[pos] < s[i][j + 1]) { tot++; break; }
		}
	}
	if (tot >= 2 && tot >= n - 1)return 1;
	return 0;
}

bool can_right(int pos)
{
	if (pos == 0)return 0;
	int tot = 0;
	for (int i = 1; i <= n; i++)
	{
		if (num[i] == 0) { tot++; continue; }
		if (t[pos] <= s[i][1] && t[pos] > t_begin) { tot++; continue; }
		if (t[pos] > e[i][num[i]]) { tot++; continue; }
		if (t[pos] == e[i][num[i]])continue;
		for (int j = 1; j <= num[i]; j++)
		{
			if (t[pos] > s[i][j] && t[pos] <= e[i][j])break;
			if (j + 1 <= num[i] && t[pos] > e[i][j] && t[pos] <= s[i][j + 1]) { tot++; break; }
		}
	}
	if (tot >= 2 && tot >= n - 1)return 1;
	return 0;
}

bool can_len(int left, int right)
{
	node_time l, r;
	l = t[left]; r = t[right];
	if (r.year - l.year >= 2)return 1;
	r.month += (r.year - l.year) * 12;
	if (r.month - l.month >= 2)return 1;
	r.day += (r.month - l.month) * 30;
	if (r.day - l.day >= 2)return 1;
	r.hour += (r.day - l.day) * 24;
	if (r.hour - l.hour >= 2)return 1;
	r.minute += (r.hour - l.hour) * 60;
	r.second += (r.minute - l.minute) * 60;
	if (r.second - l.second >= 3600)return 1;
	return 0;
}

void check(int l, int r)
{
	if (!can_len(l, r))return;
	ok = 1;
	printf("appointment possible from ");
	print(l);
	printf(" to ");
	print(r);
	printf("\n");
}

void print(int l)
{
	if (t[l].month < 10)printf("0");
	printf("%d/", t[l].month);
	if (t[l].day < 10)printf("0");
	printf("%d/", t[l].day);
	printf("%d ", t[l].year);
	if (t[l].hour < 10)printf("0");
	printf("%d:", t[l].hour);
	if (t[l].minute < 10)printf("0");
	printf("%d:", t[l].minute);
	if (t[l].second < 10)printf("0");
	printf("%d", t[l].second);
}

int main()
{
	t_begin.year = 1800; t_begin.month = 1;
	t_begin.day = 1; t_begin.hour = 0;
	t_begin.minute = 0; t_begin.second = 0;
	t_end.year = 2200; t_end.month = 1;
	t_end.day = 1; t_end.hour = 0;
	t_end.minute = 0; t_end.second = 0;
	int _; scanf("%d", &_);
	for (int sce = 1; sce <= _; sce++)
	{
		ok = 0;
		memset(num, 0, sizeof(num));
		memset(s, 0, sizeof(s));
		memset(e, 0, sizeof(e));
		memset(t, 0, sizeof(t));
		cnt = 0;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++)
		{
			scanf("%d", &num[i]);
			for (int j = 1; j <= num[i]; j++)
			{
				scanf("%d%d%d%d%d%d", &s[i][j].year, &s[i][j].month, &s[i][j].day, &s[i][j].hour, &s[i][j].minute, &s[i][j].second);
				scanf("%d%d%d%d%d%d", &e[i][j].year, &e[i][j].month, &e[i][j].day, &e[i][j].hour, &e[i][j].minute, &e[i][j].second);
				t[++cnt] = s[i][j];
				t[++cnt] = e[i][j];
				gets(c);                    //行末那些没用的活动名称 
			}
		}
		t[++cnt] = t_begin;
		t[++cnt] = t_end;
		sort(t + 1, t + 1 + cnt);             //时间节点排序 
		int left = 1, right = 1;
		printf("Scenario #%d:\n", sce);
		while (left <= cnt && right <= cnt)
		{
			right++; if (right > cnt)break;
			while (right <= cnt && can_right(right))right++;
			right--;               //类似滑动的过程 
			check(left, right);
			left = right + 1;
			while (left <= cnt && !can_left(left))left++;
			right = left;
		}
		if (ok == 0)printf("no appointment possible\n");
		printf("\n");
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【优质项目推荐】 1、项目代码均经过严格本地测试,运行OK,确保功能稳定后才上传平台。可放心下载并立即投入使用,若遇到任何使用问题,随欢迎私信反馈与沟通,博主会第一间回复。 2、项目适用于计算机相关专业(如计科、信息安全、数据科学、人工智能、通信、物联网、自动化、电子信息等)的在校学生、专业教师,或企业员工,小白入门等都适用。 3、该项目不仅具有很高的学习借鉴价值,对于初学者来说,也是入门进阶的绝佳选择;当然也可以直接用于 毕设、课设、期末大作业或项目初期立项演示等。 3、开放创新:如果您有一定基础,且热爱探索钻研,可以在此代码基础上二次开发,进行修改、扩展,创造出属于自己的独特应用。 欢迎下载使用优质资源!欢迎借鉴使用,并欢迎学习交流,共同探索编程的无穷魅力! 基于业务逻辑生成特征变量python实现源码+数据集+超详细注释.zip基于业务逻辑生成特征变量python实现源码+数据集+超详细注释.zip基于业务逻辑生成特征变量python实现源码+数据集+超详细注释.zip基于业务逻辑生成特征变量python实现源码+数据集+超详细注释.zip基于业务逻辑生成特征变量python实现源码+数据集+超详细注释.zip基于业务逻辑生成特征变量python实现源码+数据集+超详细注释.zip基于业务逻辑生成特征变量python实现源码+数据集+超详细注释.zip 基于业务逻辑生成特征变量python实现源码+数据集+超详细注释.zip 基于业务逻辑生成特征变量python实现源码+数据集+超详细注释.zip
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值