程设第十周模拟

A - 签到题

问题描述

有一个A×B×C的长方体。这个长方体是由A×B×C个1×1×1的小正方体组成的。
现在想给每个小正方体涂上颜色。
需要满以下三点条件:
(1)每个小正方体要么涂成红色,要么涂成蓝色。
(2)所有红色的小正方体组成一个长方体。
(3)所有蓝色的小正方体组成一个长方体。
现在求红色小正方体的数量和蓝色小正方体的数量的差异。

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

Input

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

Output

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

思路

如果可以平分,输出0,不可以平分,输出最小的面。

注意范围,用long long。

代码

#include
#include

using namespace std;

int main()
{
	long long a[10];
	for (int i=0;i<3;i++)
		cin>>a[i];
	for (int i=0;i<3;i++)
	{
		if (a[i]%2==0)
		{
			cout<<0<<endl;
			return 0;
		}
	}
	sort(a,a+3);
	long long ans=a[0]*a[1]; 
	cout<<ans<<endl;
	
	return 0; 
} 

B - 团 队 聚 会

问题描述

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组数据。
接下来对于所有可以用来开会的时间段,每一个时间段输出一行。

需要满足如下规则:
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.每组数据末尾须打印额外的一行空行。

思路

首先对时间进行一个处理,因为范围太大,从1800-2200,400年,如果精确到秒那么时间会爆掉,然后观察数据范围发现,20个TA,每个TA100个任务,所以共2000个任务,4000个时间点,那么我们将时间点按大小排序,4000个时间变成1-4000这4000个数,然后我们直接开一个数组a,a[i]用来存储在第(i-1)~i这个时间段有a[i]个助教在工作,然后扫一遍数组找出合法时间段即可。

代码

#include
#include
#include
#include
#include

using namespace std;

struct time
{
	int YY,MM,DD,hh,mm,ss;
	
	bool operator < (const time & x)
	{ 
		if (YY!=x.YY)
			return YY<x.YY;
		if (MM!=x.MM)
			return MM<x.MM;
		if (DD!=x.DD)
			return DD<x.DD;
		if (hh!=x.hh)
			return hh<x.hh;
		if (mm!=x.mm)
			return mm<x.mm;
		if (ss!=x.ss)
			return ss<x.ss;
	}
	
	bool operator == (const time & x)
	{ 
		if (YY==x.YY && MM==x.MM && DD==x.DD && hh==x.hh && mm==x.mm && ss==x.ss)
			return true;
		return false;
	}
	
};

struct timesum
{
	time x;
	int y;
	bool operator < (const timesum &da)
	{
		if (x==da.x)
			return y<da.y;
		return x<da.x;
	}
};

void print(int x)
{
	if (x<10)
		printf("0%d",x);
	else
		printf("%d",x);
}

int o;

void pan(time x,time y)
{
	time ans;
	ans.YY=y.YY-x.YY;
	ans.MM=y.MM-x.MM;
	ans.DD=y.DD-x.DD;
	ans.hh=y.hh-x.hh;
	ans.mm=y.mm-x.mm;
	ans.ss=y.ss-x.ss;
	if (ans.ss<0)
	{
		ans.ss=ans.ss+60;
		ans.mm--;
	} 
	if (ans.mm<0)
	{
		ans.mm=ans.mm+60;
		ans.hh--;
	}
	if (ans.hh<0)
	{
		ans.hh=ans.hh+24;
		ans.DD--;
	}
	if (ans.DD<0)
	{
		ans.DD=ans.DD+30;
		ans.MM--;
	}
	if (ans.MM<0)
	{
		ans.MM=ans.MM+12;
		ans.YY--;
	}
	if (ans.YY<0)
		return;
	if (ans.YY>0 || ans.MM>0 || ans.DD>0 || ans.hh>0)
	{
		o++; 
		printf("appointment possible from ");
		print(x.MM); printf("/");
		print(x.DD); printf("/");
		print(x.YY); printf(" ");
		print(x.hh); printf(":");
		print(x.mm); printf(":");
		print(x.ss); printf(" to ");
		print(y.MM); printf("/");
		print(y.DD); printf("/");
		print(y.YY); printf(" ");
		print(y.hh); printf(":");
		print(y.mm); printf(":");
		print(y.ss); printf("\n");
	}
}

timesum a[5050];
int b[10010];
int c[10010];

void run()
{
	int n,m;
	time begin,end;
	begin.YY=1800; begin.MM=1; begin.DD=1; begin.hh=0; begin.mm=0; begin.ss=0;
	end.YY=2200; end.MM=1; end.DD=1; end.hh=0; end.mm=0; end.ss=0;
	string s; 
	int tot=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&m);
		for (int j=0;j<m;j++)
		{
			scanf("%d %d %d %d %d %d",&a[tot].x.YY,&a[tot].x.MM,&a[tot].x.DD,&a[tot].x.hh,&a[tot].x.mm,&a[tot].x.ss);
			a[tot].y=tot;
			tot++;
			scanf("%d %d %d %d %d %d",&a[tot].x.YY,&a[tot].x.MM,&a[tot].x.DD,&a[tot].x.hh,&a[tot].x.mm,&a[tot].x.ss);
			a[tot].y=tot;
			tot++;
			if (a[tot-2].x==a[tot-1].x)	tot=tot-2;
			getline(cin,s,'\n');
		}
	}
	sort(a,a+tot);  
	for (int i=0;i<tot;i++)
		b[a[i].y]=i;
	for (int i=0;i<10000;i++)
		c[i]=0;
	for (int i=0;i<tot/2;i++)
		for (int j=b[i*2]+1;j<=b[i*2+1];j++)
			c[j]++;
	o=0;
	if (n==2)
	{
		for (int r=0;r<tot;r++)
		{
			if (c[r]>0)
			{
				pan(begin,a[r-1].x);
				begin=a[r].x;
			}
		}
		pan(begin,end);
		if (o==0)
			printf("no appointment possible\n");
		return;
	}
	for (int r=0;r<tot;r++)
	{
		if (c[r]>1)
		{
			pan(begin,a[r-1].x);
			begin=a[r].x;
		}
	}
	pan(begin,end);
	if (o==0) 
		printf("no appointment possible\n");
		
	return;
}

int main()
{
	int t;
	cin>>t;
	for (int i=1;i<=t;i++)
	{
		printf("Scenario #%d:\n",i);
		run();
		printf("\n");
	}
		
	return 0;
} 

你可能感兴趣的:(程设第十周模拟)