Bzoj 4143: [AMPPZ2014]The Lawyer

Bzoj 4143: [AMPPZ2014]The Lawyer

抱歉,水了这一片博客..( ~~ 为了凑出AMPPZ2014.... ~~

显然记录最小的右端点,和最大的左端点即可.

/*header*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i , x, p) for(int i = x;i <= p;++ i)
#define sep(i , x, p) for(int i = x;i >= p;-- i)
#define gc getchar()
#define pc putchar
#define ll long long
#define mk make_pair
#define fi first
#define se second
using std::min;
using std::max;
using std::swap;

inline int gi() {
    int x = 0,f = 1;char c = gc;
    while(c < '0' || c > '9') {if(c == '-')f = -1;c = gc;}
    while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = gc;}return x * f;
}

void print(int x) {
    if(x < 0) pc('-') , x = -x;
    if(x >= 10) print(x / 10);
    pc(x % 10 + '0');
}

int max_d[23] , min_d[23];
int idmax_d[23] , idmin_d[23];

void gmin(int &x , int y) {x = x > y ? y : x;}
void gmax(int &x , int y) {x = x > y ? x : y;}

int main() {
    int n = gi() , m = gi();
    rep(i , 1, m) max_d[i] = -1e9 , min_d[i] = 1e9;
    rep(i , 1, n) {
        int l = gi() , r = gi(), d = gi();
        if(max_d[d] < l) {idmax_d[d] = i;max_d[d] = l;}
        if(min_d[d] > r) {idmin_d[d] = i;min_d[d] = r;}
    }
    rep(i , 1, m) {
        if(max_d[i] <= min_d[i]) puts("NIE");
        else {
            printf("TAK %d %d\n", idmin_d[i],idmax_d[i]);
        }
    }
    return 0;
}

原文地址:https://www.cnblogs.com/gzygzy/p/10263121.html

时间: 2024-08-30 06:32:50

Bzoj 4143: [AMPPZ2014]The Lawyer的相关文章

BZOJ 4143: [AMPPZ2014]The Lawyer( sort )

水题... 排序搞出每天的会议有哪些, 然后再按照会议的开始时间和结束时间排序, 最晚开始的和最早结束的会议不是同一场而且最晚开始的时间>最早结束的会议就有可能方案 ---------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<iostrea

bzoj4143: [AMPPZ2014]The Lawyer

4143: [AMPPZ2014]The Lawyer Time Limit: 10 Sec  Memory Limit: 256 MBSec  Special JudgeSubmit: 462  Solved: 257[Submit][Status][Discuss] Description Byteasar要制订m天的会议计划,一共有n场会议,第i场会议开始于第d[i]天的第a[i]秒,结束于第d[i]天的第b[i]秒. 对于每一天,请找出这一天的两场会议i,j,使得它们不冲突,即不存在一个

Bzoj 4145: [AMPPZ2014]The Prices

Bzoj 4145: [AMPPZ2014]The Prices 状态压缩dp \(f[i][j]\)表示前i个商店 , 状态为j的最小花费. 考虑什么东西也不买和买了东西. 买了东西的话,就要到i地. 然后转移:\(f[i][j] = min(f[i][j] , f[i][j ^ (1 << k - 1)] + c[i][k])\) 不买东西 \(f[i][j] = f[i - 1][j]\) /*header*/ #include <iostream> #include <

BZOJ 4143 The Lawyer

       这道题看起来很吓人,但事实上看懂后会发现,其根本没有任何技术含量,做这道题其实要考虑的就是每天最早结束的一场的结束时间以及最晚开始的一场的开始时间,如果结束时间早于开始时间,那么OK就这两场,否则输出无解,要注意的是,如果想在传入时就把每天分开,记得标记每一场的序号.        代码如下: #include<cstdlib> #include<cstdio> #include<iostream> using namespace std; long lo

BZOJ 4144: [AMPPZ2014]Petrol

4144: [AMPPZ2014]Petrol Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 457  Solved: 170[Submit][Status][Discuss] Description 给定一个n个点.m条边的带权无向图,其中有s个点是加油站. 每辆车都有一个油量上限b,即每次行走距离不能超过b,但在加油站可以补满. q次询问,每次给出x,y,b,表示出发点是x,终点是y,油量上限为b,且保证x点和y点都是加油站,请回答能否从x走

循环队列+堆优化dijkstra最短路 BZOJ 4152: [AMPPZ2014]The Captain

循环队列基础知识 1.循环队列需要几个参数来确定 循环队列需要2个参数,front和rear 2.循环队列各个参数的含义 (1)队列初始化时,front和rear值都为零: (2)当队列不为空时,front指向队列的第一个元素,rear指向队列最后一个元素的下一个位置: (3)当队列为空时,front与rear的值相等,但不一定为零: 3.循环队列入队的伪算法 (1)把值存在rear所在的位置: (2)rear=(rear+1)%maxsize ,其中maxsize代表数组的长度: 4.循环队列

BZOJ 4145: [AMPPZ2014]The Prices( 状压dp + 01背包 )

我自己只能想出O( n*3^m )的做法....肯定会T O( nm*2^m )做法: dp( x, s ) 表示考虑了前 x 个商店, 已买的东西的集合为s. 考虑转移 : 先假设我们到第x个商店去, so初始时 dp( x, s) = dp( x-1, s ) + d[x] 然后我们可以对第x个商店做01背包, dp(x, s + {h} ) = min( dp( x, s + {h} ) , dp( x, s) + c[x][h]) ) ( h ∉ s ). 之后我们再比较到第x个商店划不

BZOJ 4152: [AMPPZ2014]The Captain( 最短路 )

先按x排序, 然后只有相邻节点的边才有用, 我们连起来, 再按y排序做相同操作...然后就dijkstra ------------------------------------------------------------------------ #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<queue> #include

BZOJ 4145 [AMPPZ2014] The Prices 解题报告

感觉也是一个小清新题.. 我们考虑设立状态 $Dp[i][s]$ 表示考虑了前 $i$ 个商店后,购买状态为 $s$ 的最小花费. 转移的话就枚举每个商店 $i$,首先令: $$Dp[i][s] = Dp[i - 1][s] + D[i]$$ 这个过程表示到达这个商店. 然后枚举每个状态 $s$,然后枚举每个不在 $s$ 里的物品 $j$,令: $$Dp[i][s + \{j\}] = min(Dp[i][s + \{j\}], Dp[i][s] + Cost[i][j])$$ 这个过程就相当于