D枚举子集

题:https://codeforces.com/contest/1288/problem/D
题意:给定n个序列,每个序列m个数,求第i个和第j个序列组成b序列,b序列=max(a[i][k],a[j][k]),使得b序列最小值最大化,求达成条件的 i 和 j (i可等于j)

分析1:因为m<=8,所以我们考虑对每个序列的m个数进行状压。

   这题的状压是,“1”状态,表示取max取到了这个位置,“0”就表示max没取到这个位置。

   因为题目要求很明确,要b序列最小值最大化,所以我们不用考虑取max后哪个数覆盖哪个数,只需考虑最小值应该是第几个序列即可

   然后就对应俩个序列进行最大化匹配即可

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const int inf=0x3f3f3f3f;
const ll INF=1e18;
const int M=1e3+;
int a[];
int maxx[M],maxid[M];
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
for(int j=;j<=m;j++)
scanf("%d",&a[j]);
for(int j=;j<(<<m);j++){
int minn=inf;
for(int k=;k<m;k++){
if(j&(<<k))
minn=min(minn,a[k+]);
}
if(minn>=maxx[j]){
maxx[j]=minn;
maxid[j]=i;
}
}
}
int ans=-,x,y;
for(int i=;i<(<<m);i++){
if(ans<min(maxx[i],maxx[(<<m)--i])){
ans=min(maxx[i],maxx[(<<m)--i]);
x=maxid[i];
y=maxid[(<<m)--i];
}
}
printf("%d %d",x,y);
return ;
}

分析2:二分答案,将满足条件的位置用状压记录下来更新即可。

#include<bits/stdc++.h>
using namespace std;
int ansi,ansj,limit;
const int N=1e3+;
const int M=3e5+;
int a[M][],pos[N],p[];
int n,m;
bool check(int x){
for(int i=;i<=limit;i++)
pos[i]=;
for(int i=;i<=n;i++){
int now=;
for(int j=;j<=m;j++)
if(a[i][j]>=x)
now|=p[j];
pos[now]=i;///状态now由第i个序列得来
}
for(int i=;i<=limit;i++)
for(int j=i;j<=limit;j++){
if((i|j)==limit&&pos[i]&&pos[j]){
return ansi=pos[i],ansj=pos[j],true;
}
}
return false;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
scanf("%d",&a[i][j]);
limit=(<<m)-;
for(int i=;i<=m;i++){
p[i]=<<(i-);
}
int l=,r=1e9;
while(l<=r){
int midd=(l+r)>>;
if(check(midd))
l=midd+;
else
r=midd-;
}
printf("%d %d\n",ansi,ansj);
return ;
}

E BIT

题:https://codeforces.com/contest/1288/problem/E

题意:对于从1~n的一个序列,给定m个操作,每个操作给定一个数x,含义为将x提到序列的第一个位置,问每个数可能的最小最大位置是多少

分析:最小位置俩种可能,有被操作过答案就是1,否则就是本身数值,至于最大值,我们考虑事先考虑将n个数挪后m+1个位置(因为最多m个操作),目的是留出m个位置给要提出来的数;

   然后我每次提出来一个数就统计一下这个数前面有多少个 数,取max之后BIT更新一下,一直重复m步操作。

#include<bits/stdc++.h>
using namespace std;
const int M=1e6+;
int pos[M],minn[M],maxx[M],tr[M];
void add(int x,int c){
while(x<M)
tr[x]+=c,x+=(x&-x);
}
int Sum(int x){
int ans=;
while(x)
ans+=tr[x],x-=(x&-x);
return ans;
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
pos[i]=m++i;
minn[i]=maxx[i]=i;
add(pos[i],);
}
int nowpos=m+;
while(m--){
int x;
scanf("%d",&x);
minn[x]=;
int num=Sum(pos[x]);
maxx[x]=max(maxx[x],num);
add(pos[x],-);///消除这个位置的标记
pos[x]=nowpos--;
add(pos[x],);
}
for(int i=;i<=n;i++){
int num=Sum(pos[i]);
maxx[i]=max(maxx[i],num);
}
for(int i=;i<=n;i++)
printf("%d %d\n",minn[i],maxx[i]);
return ;
}

Educational Codeforces Round 80 (Rated for Div. 2)D E的更多相关文章

  1. Educational Codeforces Round 80 (Rated for Div. 2)

    A. Deadline 题目链接:https://codeforces.com/contest/1288/problem/A 题意: 给你一个 N 和 D,问是否存在一个 X , 使得 $x+\lce ...

  2. Educational Codeforces Round 80 (Rated for Div. 2) E. Messenger Simulator

    可以推出 min[i]要么是i要么是1,当a序列中存在这个数是1 max[i]的话就比较麻烦了 首先对于i来说,如果还没有被提到第一位的话,他的max可由他后面的这部分序列中 j>=i 的不同数 ...

  3. Educational Codeforces Round 80 (Rated for Div. 2)部分题解

    A. Deadline 题目链接 题目大意 给你\(n,d\)两个数,问是否存在\(x\)使得\(x+\frac{d}{x+1}\leq n\),其中\(\frac{d}{x+1}\)向上取整. 解题 ...

  4. Educational Codeforces Round 80 (Rated for Div. 2)(A-E)

    C D E 这三道题感觉挺好       决定程序是否能通过优化在要求的时间内完成,程序运行时间为t,你可以选择花X天来优化,优化后程序的运行时间为t/(x+1)取上整,花费的时间为程序运行时间加上优 ...

  5. Educational Codeforces Round 80 (Rated for Div. 2)E(树状数组,模拟,思维)

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ],mx[],a[],pos[],sum ...

  6. Educational Codeforces Round 80 (Rated for Div. 2)D(二分答案,状压检验)

    这题1<<M为255,可以logN二分答案后,N*M扫一遍表把N行数据转化为一个小于等于255的数字,再255^2检验答案(比扫一遍表复杂度低),复杂度约为N*M*logN #define ...

  7. Educational Codeforces Round 80 (Rated for Div. 2)C(DP)

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ; ][],temp[][]; int ...

  8. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  9. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

随机推荐

  1. SPOJ FISHER + FPOLICE SPFA+背包

    当初第一次做的是FPLICE这个题,当时就觉得要用图论去搜索,但是当时陷入死思维就是 dp[][]两个维度都是点,这样就违背了题目的本意,题目给定了一个时间T,在不超过时间T的情况下求最小的消耗,这不 ...

  2. POJ - 3662 Telephone Lines (dijstra+二分)

    题意:有N个独立点,其中有P对可用电缆相连的点,要使点1与点N连通,在K条电缆免费的情况下,问剩下的电缆中,长度最大的电缆可能的最小值为多少. 分析: 1.二分临界线(符合的情况的点在右边),找可能的 ...

  3. HDU 5311:Hidden String

    Hidden String  Accepts: 437  Submissions: 2174  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit ...

  4. kube-controller-manager配置详解

    KUBE_MASTER="--master=http://10.83.52.137:8080" KUBE_CONTROLLER_MANAGER_ARGS=" "

  5. Navicat Premium 12安装和破解

    链接:https://pan.baidu.com/s/1x8AFWlJYGIl3TlbA1vX63g 提取码:9hu0  安装步骤: 1.下载好后点击navicat12018_premium_cs_x ...

  6. pymysql常见报错

    错误一: AttributeError: module 'pymysql' has no attribute 'connect' 有道翻译 AttributeError:模块'pymysql'没有属性 ...

  7. 斐波那契数列 yield 和list 生成

    def fab_demo4(max): a,n,b = 0,0,1 while n < max: yield b # 生成器走到这一步返回b,需要再次调用才能继续执行 a,b = b,a+b n ...

  8. STM32F407读编码器没上拉电阻遇见的问题

    在调试之前由于本科阶段参加飞思卡尔智能汽车的竞赛,一直在使用与竞赛相关的单片机和编码器,后来由于工程的需要开始使用STM32的板子,在调试编码器的时候遇见了,使用了STM32的官方标准库中的定时器正交 ...

  9. CentOS6.x/6.5/6.4/6.3/6.2/7.x 64位安装php5.2(使用YUM自动安装)

    默认情况下,CentOS6 64 bit 已经早已不支持php5.2.x ,但是某些php程序还需要zend optimizer支持,怎么办呢?目前大部分的yum repos 都已经不支持直接安装ph ...

  10. RedHat无法使用yum源问题

    RedHat下的yum是需要注册才能使用的 使用的话会提示: [root@test ~]# yum clean all Loaded plugins: product-id, refresh-pack ...