期望得分: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的更多相关文章

  1. 2017北京国庆刷题Day1 afternoon

    期望得分:100+100+100=300 实际得分:100+100+100=300 T1 一道图论好题(graph) Time Limit:1000ms   Memory Limit:128MB 题目 ...

  2. 2017北京国庆刷题Day7 morning

    期望得分:100+0+100=200 实际得分:100+20+0=120 离散化搞搞 #include<cstdio> #include<iostream> #include& ...

  3. 2017北京国庆刷题Day5 afternoon

    期望得分:100+60+100=260 实际得分:0+60+40=100 设图中有m个环,每个环有si条边,有k条边不在环中 ans= (2^s1 -2)*( 2^s2 -2)* (2^s3 -2)… ...

  4. 2017北京国庆刷题Day2 afternoon

    期望得分:100+100+50=250 实际得分:100+70+50=220 T1 最大值(max) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK有一 ...

  5. 2017北京国庆刷题Day4 afternoon

    期望得分:100+100+0=200 实际得分:5+0+0=5 每加入一个数,x的因数位置++ 注意:根号x枚举时,如果x是完全平方数,根号x会重复累计2次,要减去 考场上没减,5分 /(ㄒoㄒ)/~ ...

  6. 2017北京国庆刷题Day6 afternoon

    期望得分:100+100+40=240 实际得分:100+0+40=140 二进制拆分.二进制前缀和 #include<cstdio> #include<iostream> u ...

  7. 2017北京国庆刷题Day3 afternoon

    期望得分:100+0+30=130 实际得分:100+36.5+0=136.5 T3 一个变量写混了,丢了30.. 模拟栈 #include<cstdio> #include<cst ...

  8. 2017北京国庆刷题Day3 morning

    期望得分:100+60+0=160 实际得分:100+30+0=130 考场上用的哈希 #include<cstdio> #include<cstring> #include& ...

  9. 2017北京国庆刷题Day2 morning

    期望得分:100+100+40=240 实际得分:100+40+0=140 T1 一道图论神题(god) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK ...

随机推荐

  1. 对石家庄铁道大学网站UI的分析

         作为我们团队的PM,老师对我们提出了一些额外的要求,所以我发表这篇博客来谈一下对石家庄铁道大学网站UI的分析.      首先,PM 对项目所有功能的把握, 特别是UI.最差的UI, 体现了 ...

  2. UIView maskView属性

    给View1的maskView 赋值View2 1.View2不会显示在View1上: 2.View2 的alpha通道会体现在View1上. 关于maskView,Apple的解释: An opti ...

  3. web.config详解(转载)

    该文为转载 原文地址:http://www.cnblogs.com/gaoweipeng/archive/2009/05/17/1458762.html 花了点时间整理了一下ASP.NET Web.c ...

  4. lintcode-451-两两交换链表中的节点

    451-两两交换链表中的节点 给一个链表,两两交换其中的节点,然后返回交换后的链表. 样例 给出 1->2->3->4, 你应该返回的链表是 2->1->4->3. ...

  5. java沙盒

    JAVA的安全模型不同于传统的安全方法,传统的安全方法中,大多数操作系统允许应用程序充分访问系统资源,在操作系统不提供安全保护的机器里,运行环境不能被信任.为了弥补这个缺陷,安全策略经常要求在应用程序 ...

  6. BurpSuite 激活破解

    1.下载软件关于Burp Suite, 它是进行Web应用安全测试的一个集成平台,无缝融合各种安全工具并提供全面的接口适配,支持完整的Web应用测试流程,从最初的映射和应用程序的攻击面分析到发现和利用 ...

  7. saltstack基础篇

    使用saltstack的前提是PPT      服务.流程.工具和技术 安装 rpm -Uvh http://mirrors.yun-idc.com/epel/6Server/x86_64/epel- ...

  8. android studio 运行太慢了

    Android Studio每次升级/安装 Android Studio 之后最好都修改一下这个参数:到 Android Studio 安装目录,找到 bin/studio(64?).vmoption ...

  9. codeforces 1027 E. Inverse coloring (DP)

    E. Inverse Coloring time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  10. 【bzoj3110】[Zjoi2013]K大数查询 整体二分+树状数组区间修改

    题目描述 有N个位置,M个操作.操作有两种,每次操作如果是1 a b c的形式表示在第a个位置到第b个位置,每个位置加入一个数c.如果是2 a b c形式,表示询问从第a个位置到第b个位置,第C大的数 ...