Week 10 大模拟

A - 签到题

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

输入

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

输出

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

样例输入

3 3 3

样例输出

9

思路

综述

简单的逻辑思维题;
可以这样解决,找出整个长方体,最小的面。则这一个面的小正方体的个数即为答案;
因为两种颜色的正方体需要在一块,然后两种颜色差的绝对值需要最小,所以自然想到可以如上处理;

代码

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

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一直在场。
要求:
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、每组数据末尾须打印额外的一行空行。

样例输入

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

样例输出

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

思路

综述

重点:可以开会的时间段的两端时刻一定是助教的任务开始或结束时刻 或者是1800年1月1日00:00:00或者2200年1月1日00:00:00
所以,只需要摘出上面提到的所有时刻,排序,对紧挨着的两个时刻做一下判断,如果可以开会,并且大于等于1h,则打标记入数组;
对可以开会的时间段进行合并(即可能两个时间段是可以合并的,比如2020年1月1日18:00:00到2020年1月1日19:00:00
和2020年1月1日19:00:00 到 2020年1月1日23:00:00)这两个时间段是可以合并的;

变量

node结构体:存时间节点

    int year;
    int month;
    int day;
    int hour;
    int mins;
    int second;

TA结构体,存助教个体:

    int tsk_num;//任务数量
    vector<node> start_time;//第i个任务开始时间
    vector<node> end_time;//第i个任务结束时间

time_segment结构体:
存时间段

    node start_time;
    node end_time;

总结

大模拟题,采用面向对象的程序设计理念较为简单,因为面向对象,则较为清晰理清楚其中的过程;

最后遇到的坑

开始的思路不大对:一开始是先判断的某一个时间段是否满足1h,如果不满足直接跳过,殊不知,该时间段虽然不满足1h,但是可能与后面的时间段合并就可以满足,并且可以开会这样出锅;
最后修改后:如果遇到一个小于1h的时间段,就和后面的合并,判断是否满足1h并且可以开会,其实这样是不合理的,因为再往后可能还会继续合并,这样逻辑就非常混乱,遂先判断能否开会,然后小段合并,之后再判断是否能够满足1h

printf用于输出

好用,%02d表示int数据得是两位,否则前面补’0’,这样似乎专门为这种类型数据量身定做的一样。

 printf("%02d/%02d/%04d %02d:%02d:%02d\n",se.end_time.month,se.end_time.day,se.end_time.year,se.end_time.hour,se.end_time.mins,se.end_time.second);
        }

代码

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#define ll long long

using namespace std;
int T;
int n, m;
int print_num=1;
struct node
{
    int year;
    int month;
    int day;
    int hour;
    int mins;
    int second;
	
	node(){
		
	}
	
    node(int y, int m1, int d, int h, int m2, int second) : year(y), month(m1), day(d), hour(h), mins(m2), second(second) {}
	 
    void operator = (const node &P) 
    {
        year = P.year;
        month = P.month;
        day = P.day;
        hour = P.hour;
        mins = P.mins;
        second = P.second;
    }

    bool operator < (const node &P) const
    {
        if (year != P.year)
            return year < P.year;
        if (month != P.month)
            return month < P.month;
        if (day != P.day)
            return day < P.day;
        if (hour != P.hour)
            return hour < P.hour;
        if (mins != P.mins)
            return mins < P.mins;
        if (second != P.second)
            return second < P.second;
        return false;
    }
    bool operator > (const node &P) const
    {
        return P < *this;
    }
    bool operator <= (const node &P) const
    {
        return !(P < *this);
    }
    bool operator>=(const node &P) const
    {
        return !(*this < P);
    }
    bool operator == (const node &P) const
    {
        return !(*this < P || P < *this);
    }
};

struct TA
{
    int tsk_num;
    vector<node> start_time;
    vector<node> end_time;
    TA()
    {
        tsk_num = 0;
    }
};

struct time_segment
{
    node start_time;
    node end_time;
    bool operator < (const time_segment &P)const{
		if(!(start_time == P.start_time)){
			return start_time < P.start_time;
		}else{
			return true;
		}
	}
};

vector<TA> TAs;

vector<node> times;
vector<time_segment> meet_bar;
vector<time_segment> print_can;
bool flag;

bool onehour(node nd1, node nd2)
{
    ll start_second =(ll) (nd1.year) * 12 * 30 * 24 * 60 * 60 + (ll)nd1.month * 30 * 24 * 60 * 60 + (ll)nd1.day * 24 * 60 * 60 + (ll)nd1.hour * 3600 + (ll)nd1.mins * 60 + (ll)nd1.second;
    ll end_second =(ll) nd2.year * 12 * 30 * 24 * 60 * 60 + (ll)nd2.month * 30 * 24 * 60 * 60 + (ll)nd2.day * 24 * 60 * 60 + (ll)nd2.hour * 3600 + (ll)nd2.mins * 60 + (ll)nd2.second;
    if (end_second - start_second >= 3600)//
        return true;
    return false;
}

bool canmeet(node nd1, node nd2)
{
    int absence = 0;
    for (int i = 0; i < TAs.size(); i++)
    {
        for(int j=0;j<TAs[i].tsk_num;j++){

            if(nd1 >= TAs[i].start_time[j] && nd2 <= TAs[i].end_time[j]){
            	absence++;
            	break;
			}
        }
    }

    if(absence>=2)return false;
    if(TAs.size()<=1)return false;
    if(TAs.size()==2 && absence==1){
    	return false;
	} 

    return true;
}

void merge(){
    if(meet_bar.size() == 0){
        flag=false;
        return ;
    }
    flag = true;
    //meet_bar
    // 0  1 
    node nd1;
    node nd2;
    nd1 = meet_bar[0].start_time;
    nd2 = meet_bar[0].end_time;
    for(int i=1;i<meet_bar.size();i++){
        if(meet_bar[i].start_time == nd2){
            nd2 = meet_bar[i].end_time;
            continue;
        }else{
        	   
            time_segment se;
            se.start_time = nd1;
            se.end_time = nd2;
            print_can.push_back(se);
            nd1 = meet_bar[i].start_time;
            nd2 = meet_bar[i].end_time;
        }
    }
    //处理最后一段
    time_segment se;
    se.start_time = nd1;
    se.end_time = nd2;
    print_can.push_back(se);
}

void calc()
{
    //开头和结束
    node nd1(1800, 1, 1, 0, 0, 0);
    node nd2(2200, 1, 1, 0, 0, 0);
    times.push_back(nd1);
	times.push_back(nd2);

	//去重
    sort(times.begin(), times.end());
    times.erase(unique(times.begin(), times.end()), times.end());

    sort(times.begin(), times.end());
    nd1 = times[0];

    for (int i = 1; i < times.size(); i++)
    {
        nd2 = times[i];

        if (canmeet(nd1, nd2))
        {
            time_segment t_s;
            t_s.start_time = nd1;
            t_s.end_time = nd2;
        
            meet_bar.push_back(t_s);
        }
        nd1 = nd2;
    }
    //重复的时间合并
    merge();
}
//0  1
void output(){
    printf("Scenario #%d:\n",print_num);
    print_num++;
    if(!flag){
        printf("no appointment possible\n");
        printf("\n");
        return;
    }else{
    	bool flag2 = false;
    	sort(print_can.begin(),print_can.end());
        for(int i=0;i<print_can.size();i++){
            time_segment se;
            se = print_can[i];
            if(!onehour(se.start_time,se.end_time)){
            	continue;
			}else{
				flag2 = true;
			}
			
			printf("appointment possible from %02d/%02d/%04d %02d:%02d:%02d to ",se.start_time.month,se.start_time.day,se.start_time.year,se.start_time.hour,se.start_time.mins,se.start_time.second);
            printf("%02d/%02d/%04d %02d:%02d:%02d\n",se.end_time.month,se.end_time.day,se.end_time.year,se.end_time.hour,se.end_time.mins,se.end_time.second);
        }
        if(!flag2){
		    printf("no appointment possible\n");				
		}
		printf("\n");
    }
}

void work()
{
    scanf("%d", &m);
    while (m--)
    {
        TA per;
        node start_time;
        node last_time;
        string s;
        scanf("%d", &per.tsk_num);
        for (int i = 0; i < per.tsk_num; i++)
        {
            scanf("%d%d%d%d%d%d", &start_time.year, &start_time.month, &start_time.day, &start_time.hour, &start_time.mins, &start_time.second);
            scanf("%d%d%d%d%d%d", &last_time.year, &last_time.month, &last_time.day, &last_time.hour, &last_time.mins, &last_time.second);
			char ch;
			getline(cin , s);
            per.start_time.push_back(start_time);
            per.end_time.push_back(last_time);
            
            times.push_back(start_time);
            times.push_back(last_time);
        }
        TAs.push_back(per);
    }
    calc();
    output();
}

void init()
{
    TAs.clear();
    meet_bar.clear();
    print_can.clear();
    times.clear(); 
    flag = true;
}

int main()
{
    scanf("%d", &T);
    while (T--){
    	init();
    	work();
	}
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值