程序设计思维与实践 Week10 限时大模拟 (1/2/智能班)

A - 签到题

题目描述

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

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

需要满以下三点条件:

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

现在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

思路

如果某条边能平分,答案就是0,否则就是两个较小的边的乘积。

代码

#include<iostream>
using namespace std;
int main() {
	long long a,b,c;
	long long ans;
	cin>>a>>b>>c;
	long long tmin = min(a,min(b,c));
	long long tmin2;
	if(a%2==0||b%2==0||c%2==0) {
		cout<<0<<endl;
	} else {
		if(tmin==a) {
			tmin2 = min(b,c);
		} else if(tmin==b) {
			tmin2 = min(a,c);
		} else {
			tmin2 = min(a,b);
		}
		cout<<tmin*tmin2;
	}

	return 0;
}

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

题目描述

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组数据。

接下来对于所有可以用来开会的时间段,每一个时间段输出一行。

需要满足如下规则:

  1. 在该时间段的任何时间点,都应该有至少两人在场。
  2. 在该时间段的任何时间点,至多有一位成员缺席。
  3. 该时间段的时间长度至少应该1h。

所有的成员都乐意一天24h进行工作。

举个例子,假如现在TA团队有3位成员,TT、zjm、hrz。

那么这样的时间段是合法的:会议开始之初只有TT和zjm,后来hrz加入了,hrz加入之后TT离开了,此后直到会议结束,hrz和zjm一直在场。

要求:

  1. 输出满足条件的所有的时间段,尽管某一段可能有400年那么长。
  2. 时间点的格式为MM/DD/YYYY hh:mm:ss。
  3. 时间段的输出格式为"appointment possible from T0 to T1",其中T0和T1均应满足时间点的格式。
  4. 严格按照格式进行匹配,如果长度不够则在前面补前导0。
  5. 按时间的先后顺序输出各个时间段。
  6. 如果没有合适的时间段,输出一行"no appointment possible"。
  7. 每组数据末尾须打印额外的一行空行。

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

思路

学长讲的。。。

首先,把所有的时间点映射到一条线段上,对这些线段进行判断即可。

而对于输入的时间格式,将其转化为时间戳就行。

代码

#include<iostream>
#include<vector>
#include<queue>
#include<set>
#define Heap priority_queue
#define ll long long
using namespace std;
int m,n;
long long dtime(long long a,long long b,long long c,long long d,long long e,long long f) {
	long long ts;
	ts = (a - 1800)*360*24*3600 + (b - 1)*30*24*3600 + (c - 1)*24*3600 + d * 3600 + e*60 + f;
	return ts;
}
void stime(ll ts) {
	ll a,b,c,d,e,f;
	ll ret[6];
	ll s = 0;
	ll beichu[6] = {360*24*3600,30*24*3600,24*3600,3600,60,1};
	for(int i=0; i<6; i++) {
		ret[i] = (ts-s)/beichu[i];
		s += ret[i]*beichu[i];
	}
	printf("%02lld/%02lld/%lld %02lld:%02lld:%02lld",ret[1]+1,ret[2]+1,ret[0]+1800,ret[3],ret[4],ret[5]);
}
struct myPair {
	ll a,b;
	myPair() {}
	myPair(ll x,ll y) {
		this->a = x;
		this->b = y;
	}
	bool operator<(myPair m) const {
		if((this->a)!=(m.a)) return (this->a)>(m.a);
		else {
			return (this->b-this->a)<(m.b-m.a);
		}
	}
	void out() const {
		cout<<a<<","<<b<<endl;
	}
};
int main() {
	int T;
//	freopen("in2.txt","r",stdin);
	int ci = 0;
	cin>>T;
	while(T) {
		T--;
		ci++;
		char s[100];
		vector<myPair> Union[20];
		Heap<ll> heap;
		myPair tmp;
		set<ll> st;
		ll start,end;
		vector<ll> v;
		start = dtime(1800,1,1,0,0,0);
		end = dtime(2200,1,1,0,0,0);
		st.insert(start);
		st.insert(end);

		cin>>m;
		for(int i =0; i<m; i++) {
			cin>>n;
			long long a,b,c,d,e,f;
			for(int j=0; j<n; j++) {
				scanf("%lld%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e,&f);
				start = dtime(a,b,c,d,e,f);
				scanf("%lld%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e,&f);
				end = dtime(a,b,c,d,e,f);
				cin.getline(s,100);
				st.insert(start);
				st.insert(end);
				Union[i].push_back(myPair(start,end));
			}
		}

		for(set<ll>::iterator it = st.begin(); it!=st.end(); it++) {
			v.push_back(*it);
//			cout<<*it<<endl;
		}

		int lindex = 0,rindex = 0;
		vector<myPair> ans;
		while(rindex<v.size()) {
			while(1) {
				if(rindex>=v.size()-1) break;
				int tot = 0;
				for(int i=0; i<m; i++) {
					int j = 0;
					for(; j<Union[i].size(); j++) {
						if(v[rindex]>=Union[i][j].a&&v[rindex+1]<=Union[i][j].b) break;
					}
					if(j==Union[i].size()) tot++;
				}
				if(tot>=2&&tot>=m-1) rindex++;
				else break;
			}
//			cout<<rindex<<":"<<v[rindex]<<endl;
			if(v[rindex]-v[lindex]>=3600) ans.push_back(myPair(v[lindex],v[rindex]));
			lindex = rindex + 1;
			while(1){
				if(lindex>=v.size()-1) break;
				int tot = 0;
				for(int i=0; i<m; i++) {
					int j = 0;
					for(; j<Union[i].size(); j++) {
						if(v[lindex]>=Union[i][j].a&&v[lindex+1]<=Union[i][j].b) break;
					}
					if(j==Union[i].size()) tot++;
				}
				if(tot<2||tot<m-1) lindex++;
				else break;
			}
			rindex = lindex;
//			printf("lindex=%d,rindex=%d\na=%lld,b=%lld\n",lindex,rindex,v[lindex],v[rindex]);
		}
		printf("Scenario #%d:\n",ci);
		for(int i=0; i<ans.size(); i++) {
			cout<<"appointment possible from ";
			stime(ans[i].a);
			cout<<" to ";
//			cout<<ans[i].b<<"?"<<endl;
			stime(ans[i].b);
			cout<<endl;
		}
		if(ans.size()==0)cout<<"no appointment possible"<<endl;
		cout<<endl;
	}


	return 0;
}

猜你喜欢

转载自www.cnblogs.com/mopa/p/12934287.html