2021團(tuán)體程序設(shè)計(jì)天梯賽】L2部分(PTA,L2-037到L2-040)題解代碼&復(fù)盤

      網(wǎng)友投稿 823 2022-05-29

      都是模擬,沒(méi)啥好說(shuō)的。

      T1注意軌道空了的時(shí)候按鈕沒(méi)反應(yīng)的,考場(chǎng)一遍過(guò)了復(fù)盤的時(shí)候給忘了改了好久。

      T2題目沒(méi)說(shuō)清楚可以從任意節(jié)點(diǎn)出發(fā),以為只有0出發(fā)改了好久最后都沒(méi)改出來(lái),最后只拿了17分,不然就國(guó)二了,復(fù)盤的時(shí)候套個(gè)循環(huán)就A了,害。另外補(bǔ)充了一種并查集的解法。

      T3用STL模擬,30行就可以敲出來(lái),考場(chǎng)的時(shí)候因?yàn)橥涊敵鲎铋_(kāi)始的長(zhǎng)度4,然后交上去一直全WA,想了好久沒(méi)想出來(lái)qaq

      T4就是建個(gè)圖直接模擬就行,好像去年也有這種題。

      L2-037 包裝機(jī) 25 69 257 0.27

      L2-038 病毒溯源 25 72 277 0.26

      L2-039 清點(diǎn)代碼庫(kù) 25 47 487 0.10

      L2-040 哲哲打游戲 25 39 223 0.17

      #include using namespace std; const int maxn = 2e4+10; string ss[1010]; int f[1010]; int main(){ int n, m, s; cin>>n>>m>>s; for(int i = 1; i <= n; i++){ cin>>ss[i]; } stackstk; int x; while(cin>>x && x!=-1){ if(x==0){ if(stk.size()==0){ continue; } cout<=ss[x].size())continue; if(stk.size()==s){ cout<

      1

      2

      3

      4

      5

      6

      7

      8

      9

      10

      11

      12

      13

      14

      15

      16

      17

      18

      19

      20

      21

      22

      23

      24

      25

      26

      27

      28

      【2021團(tuán)體程序設(shè)計(jì)天梯賽】L2部分(PTA,L2-037到L2-040)題解代碼&amp;復(fù)盤

      29

      30

      31

      32

      #include using namespace std; const int maxn = 2e4+10; vectorG[maxn]; int ans = 0, ans2=0, root=0; void dfs(int u, int h){ ans = max(ans,h); for(int v:G[u]){ dfs(v,h+1); } } int ok = 0; vectorvc; void dfs2(int u,int h){ if(ok==1)return ; if(h==ans2 && ok==0){ ok = 1; for(int i = 0; i < ans2; i++){ if(i!=0)cout<<" "<>n; for(int i = 0; i < n; i++){ int k; cin>>k; for(int j = 0; j < k; j++){ int x; cin>>x; G[i].push_back(x); } if(G[i].size()!=0)sort(G[i].begin(),G[i].end()); } for(int i = 0; i < n; i++){ dfs(i,1); if(ans>ans2){ ans2 = ans; root = i; } } cout<

      1

      2

      3

      4

      5

      6

      7

      8

      9

      10

      11

      12

      13

      14

      15

      16

      17

      18

      19

      20

      21

      22

      23

      24

      25

      26

      27

      28

      29

      30

      31

      32

      33

      34

      35

      36

      37

      38

      39

      40

      41

      42

      43

      44

      45

      46

      47

      48

      49

      50

      51

      52

      53

      54

      //給出一棵樹(shù),求最長(zhǎng)鏈 //并查集不要路徑壓縮,統(tǒng)計(jì)每個(gè)點(diǎn)所在的鏈 ps. 可以不是從0開(kāi)始 #include using namespace std; const int maxn = 1e5+10; int fa[maxn+10]; inline void init(int n){for(int i = 0; i < n; i++)fa[i]=i;} inline int find(int x){return x==fa[x]?x:find(fa[x]);} inline void merge(int x, int y){ if(x!=y)fa[y] = x;} int cc[maxn+10]; inline int size(int x){//TLE5 int ans = 1; while(x!=fa[x])x=fa[x],ans++; return ans; } bool cmp(vectora, vectorb){ for(int i = 0; i < a.size(); i++) if(a[i]!=b[i])return a[i]>n; init(n); for(int i = 0; i < n; i++){ int k; scanf("%d",&k); for(int j = 1; j <= k; j++){ int x; scanf("%d",&x); merge(i,x); } } //先找最長(zhǎng)鏈 int len = 1; for(int i = 0; i < n; i++){ cc[i] = size(i); len = max(len, cc[i]); } //存儲(chǔ)所有路徑,排序輸出最短 vector >ans; for(int i = 0; i < n; i++){ if(cc[i]!=len)continue; vectorvc; int x = i; while(x!=fa[x]){ vc.push_back(x); x = fa[x]; } vc.push_back(x); reverse(vc.begin(),vc.end()); ans.push_back(vc); } sort(ans.begin(),ans.end(),cmp); //cout<

      1

      2

      3

      4

      5

      6

      7

      8

      9

      10

      11

      12

      13

      14

      15

      16

      17

      18

      19

      20

      21

      22

      23

      24

      25

      26

      27

      28

      29

      30

      31

      32

      33

      34

      35

      36

      37

      38

      39

      40

      41

      42

      43

      44

      45

      46

      47

      48

      49

      50

      51

      52

      53

      54

      55

      56

      57

      58

      59

      60

      #include using namespace std; const int maxn = 2e4+10; bool cmp(pair, int> a, pair, int> b){ if(a.second!=b.second)return a.second>b.second; for(int i = 0; i < a.first.size(); i++){ if(a.first[i]!=b.first[i]) return a.first[i]>n>>m; map, int>ma; for(int i = 1; i <= n; i++){ vectorvc; for(int j = 1; j <= m; j++){ int x; cin>>x; vc.push_back(x); } ma[vc]++; } vector, int> >vc(ma.begin(), ma.end()); sort(vc.begin(),vc.end(), cmp); cout<

      1

      2

      3

      4

      5

      6

      7

      8

      9

      10

      11

      12

      13

      14

      15

      16

      17

      18

      19

      20

      21

      22

      23

      24

      25

      26

      27

      28

      29

      30

      31

      32

      33

      #include using namespace std; const int maxn = 1e5+10; vectorG[maxn]; int back[110]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin>>n>>m; for(int i = 1; i <= n; i++){ int k; cin>>k; for(int j = 1; j <= k; j++){ int x; cin>>x; G[i].push_back(x); } } int now = 1; for(int i = 1; i <= m; i++){ int op, x; cin>>op>>x; if(op==0){ now = G[now][x-1]; }else if(op==1){ back[x] = now; cout<

      1

      2

      3

      4

      5

      6

      7

      8

      9

      10

      11

      12

      13

      14

      15

      16

      17

      18

      19

      20

      21

      22

      23

      24

      25

      26

      27

      28

      29

      30

      5G游戲

      版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請(qǐng)聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時(shí)內(nèi)刪除侵權(quán)內(nèi)容。

      上一篇:使用ModelArts實(shí)現(xiàn)花卉圖像分類
      下一篇:認(rèn)識(shí)云存儲(chǔ)不可不知的5大優(yōu)勢(shì)
      相關(guān)文章
      亚洲乱码无码永久不卡在线| 亚洲乱码国产乱码精华| 在线观看亚洲AV日韩AV| 久久久亚洲AV波多野结衣| 九月丁香婷婷亚洲综合色| 国产亚洲精品AA片在线观看不加载 | 亚洲伊人久久大香线蕉啊| 久久久久亚洲精品日久生情| 亚洲国产高清在线| 亚洲成av人影院| 亚洲爆乳无码一区二区三区| 亚洲高清专区日韩精品| 亚洲国产成人精品无码区在线观看| 亚洲理论电影在线观看| 国产成人亚洲综合无码精品| 国产成人亚洲综合无码精品| 亚洲av丰满熟妇在线播放| 亚洲精品国产成人99久久| 亚洲Av无码专区国产乱码DVD| 国产精品亚洲不卡一区二区三区| 国产成人精品亚洲一区| 一本久久综合亚洲鲁鲁五月天| 亚洲 另类 无码 在线| 亚洲高清偷拍一区二区三区 | 亚洲激情中文字幕| 亚洲成a人片77777老司机| 97久久精品亚洲中文字幕无码| 亚洲色偷偷偷网站色偷一区| 亚洲小说区图片区| 国产午夜亚洲精品国产| 亚洲A∨精品一区二区三区下载| 国产精品自拍亚洲| 久久亚洲中文字幕精品一区四| 国产亚洲av片在线观看播放| 亚洲AV无码久久精品色欲| 亚洲高清无在码在线电影不卡| 亚洲国产精品xo在线观看| 一本色道久久综合亚洲精品蜜桃冫| 亚洲欧美黑人猛交群| 亚洲国产成人VA在线观看| 亚洲色WWW成人永久网址|