2017北京国庆刷题Day7 afternoon
期望得分:100+30+100=230
实际得分:60+30+100=190
排序去重
固定右端点,左端点单调不减
考场上用了二分,没去重,60
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 100001
void read(int &x)
{
x=;char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
}
struct node
{
int a,b;
bool operator < (node q) const
{
if(a!=q.a) return a<q.a; return b<q.b;
}
bool operator == (node p) const
{
return a==p.a && b==p.b;
}
}e[N];
int main()
{
freopen("card.in","r",stdin);
freopen("card.out","w",stdout);
int n;
read(n);
for(int i=;i<=n;i++) read(e[i].a),read(e[i].b);
sort(e+,e+n+);
int tot=unique(e+,e+n+)-e-;
int l,last,mx=;
for(l=;l<=tot;l++)
{
if(e[l].a!=e[l-].a) last=l;
while(e[l].b-e[last].b+>n) last++;
mx=max(mx,l-last+);
}
printf("%d\n",n-mx);
}
记录所有子集的最后出现位置
对于每个ai,枚举ai的子集,若最后出现位置<i-bi,ans++
枚举子集复杂度:
for(int s=1;s<(1<<n);s++)
for(int i=s;i;i=(i-1)&s)
这两个循环的复杂度为3^n
因为对于n个二进制位,要么属于s不属于i,要么属于s属于i,要么不属于s
#include<cstdio>
#include<iostream>
#define N 100001
using namespace std;
void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
}
int pos[N];
int main()
{
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
int n,a,b,ans;
read(n);
for(int i=;i<=n;i++)
{
ans=;
read(a); read(b);
for(int j=a;j;j=(j-)&a)
{
if(pos[j]<i-b) ans++;
pos[j]=i;
}
printf("%d\n",ans);
}
}
套路,tarjan+拓扑排序/单源最短路
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 500001
using namespace std;
int n,m,S;
int val[N];
int front[N],to[N],nxt[N],tot,from[N];
int dfn[N],low[N],st[N],top;
bool ins[N];
int id[N],cnt,sum[N];
int nxt2[N],front2[N],to2[N],tot2;
int q[N];
int in[N],dp[N];
void read(int &x)
{
x=;char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
}
void add(int u,int v)
{
if(u==v) return;
for(int i=front[u];i;i=nxt[i])
if(to[i]==v) continue;
to[++tot]=v; nxt[tot]=front[u]; front[u]=tot; from[tot]=u;
}
void init()
{
read(n);read(m);
int u,v;
for(int i=;i<=m;i++) { read(u); read(v); add(u,v); }
for(int i=;i<=n;i++) read(val[i]);
read(S);
}
void tarjan(int x)
{
dfn[x]=low[x]=++tot;
st[++top]=x; ins[x]=true;
for(int i=front[x];i;i=nxt[i])
if(!dfn[to[i]]) tarjan(to[i]),low[x]=min(low[x],low[to[i]]);
else if(ins[to[i]]) low[x]=min(low[x],dfn[to[i]]);
if(low[x]==dfn[x])
{
id[x]=++cnt; sum[cnt]+=val[x];
while(top && st[top]!=x) { id[st[top]]=cnt; sum[cnt]+=val[st[top]]; ins[st[top--]]=false; }
ins[st[top--]]=false;
}
}
void add2(int u,int v)
{
to2[++tot2]=v; nxt2[tot2]=front2[u]; front2[u]=tot2; in[v]++;
}
void rebuild()
{
for(int i=;i<=m;i++)
if(id[from[i]]!=id[to[i]]) add2(id[from[i]],id[to[i]]);
}
void pre()
{
memset(ins,false,sizeof(ins));
int h=,t=;
q[++h]=id[S]; ins[id[S]]=true;
int now;
while(h<=t)
{
now=q[h++];
for(int i=front2[now];i;i=nxt2[i])
if(!ins[to2[i]]) ins[to2[i]]=true,q[++t]=to2[i];
}
for(int i=;i<=cnt;i++)
if(!ins[i])
for(int j=front2[i];j;j=nxt2[j]) in[to2[j]]--;
}
void topsort()
{
st[top=]=id[S]; dp[id[S]]=sum[id[S]];
int now;
while(top)
{
now=st[top--];
for(int i=front2[now];i;i=nxt2[i])
{
dp[to2[i]]=max(dp[to2[i]],dp[now]+sum[to2[i]]);
in[to2[i]]--;
if(!in[to2[i]]) st[++top]=to2[i];
}
}
}
void answer()
{
int ans=,k,x;
read(k);
for(int i=;i<=k;i++)
{
read(x);
ans=max(ans,dp[id[x]]);
}
printf("%d\n",ans);
}
int main()
{
freopen("save.in","r",stdin);
freopen("save.out","w",stdout);
init();
tot=;
for(int i=;i<=n;i++)
if(!dfn[i]) top=,tarjan(i);
rebuild();
pre();
topsort();
answer();
}
2017北京国庆刷题Day7 afternoon的更多相关文章
- 2017北京国庆刷题Day1 afternoon
期望得分:100+100+100=300 实际得分:100+100+100=300 T1 一道图论好题(graph) Time Limit:1000ms Memory Limit:128MB 题目 ...
- 2017北京国庆刷题Day7 morning
期望得分:100+0+100=200 实际得分:100+20+0=120 离散化搞搞 #include<cstdio> #include<iostream> #include& ...
- 2017北京国庆刷题Day5 afternoon
期望得分:100+60+100=260 实际得分:0+60+40=100 设图中有m个环,每个环有si条边,有k条边不在环中 ans= (2^s1 -2)*( 2^s2 -2)* (2^s3 -2)… ...
- 2017北京国庆刷题Day2 afternoon
期望得分:100+100+50=250 实际得分:100+70+50=220 T1 最大值(max) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有一 ...
- 2017北京国庆刷题Day4 afternoon
期望得分:100+100+0=200 实际得分:5+0+0=5 每加入一个数,x的因数位置++ 注意:根号x枚举时,如果x是完全平方数,根号x会重复累计2次,要减去 考场上没减,5分 /(ㄒoㄒ)/~ ...
- 2017北京国庆刷题Day6 afternoon
期望得分:100+100+40=240 实际得分:100+0+40=140 二进制拆分.二进制前缀和 #include<cstdio> #include<iostream> u ...
- 2017北京国庆刷题Day3 afternoon
期望得分:100+0+30=130 实际得分:100+36.5+0=136.5 T3 一个变量写混了,丢了30.. 模拟栈 #include<cstdio> #include<cst ...
- 2017北京国庆刷题Day3 morning
期望得分:100+60+0=160 实际得分:100+30+0=130 考场上用的哈希 #include<cstdio> #include<cstring> #include& ...
- 2017北京国庆刷题Day2 morning
期望得分:100+100+40=240 实际得分:100+40+0=140 T1 一道图论神题(god) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK ...
随机推荐
- Table Tennis Game 2(找规律)
Description Misha and Vanya have played several table tennis sets. Each set consists of several serv ...
- 探路者 Alpha阶段中间产物
版本控制 git地址:https://git.coding.net/clairewyd/toReadSnake.git 贪吃蛇(单词版)软件功能说明书 1 开发背景 “贪吃蛇”这个游戏对于80, ...
- 团队Alpha冲刺(三)
目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:丹丹 组员7:家伟 组员8:政演 组员9:鸿杰 组员10:刘一好 组员11:何宇恒 展示组内最 ...
- 结对作业_Two
Part 1.前言 (附:本次编码涵盖的所有功能均为java语言实现) 结对项目作业 结对同学高裕翔的博客 个人github传送门 博文pdf链接 Part 2.具体分工 本次的结对作业我们简单的拆分 ...
- Qt使用QNetworkAccessManager实现Ftp操作
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt使用QNetworkAccessManager实现Ftp操作 本文地址:http: ...
- Spring 学习 5- task 定时任务
Spring-Task 1.这是网上的: 后面是我自己的配置 Spring3.0以后自主开发的定时任务工具,spring task,可以将它比作一个轻量级的Quartz,而且使用起来很简单,除spri ...
- vue.js+vue-router+webpack keep-alive用法
本文是机遇 提纲: 现有需求 各个解决方案的优缺点 相关的问题延伸 keep-alive使用详解 现有需求 每个项目中都存在许多列表数据展示页面,而且通常包含一些筛选条件以及分页. 并 ...
- 【数据库】mysql中复制表结构的方法小结
mysql中用命令行复制表结构的方法主要有一下几种: 1.只复制表结构到新表 ? 1 CREATE TABLE 新表 SELECT * FROM 旧表 WHERE 1=2 或者 ? 1 CREATE ...
- list的迭代器能解决并发问题,collection 的迭代器不能解决并发问题,for可以解决并发问题
list的迭代器能解决并发问题,collection 的迭代器不能解决并发问题 为什么list支持add,collection不支持 例如有两个人同时添加第三个元素 list的迭代器能锁定线程 只有等 ...
- bzoj4568-幸运数字
题目 给出一棵树,每个节点上有权值\(a_i\),多次询问一条路径上选择一些点权值异或和最大值.\(n\le 2\times 10^4,q\le 2\times 10^5,0\le a_i\le 2\ ...