GCJ2017R1C B. Parenting Partnering

题目大意

两个基友有了宝宝,每人每天照顾宝宝720mins,同时每个人有一些activity要脱身参加,求最小换班次数。

简要题解

dp,设f[i][j][2][2]表示一个照看i分钟,另一个照看j分钟,一开始是谁在看,现在是谁在看的最小换班次数,转移就枚举前两维推就好。

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

const int MAXN = 733;
int f[MAXN][MAXN][2][2];
int act[MAXN*2];

void upd(int &a, int b) {
    if (b < a) a = b;
}

int main() {
    freopen("B.in", "r", stdin);
    freopen("B.out", "w", stdout);
    int T; cin >> T;
    for (int kase = 1; kase <= T; ++kase) {
        int Ac, Aj; cin >> Ac >> Aj;
        memset(act, 0, sizeof act);
        for (int i = 0; i < Ac; ++i) {
            int c, d; cin >> c >> d;
            for (int j = c + 1; j <= d; ++j)
                act[j] = 1;
        }
        for (int i = 0; i < Aj; ++i) {
            int c, d; cin >> c >> d;
            for (int j = c + 1; j <= d; ++j)
                act[j] = 2;
        }
        memset(f, 0x3f, sizeof f);
        f[0][0][0][0] = f[0][0][1][1] = 0;
        f[0][0][0][1] = f[0][0][1][0] = 1;
        for (int i = 1; i <= 1440; ++i) {
            for (int j = 0; j <= min(i, 720); ++j) {
                int k = i - j;
                if (k > 720) continue;
                //    cout << i << ‘ ‘ << k << ‘ ‘ << j << endl;
                if (act[i] == 1 && k >= 1) {
                    upd(f[k][j][0][0], f[k - 1][j][0][1] + 1);
                    upd(f[k][j][0][0], f[k - 1][j][0][0]);
                    upd(f[k][j][1][0], f[k - 1][j][1][1] + 1);
                    upd(f[k][j][1][0], f[k - 1][j][1][0]);
                }
                if (act[i] == 2 && j >= 1) {
                    upd(f[k][j][0][1], f[k][j - 1][0][1]);
                    upd(f[k][j][0][1], f[k][j - 1][0][0] + 1);
                    upd(f[k][j][1][1], f[k][j - 1][1][1]);
                    upd(f[k][j][1][1], f[k][j - 1][1][0] + 1);
                }
                if (act[i] == 0) {
                    if (k >= 1) {
                        upd(f[k][j][0][0], f[k - 1][j][0][0]);
                        upd(f[k][j][0][0], f[k - 1][j][0][1] + 1);
                        upd(f[k][j][1][0], f[k - 1][j][1][0]);
                        upd(f[k][j][1][0], f[k - 1][j][1][1] + 1);
                    }
                    if (j >= 1) {
                        upd(f[k][j][0][1], f[k][j - 1][0][0] + 1);
                        upd(f[k][j][0][1], f[k][j - 1][0][1]);
                        upd(f[k][j][1][1], f[k][j - 1][1][0] + 1);
                        upd(f[k][j][1][1], f[k][j - 1][1][1]);
                    }
                }
            }
        }
        int ans = 0x3f3f3f3f;
        ans = min(ans, f[720][720][0][0]);
        ans = min(ans, f[720][720][1][1]);
        ans = min(ans, f[720][720][1][0] + 1);
        ans = min(ans, f[720][720][0][1] + 1);
        cout << "Case #" << kase << ": " << ans << endl;
    }

    return 0;
}
时间: 2024-08-07 17:01:35

GCJ2017R1C B. Parenting Partnering的相关文章

One parenting weapon

Number One Parenting Tool There is only one main parenting tool that must be used to develop your child emotional behavior. I know that sounds unreal. How could there be just one main thing to do with all of the information available that prescribes

Parenting父类化

Parenting父类化:一个子对象将继承它的父对象的动作和旋转. 两个非父对象 对另一个来讲的一个父对象 原文地址:https://www.cnblogs.com/kubll/p/10801415.html

Parenting育儿

Parenting育儿 unity使用一种称为概念育儿.当创建一组对象时,最顶层的对象或场景称为"父对象",并且下面分组的所有对象都称为"子对象"或"子对象".您还可以创建嵌套的父子对象(称为顶级父对象的"后代"). 在此图像中,子和子2是父的子对象. 子节点3是子节点2的子对象,父节点的子对象. 在此图像中,儿童和儿童2是的子对象父.儿童3是的子对象子2和的后裔对象父. 单击父对象的下拉箭头(位于其名称的左侧)以显示或隐藏其

爬取https://www.parenting.com/baby-names/boys/earl网站top10男女生名字及相关信息

爬取源代码如下: import requestsimport bs4from bs4 import BeautifulSoupimport reimport pandas as pdimport ioimport syssys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='gb18030') lilist=[] r=requests.get('https://www.parenting.com/baby-names/boys/earl

GCJ2017R1C A. Ample Syrup

题目大意 给$n$个圆盘,取$k$个组成一个stack,要求表面积最大 简要题解 按侧面积排序取最大的前$k-1$个,再枚举剩下的一个加入求总面积取最大值即可. #include <vector> #include <algorithm> #include <iostream> using namespace std; using DB = double; using II = pair<int, int>; using VII = vector<pa

RE写作Issue问题题库分析与提纲

RE写作Issue问题题库分析与提纲 GRE写作Issue问题题库分析与提纲 第一类 社会 2. "Competition is ultimately more beneficial than detrimental to society." 归根结底,竞争对于社会是利多弊少. Generally speaking, competition contributes to progress in society. 1.        Generally speaking, competi

Behavior trees for AI: How they work

http://www.gamasutra.com/blogs/ChrisSimpson/20140717/221339/Behavior_trees_for_AI_How_they_work.php by Chris Simpson on 07/17/14 09:35:00 pm       27 comments       The following blog post, unless otherwise noted, was written by a member of Gamasutra

【Unity】11.2 刚体(Rigidbody)

分类:Unity.C#.VS2015 创建日期:2016-05-02 一.简介 Rigidbody(刚体)组件可使游戏对象在物理系统的控制下来运动,刚体可接受外力与扭矩力,使游戏对象像在真实世界中那样进行运动. 任何游戏对象,只有对其添加了刚体组件,该对象才能受重力的影响. 通过脚本为游戏对象添加的作用力,以及通过NVIDlA物理引擎与其他的游戏对象发生互动的运算,都需要为游戏对象添加刚体组件. 二.如何为对象添加刚体 在Unity 5.x中为某个游戏对象添加刚体组件的办法是:选中要添加刚体的游

微软职位内部推荐-Software Development Engineering II

微软近期Open的职位: Job Title: Software Development Engineering II Work Location: Suzhou, China Enterprise customer and consumers are rapidly adopting Office 365 Cloud services. Delivering on those online services requires building, maintaining, and securin