期望得分: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. Scrum立会报告+燃尽图(Beta阶段第二周第三次)

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2411 项目地址:https://coding.net/u/wuyy694 ...

  2. 第二次作业——个人项目实战(sudoku)

    第二次作业--个人项目实战(sudoku) 一.作业要求地址 第二次作业--个人项目实战 二.Github项目地址 softengineering1--sudoku 三.PSP表格估计耗时 PSP2. ...

  3. 第5题 查找字符串中的最长回文字符串---Manacher算法

    转载:https://www.felix021.com/blog/read.php?2040 首先用一个非常巧妙的方式,将所有可能的奇数/偶数长度的回文子串都转换成了奇数长度:在每个字符的两边都插入一 ...

  4. 【第六周】关于beta测试组员评分标准的若干意见

    组名: 新蜂 组长: 武志远 组员: 宫成荣 谢孝淼 杨柳 李峤 项目名称: java俄罗斯方块 评分规则:简单的才是坠吼的,本组不想搞个大新闻,所以奉行极简的评分方式.每一个人交给组长一个排名,假如 ...

  5. 小程序获取access_token

    <?php //小程序appid $appid = 'wx79d7c348d19f010c'; //小程序 APPSecret 密钥 $appsecret = 'd624aca86d0350ee ...

  6. [转帖]IBM收购Red Hat

    来源cnbeta:https://www.cnbeta.com/articles/tech/782009.htm 2018年10月28 日,IBM 宣布收购 Linux 巨头 Red Hat.公告中称 ...

  7. docker-py execute echo无效

    错误写法: cli.execute('9b2606a50304','echo "bibo">/tmp/1.txt')   争取写法: cli.execute('9b2606a ...

  8. pixi.js 微信小游戏 入手

    pixi是什么?一款h5游戏引擎 优点:简单简洁性能第一 缺点:大多数用的国产三大引擎,pixi资料少,工具少, 为什么学,装逼 用pixi开发小游戏行吗? 行.但要简单处理下 下载官网上的 weap ...

  9. el表达式作用域查找顺序 注意:当属性名字相同时候 先找到是小的作用域 因为是从小到大开始找的

  10. 最大流Dinic算法模板(pascal)

    program rrr(input,output); const inf=; type pointer=^nodetype; nodetype=record t,c:longint; next,rev ...