week10 限时大模拟

A - 签到题

题目描述

TT有一个A×B×C的长方体。这个长方体是由A×B×C个1×1×1的小正方体组成的。

现在TT想给每个小正方体涂上颜色。

需要满以下三点条件:

每个小正方体要么涂成红色,要么涂成蓝色。
所有红色的小正方体组成一个长方体。
所有蓝色的小正方体组成一个长方体。

现在TT想知道红色小正方体的数量和蓝色小正方体的数量的差异。

你需要找到红色正方体的数量与蓝色正方体的数量差值的绝对值的最小值。
即min{|红色正方体数量 - 蓝色正方体数量|}。
输入格式

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

输出格式

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

Simple Input 1

3 3 3

Simple Output 1

9

Simple Input 2

2 2 4

Simple Output 2

0

Simple Input 3

5 3 5

Simple Output 3

15

hint

三组样例如图所示:
在这里插入图片描述
解题思路

水题:这个问题相当于把一个长方体进行切割,分别从三个方向,沿A边B边C边把长方体切割成两部分,使得两部分体积差最小。
体积差最小当然是平分最好,如果不是偶数,直接/2就是最小的,然后找出三个方向里差最小的。

long long int

完整代码

#include<iostream>
#include<cmath>
using namespace std;
long long A, B, C;
long long mm, box1, box2, ans;

int main()
{
	cin>>A>>B>>C;
	mm = A>>1;
	box1 = mm*B*C;
	box2 = (A-mm)*B*C;
	ans = abs(box1-box2);
	
	mm = B>>1;
	box1 = mm*A*C;
	box2 = (B-mm)*A*C;
	if(abs(box1-box2)<ans)	ans = abs(box1-box2);
	
	mm = C>>1;
	box1 = mm*B*A;
	box2 = (C-mm)*B*A;
	if(abs(box1-box2)<ans)	ans=abs(box1-box2);
	
	cout<<ans<<endl;
	return 0;
}

B - 团队聚会

题目描述

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

给出每位助教的各项事情的时间表,你的任务是找出所有可以用来开会的时间段。

输入格式

第一行一个数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天的,数据保证不含有不合法的日期。

注意每件事务的结束时间点也即是该成员可以开始参与开会的时间点。

输出格式

对于每一组数据,首先输出一行"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"。
每组数据末尾须打印额外的一行空行。

Simple 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

Simple 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

解题思路

定义一个结构体记录时间计划数组,重载符号按时间进行排序;
用notime记录没有时间的人数,对时间遍历,如果时间点是一个任务的开始,那么没时间的人数++,如果是一个任务的结束,那么人数- -,判断时间是否能加入vector中;
没有结果的输出,输出no appointment,时间都小于1h也会导致没有输出;用judge判断是否大于一个小时。

完整代码

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdio>
using namespace std;
int T, m, n, cnt, N, kk; 
struct plan
{
	string name;
	int year, mon, day, hour, minu, sec;
	int k;
	bool operator<(const plan &a)const
	{
		if(year != a.year) 	return year < a.year;
		if(mon != a.mon) 	return mon < a.mon;
		if(day != a.day) 	return day < a.day;
		if(hour != a.hour) 	return hour < a.hour;
		if(minu != a.minu) 	return minu < a.minu;
		return sec < a.sec; 
	}
	bool operator<=(const plan &a)const 
	{
		return !(a < *this);
	}
	bool operator!=(const plan &a)const
	{
		if(year != a.year || mon != a.mon || day != a.day
			|| hour != a.hour || minu != a.minu || sec != a.sec)
			return true;
		return false;
	}
}t[10000];

void Printf(plan a)
{
	if(a.mon < 10) 		cout<<"0";
	cout<<a.mon<<"/";
	if(a.day < 10) 		cout<<"0";
	cout<<a.day<<"/";
	cout<<a.year<<" ";
	if(a.hour < 10) 	cout<<"0";
	cout<<a.hour<<":";
	if(a.minu < 10) 	cout<<"0";
	cout<<a.minu<<":";
	if(a.sec < 10) 		cout<<"0";
	cout<<a.sec;
}

vector<plan> p;
void solve()
{
	p.clear();
	bool flag;
	int notime = 0;
	plan st;
	st.year = 1800;		st.mon = 1;		st.day = 1;
	st.hour = 0;		st.minu = 0;	st.sec = 0;
	plan ed; 
	ed.year = 2200;		ed.mon = 1;		ed.day = 1;
	ed.hour = 0;	ed.minu = 0;	ed.sec = 0;
	if(!(t[0] != st))	flag = false;
	else
	{
		p.push_back(st);
		flag = true;
	} 
	plan r;
	for(int i=0;i<=cnt;i++)
	{
		r = t[i];
		while(t[i] <= r && i <= cnt)
		{
			if(t[i].k)	notime++;
			else	notime--;
			i++;
		}
		i--;
		if(flag)
		{
			if((m == 2 && notime > 0) || (m > 2 && notime > 1))
			{
				p.push_back(t[i]);
				flag = false; 
			} 		
		}
		else
		{
			if(!(t[i] != ed)) 	continue;
			if((m > 2 && notime <= 1) || (m == 2 && notime == 0))
			{
				p.push_back(t[i]);
				flag = true;
			}
		}
	}
	if(flag) 	p.push_back(ed);
} 

bool judge(plan a,plan b)
{
	b.hour += 1;
	if(b.hour > 23)
	{
		b.hour -= 24;
		b.day += 1;
	} 
	if(b.day > 30)
	{
		b.day -= 30;
		b.mon += 1;
	}
	if(b.mon > 12)
	{
		b.mon -= 12;
		b.year += 1;
	} 
	if(!(a != b) || b < a)	 return true;
	return false;
}

void print()
{
	for(int i=1;i<p.size();i+=2)
	{
		if(judge(p[i], p[i-1]))
		{
			cout<<"appointment possible from ";
			Printf(p[i-1]);
			cout<<" to ";
			Printf(p[i]);
			cout<<endl;
			kk = 1;
		}
	}
}
int main()
{
	cin>>T;
	string s;
	while(T--)
	{
		cin>>m;
		int mm = m;
		cnt = -1;
		kk = 0;
		while(mm--)
		{
			cin>>n;
			getchar();
			for(int i=0;i<n;i++)
			{
				t[++cnt].k = 1;
				scanf("%d%d%d%d%d%d", &t[cnt].year, &t[cnt].mon, &t[cnt].day,
									&t[cnt].hour, &t[cnt].minu, &t[cnt].sec);
				t[++cnt].k = 0;
				scanf("%d%d%d%d%d%d", &t[cnt].year, &t[cnt].mon, &t[cnt].day,
									&t[cnt].hour, &t[cnt].minu, &t[cnt].sec);
				getline(cin,s);
			}
		} 
		sort(t, t + cnt + 1);
		solve();
		N++;
		cout<<"Scenario #"<<N<<":"<<endl;
		print();
		if(!kk) 	cout<<"no appointment possible"<<endl;
		cout<<endl;
	}
	return 0;
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值