[2018.11.03 T1] 游戏攻略

暂无链接

游戏攻略

GISPZJZ 在玩一款火爆的游戏,游戏中有 n n n个技能点,编号分别为 1 , 2 , … , n 1,2,…,n 1,2,,n。有些技能 点可以直接学习,还有一些技能点需要你已经学习某些技能点,才能够学习。一开始 GISPZJZ 没有学习任何技能点,现在 GISPZJZ 想知道,他最多能够学习技能池里的多少个技能。

输入:

第一行一个正整数 n n n​。

接下来 n n n 行,第 i + 1 i+1 i+1 行先输入一个整数 s i s_i si,接下来输入 s i s_i si 个正整数 a s 1 , a s 2 , … , a s i a_{s_1},a_{s_2},…,a_{s_i} as1,as2,,asi。 表示学习第 i i i 个技能,需要先学习的技能点。 s i = 0 s_i=0 si=0 表示学习 i i i 技能没有任何前置条件。

输出:

一行一个整数 ,表示 GISPZJZ 能学习的最大技能数。

样例输入:

4
0
1 1
2 1 4
2 1 3

样例输出:

2

样例说明:

GISPZJZ 可以按顺序学习技能 1,技能 2,然后无法获得其他的技能点。

数据范围:

对于 10 % 10\% 10%的数据, 1 ≤ n ≤ 10 , 1 ≤ s 1 + s 2 + … + s n ≤ 10 1≤n≤10,1≤s_1+s_2+…+s_n≤10 1n101s1+s2++sn10

对于 40 % 40\% 40%的数据, 1 ≤ n ≤ 500 , 1 ≤ s 1 + s 2 + … + s n ≤ 500 1≤n≤500,1≤s_1+s_2+…+s_n≤500 1n5001s1+s2++sn500

对于额外 10 % 10\% 10%的数据,满足对任意 1 ≤ i ≤ n , s i ≥ 1 1≤i≤n,s_i\ge 1 1insi1

对于额外 20 % 20\% 20%的数据,满足对任意 1 ≤ i ≤ n , s i ≤ 1 1≤i≤n,s_i≤1 1insi1

对于 100 % 100\% 100%的数据, 1 ≤ n ≤ 100000 , 1 ≤ s 1 + s 2 + … + s n ≤ 100000 1≤n≤100000,1≤s_1+s_2+…+s_n≤100000 1n1000001s1+s2++sn100000

题解

技能加点相当于一个图,每次将入度为 0 0 0的点删去,更新其他点的入度,答案 + 1 +1 +1,类似于拓扑排序。

不知道为什么考场上脑子抽了写一个用优先队列的 O ( n log ⁡ n ) O(n\log n) O(nlogn)算法。。。

代码
#include<bits/stdc++.h>
using namespace std;
const int M=1e5+5;
struct sd{int id,du;};
bool operator<(sd a,sd b){return a.du>b.du;}
int ru[M],n,ans;
bool vis[M];
vector<int>mmp[M];
priority_queue<sd>dui;
void in()
{
	scanf("%d",&n);
	for(int i=1,j,a,b;i<=n;dui.push((sd){i,ru[i]}),++i)
	for(scanf("%d",&a),ru[i]=a,j=1;j<=a;++j)
	scanf("%d",&b),mmp[b].push_back(i);
}
void ac()
{
	for(sd f;!dui.empty();)
	{
		f=dui.top();dui.pop();
		if(vis[f.id])continue;
		if(f.du)break;
		vis[f.id]=1,++ans;
		for(int i=mmp[f.id].size()-1;i>=0;--i)
		dui.push((sd){mmp[f.id][i],--ru[mmp[f.id][i]]});
	}
	printf("%d",ans);
}
int main(){in(),ac();
select * from (select t1.[id] as t1_id,t1.[requestId] as t1_requestId,t1.[htqsrq] as t1_htqsrq,t1.[htjzrq] as t1_htjzrq,t1.[htbh] as t1_htbh,t1.[gf] as t1_gf,t1.[xf] as t1_xf,t1.[rq] as t1_rq,t1.[fkfs] as t1_fkfs,t1.[formmodeid] as t1_formmodeid,t1.[modedatacreater] as t1_modedatacreater,t1.[modedatacreatertype] as t1_modedatacreatertype,t1.[modedatacreatedate] as t1_modedatacreatedate,t1.[modedatacreatetime] as t1_modedatacreatetime,t1.[modedatamodifier] as t1_modedatamodifier,t1.[modedatamodifydatetime] as t1_modedatamodifydatetime,t1.[form_biz_id] as t1_form_biz_id,t1.[MODEUUID] as t1_MODEUUID,t1.[htfj] as t1_htfj,t1.[zje] as t1_zje,t1.[ds] as t1_ds,t1.[zjedx] as t1_zjedx,t1.[cspp] as t1_cspp,t1.[yfk] as t1_yfk,t1.[gxid] as t1_gxid,t1.[bz] as t1_bz,t1.[gfqymc] as t1_gfqymc,t1.[gfjc] as t1_gfjc,t1.[bh] as t1_bh,t1.[jylx] as t1_jylx,t1.[cght] as t1_cght,t1.[yf] as t1_yf,t1.[yfk1] as t1_yfk1,t1.[yf11] as t1_yf11,t1.[nf] as t1_nf,t1.[rksj] as t1_rksj,t1.[cclx] as t1_cclx,t1.[cgbt] as t1_cgbt,t1.[yfk2] as t1_yfk2,t1.[sywf] as t1_sywf,t1.[yfbl] as t1_yfbl,t1.[fhbl] as t1_fhbl,t1.[yfh] as t1_yfh,t1.[sykf] as t1_sykf,t1.[hzsdlqys] as t1_hzsdlqys,t1.[sys_workflowid] as t1_sys_workflowid,t1.[cgqzyz] as t1_cgqzyz,t1.[htwjpdf] as t1_htwjpdf,t1.[cghtlc] as t1_cghtlc,t1.[htzt] as t1_htzt,t1.[qzfs] as t1_qzfs,t1.[htwjtp] as t1_htwjtp,t1.[cgqzlc] as t1_cgqzlc,t1.[sjfk] as t1_sjfk,t1.[ydkds] as t1_ydkds,t1.[chpt] as t1_chpt,t1.[lxdhchr] as t1_lxdhchr,t1.[gxsjkx] as t1_gxsjkx,t1.[hkzt] as t1_hkzt,t1.[lcfkd] as t1_lcfkd,t1.[fkzlcid] as t1_fkzlcid,t1.[mode_top_4] as t1_mode_top_4,t1.[cgdj] as t1_cgdj,t1.[mode_top_22] as t1_mode_top_22,t2.[id] as t2_id,t2.[mainid] as t2_mainid,t2.[sld] as t2_sld,t2.[ppcj] as t2_ppcj,t2.[hsdj] as t2_hsdj,t2.[bz] as t2_bz,t2.[je] as t2_je,t2.[xhggyt] as t2_xhggyt,t2.[mxgxid] as t2_mxgxid,t2.[dqkckc] as t2_dqkckc,t2.[rkhkc] as t2_rkhkc,t2.[yf] as t2_yf,t2.[yldjbhyf] as t2_yldjbhyf,SELECT year(rksj) as 年 FROM uf_gfht as cus_年年 from uf_gfht t1 INNER join uf_gfht_dt1 t2 on t1.id = t2.mainid) tmp1 where t1 错在哪里
最新发布
05-14
这段 SQL 语句有语法错误,其中的 `SELECT` 语句需要在外层再嵌套一层括号以便正确引用别名。正确的语句应该是: ``` SELECT tmp1.*, tmp2.年 FROM (SELECT t1.[id] as t1_id, t1.[requestId] as t1_requestId, t1.[htqsrq] as t1_htqsrq, t1.[htjzrq] as t1_htjzrq, t1.[htbh] as t1_htbh, t1.[gf] as t1_gf, t1.[xf] as t1_xf, t1.[rq] as t1_rq, t1.[fkfs] as t1_fkfs, t1.[formmodeid] as t1_formmodeid, t1.[modedatacreater] as t1_modedatacreater, t1.[modedatacreatertype] as t1_modedatacreatertype, t1.[modedatacreatedate] as t1_modedatacreatedate, t1.[modedatacreatetime] as t1_modedatacreatetime, t1.[modedatamodifier] as t1_modedatamodifier, t1.[modedatamodifydatetime] as t1_modedatamodifydatetime, t1.[form_biz_id] as t1_form_biz_id, t1.[MODEUUID] as t1_MODEUUID, t1.[htfj] as t1_htfj, t1.[zje] as t1_zje, t1.[ds] as t1_ds, t1.[zjedx] as t1_zjedx, t1.[cspp] as t1_cspp, t1.[yfk] as t1_yfk, t1.[gxid] as t1_gxid, t1.[bz] as t1_bz, t1.[gfqymc] as t1_gfqymc, t1.[gfjc] as t1_gfjc, t1.[bh] as t1_bh, t1.[jylx] as t1_jylx, t1.[cght] as t1_cght, t1.[yf] as t1_yf, t1.[yfk1] as t1_yfk1, t1.[yf11] as t1_yf11, t1.[nf] as t1_nf, t1.[rksj] as t1_rksj, t1.[cclx] as t1_cclx, t1.[cgbt] as t1_cgbt, t1.[yfk2] as t1_yfk2, t1.[sywf] as t1_sywf, t1.[yfbl] as t1_yfbl, t1.[fhbl] as t1_fhbl, t1.[yfh] as t1_yfh, t1.[sykf] as t1_sykf, t1.[hzsdlqys] as t1_hzsdlqys, t1.[sys_workflowid] as t1_sys_workflowid, t1.[cgqzyz] as t1_cgqzyz, t1.[htwjpdf] as t1_htwjpdf, t1.[cghtlc] as t1_cghtlc, t1.[htzt] as t1_htzt, t1.[qzfs] as t1_qzfs, t1.[htwjtp] as t1_htwjtp, t1.[cgqzlc] as t1_cgqzlc, t1.[sjfk] as t1_sjfk, t1.[ydkds] as t1_ydkds, t1.[chpt] as t1_chpt, t1.[lxdhchr] as t1_lxdhchr, t1.[gxsjkx] as t1_gxsjkx, t1.[hkzt] as t1_hkzt, t1.[lcfkd] as t1_lcfkd, t1.[fkzlcid] as t1_fkzlcid, t1.[mode_top_4] as t1_mode_top_4, t1.[cgdj] as t1_cgdj, t1.[mode_top_22] as t1_mode_top_22, t2.[id] as t2_id, t2.[mainid] as t2_mainid, t2.[sld] as t2_sld, t2.[ppcj] as t2_ppcj, t2.[hsdj] as t2_hsdj, t2.[bz] as t2_bz, t2.[je] as t2_je, t2.[xhggyt] as t2_xhggyt, t2.[mxgxid] as t2_mxgxid, t2.[dqkckc] as t2_dqkckc, t2.[rkhkc] as t2_rkhkc, t2.[yf] as t2_yf, t2.[yldjbhyf] as t2_yldjbhyf FROM uf_gfht t1 INNER JOIN uf_gfht_dt1 t2 ON t1.id = t2.mainid) tmp1 INNER JOIN (SELECT year(rksj) as 年 FROM uf_gfht) tmp2 ON tmp1.t1_rksj = tmp2.年 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ShadyPi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值