#10023. 「一本通 1.3 练习 2」平板涂色

#include<bits/stdc++.h>
#define lop(x,m,n) for(int x=m;x<=n;x++)
using namespace std;
int n;
struct node{
    int x1,y1,x2,y2,se;
}sq[20];
int used[20]={0};
int maxx,maxy;
bool b[40][40]={0};
void init()
{
    maxx=-1,maxy=-1;
    scanf("%d",&n);
    lop(i,1,n)
    {
        scanf("%d%d%d%d%d",&sq[i].x1,&sq[i].y1,&sq[i].x2,&sq[i].y2,&sq[i].se);
        maxx=max(maxx,sq[i].x2);
        maxy=max(maxy,sq[i].y2);

    }

}
int ans=15;
bool check(int x)
{
    if(sq[x].x1==0) return true;
    lop(i,sq[x].y1+1,sq[x].y2)
    {
        if(b[sq[x].x1][i]==0)
        {
            return false;
        }
    }
    return true;
}
void ss(int x)
{
    lop(i,sq[x].x1+1,sq[x].x2)
     lop(j,sq[x].y1+1,sq[x].y2)
      b[i][j]=1;
}
void zz(int x)
{
    lop(i,sq[x].x1+1,sq[x].x2)
     lop(j,sq[x].y1+1,sq[x].y2)
      b[i][j]=0;
}
void dfs(int k,int p,int num)//第k次拿笔,第p块方板 ,累积num块方板
{
    if(k>ans) return;
    if(num==n)
    {
        ans=min(ans,k);
    }
    lop(i,1,n)
    {
        if(!used[i]&&check(i))
        {
            used[i]=1;
            ss(i);
            num++;
            if(sq[i].se!=sq[p].se)
            {
                k++;
                dfs(k,i,num);

                k--;
            }
            else{
                dfs(k,i,num);
            }
            zz(i);
            num--;
            used[i]=0;
        }
    }
}
int main()
{
    init();
    dfs(0,0,0);
    cout<<ans;
} 

原文地址:https://www.cnblogs.com/719666a/p/9508418.html

时间: 2024-08-30 13:11:14

#10023. 「一本通 1.3 练习 2」平板涂色的相关文章

10249「一本通 1.3 例 5」weight

#10249「一本通 1.3 例 5」weight 题目描述 原题来自:USACO 已知原数列a1,a2,...,an中的前1项,前2项,前3项,... ,前 n 项的和,以及后 1 项,后 2 项,后 3 项,...,后 n 项的和,但是==所有的数都被打乱了顺序==.此外,我们还知道数列中的数存在于集合 S 中.试求原数列.当存在多组可能的数列时,求字典序最小的数列. 输入格式 第 1 行,一个整数 n . 第 2 行, 2 × n 个整数,注意:数据已被打乱. 第 3 行,一个整数 m ,

「一本通 4.1 练习 2」简单题

题目描述 题目来源:CQOI 2006 有一个 n 个元素的数组,每个元素初始均为 0.有 m 条指令,要么让其中一段连续序列数字反转--0 变 1,1变 0(操作 1),要么询问某个元素的值(操作 2). 例如当 n=20 时,10 条指令如下: 操作 回答 操作后的数组 1 1 10 N/A 11111111110000000000 2 6 1 11111111110000000000 2 12 0 11111111110000000000 1 5 12 N/A 11110000001100

「一本通 4.2 例 2」最敏捷的机器人(loj10120)

题目描述 Wind 设计了很多机器人.但是它们都认为自己是最强的,于是,一场比赛开始了-- 机器人们都想知道谁是最敏捷的,于是它们进行了如下一个比赛.首先,他们面前会有一排共 n 个数,它们比赛看谁能最先把每连续 k 个数中最大和最小值写下来,当然,这些机器人运算速度都很快,它们比赛的是谁写得快. 但是 Wind 也想知道答案,你能帮助他吗? 输入格式 第一行为 n,k,意义如题目描述. 第二行共 n 个数,为数字序列,所有数字均在 Pascal 的 longint 范围内,即所有数均为整数,且

loj10139. 「一本通 4.5 练习 1」树上操作(loj2125. 「HAOI2015」树上操作 )

思路: 第二遍dfs时记录end[x]为在结点序列中以x为根的子树最后访问的节点,写个线段树标记下传即可.与值有关的数据注意long long #include<cstdio> #include<iostream> #include<vector> #include<cmath> #include<string> using namespace std; const int maxn = 100010; inline void qread(int

loj10143. 「一本通 4.6 例 1」营业额统计

思路: 使用treap在线存数据,每次取出新读入数据的前驱与后继,与该数据差值较小的就是.(注意若已有同一个数据,特判ans+=0) #include<cstdio> #include<iostream> #include<cstdlib> #include<cmath> using namespace std; const int maxn = 100010; inline void qread(int &x) { x = 0; register

loj10144. 「一本通 4.6 练习 1」宠物收养所

思路: treap+简单模拟. 我只能说:注意取模!!!! #include<cstdio> #include<iostream> #include<cstdlib> #include<cmath> using namespace std; const int maxn = 80010; inline void qread(int &x) { x = 0; register int ch = getchar(), flag = 0; while(ch

loj10145. 「一本通 4.6 练习 2」郁闷的出纳员

思路: 简单的treap+模拟. 但这道题的题面有误导群众的嫌疑,因为题中并没有明确刚进入公司就离开的算不算在离开公司的人中. 当然,对于这道题的数据,题目意思是不算在内. #include<cstdio> #include<iostream> #include<cstdlib> #include<string> using namespace std; const int maxn = 80010; inline void qread(int &x

loj10141. 「一本通 4.5 练习 3」染色

思路: 利用树链剖分转化为线段树问题,考虑线段上经这两种操作后的sum求值方法,并着重考虑树链合并的情况即可.线段树为了打cov,要注意将所有的颜色统一加一. #include<cstdio> #include<iostream> using namespace std; const int maxn = 100010; inline void qread(int &x){ x = 0; register int ch = getchar(); while(ch <

loj10147. 「一本通 5.1 例 1」石子合并

思路: 经典的区间dp,题解到处都是... #include<cstdio> #include<iostream> #include<cstdio> using namespace std; const int maxn = 1010; inline void qread(int &x){ x = 0; register int ch = getchar(); while(ch < '0' || ch > '9') ch = getchar(); w