USACO 2018 December Contest Platinum T2: Sort It Out

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了USACO 2018 December Contest Platinum T2: Sort It Out相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/pac' title='pac'>pac   def   鏍戠姸   div   鎺掑垪   缁撴灉   瀛楀吀   names   bin   

棰樼洰澶ф剰

FJ鏈?nbsp;N锛?span class="katex">1N1e5 锛夊ご濂剁墰锛堝垎鍒敤 1N 缂栧彿锛夋帓鎴愪竴琛屻€侳J鍠滄浠栫殑濂剁墰浠ュ崌搴忔帓鍒楋紝涓嶅垢鐨勬槸鐜板湪濂逛滑鐨勯『搴忚鎵撲贡浜嗐€傚湪杩囧幓FJ鏇剧粡浣跨敤涓€浜涜濡?ldquo;鍐掓场鎺掑簭”鐨勫紑鍒涙€х殑绠楁硶鏉ヤ娇浠栫殑濂剁墰鎺掑ソ搴忥紝浣嗕粖澶╀粬鎯冲伔涓噿銆傚彇鑰屼唬涔嬶紝浠栦細姣忔瀵圭潃涓€澶村ザ鐗涘彨閬?ldquo;鎸夐『搴忔帓濂?rdquo;銆傚綋涓€澶村ザ鐗涜鍙埌鐨勬椂鍊欙紝濂逛細纭繚鑷繁鍦ㄩ槦浼嶄腑鐨勯『搴忔槸姝g‘鐨勶紙浠庡ス鐨勮搴︾湅鏉ワ級銆傚綋鏈変竴澶寸揣鎺ュ湪濂瑰彸杈圭殑濂剁墰鐨勭紪鍙锋瘮濂瑰皬锛屽ス浠氨浜ゆ崲浣嶇疆銆傜劧鍚庯紝褰撴湁涓€澶寸揣鎺ュ湪濂瑰乏杈圭殑濂剁墰鐨勭紪鍙锋瘮濂瑰ぇ锛屽ス浠氨浜ゆ崲浣嶇疆銆傝繖鏍疯繖澶村ザ鐗涘氨瀹屾垚浜?ldquo;鎸夐『搴忔帓濂?rdquo;锛屽湪杩欏ご濂剁墰鐪嬫潵宸﹁竟鐨勫ザ鐗涚紪鍙锋瘮濂瑰皬锛屽彸杈圭殑濂剁墰缂栧彿姣斿ス澶с€?/span>

FJ鎯宠閫夊嚭杩欎簺濂剁墰鐨勪竴涓瓙闆嗭紝鐒跺悗閬嶅巻杩欎釜瀛愰泦锛屼緷娆″鐫€姣忎竴澶村ザ鐗涘彂鍙锋柦浠わ紙鎸夌紪鍙烽€掑鐨勯『搴忥級锛岄噸澶嶈繖鏍风洿鍒版墍鏈塏澶村ザ鐗涙帓濂介『搴忋€備緥濡傦紝濡傛灉濂归€夊嚭浜嗙紪鍙蜂负 2,4,5 鐨勫ザ鐗涚殑瀛愰泦锛岄偅涔堜粬浼氬枈鍙ザ鐗?锛岀劧鍚庢槸濂剁墰4锛岀劧鍚庢槸濂剁墰5銆傚鏋?nbsp;N 澶村ザ鐗涙鏃朵粛鏈帓濂介『搴忎粬浼氬啀娆″鐫€杩欏嚑澶村ザ鐗涘枈鍙紝濡傛灉鏈夊繀瑕佺殑璇濈户缁噸澶嶃€?/span>

鐢变簬FJ涓嶇‘瀹氬摢浜涘ザ鐗涙瘮杈冧笓蹇冿紝浠栨兂瑕佷娇寰楄繖涓瓙闆嗘渶灏忋€傛澶栵紝浠栬涓?nbsp;K 鏄釜骞歌繍鏁板瓧銆傝甯粬姹傚嚭婊¤冻閲嶅鍠婂彨鍙互浣垮緱鎵€鏈夊ザ鐗涙帓濂介『搴忕殑鏈€灏忓瓙闆嗕箣涓瓧鍏稿簭绗?nbsp;K 灏忕殑瀛愰泦銆?/span>

鎴戜滑绉?nbsp;1,,N 鐨勪竴涓瓙闆?nbsp;S 鍦ㄥ瓧鍏稿簭涓嬪皬浜庡瓙闆?nbsp;T 锛屽綋 S 鐨勬墍鏈夊厓绱犵粍鎴愮殑搴忓垪锛堟寜鍗囧簭鎺掑垪锛夊湪瀛楀吀搴忎笅灏忎簬 T 鐨勬墍鏈夊厓绱犵粍鎴愮殑搴忓垪锛堟寜鍗囧簭鎺掑垪锛夈€備緥濡傦紝 1,3,6 鍦ㄥ瓧鍏稿簭涓嬪皬浜?nbsp;1,4,5 銆?/span>

棰樼洰鍒嗘瀽

瑙傚療棰樼洰锛岃€冭檻涓€鐩村鏌愪釜闆嗗悎閲岀殑鍏冪礌涓€鐩村彂鍙锋柦浠や細浜х敓浠€涔堢粨鏋溿€傛樉鐒舵槗瑙侊紝璇ラ泦鍚堥噷鐨勬墍鏈夊厓绱犻兘鏈€缁堜細琚帓鍒拌嚜宸遍偅涓渶“鍚堥€?rdquo;鐨勪綅缃紝鑰岄泦鍚堝閮ㄧ殑鍏冪礌椤哄簭涓嶄細鏀瑰彉銆?/span>

鏃㈢劧鎴戜滑瑕佽鍏ㄩ儴鍏冪礌浠庡皬鍒板ぇ鎺掑垪锛屾垜浠璁?閫変腑闆嗗悎 澶栭儴鐨勫厓绱犳湁搴忋€?/span>

杩欐牱鐨勮瘽锛屾垜浠繀椤诲厛姹傚嚭 “閫変腑闆嗗悎 澶栭儴鐨勫厓绱犳湁搴?rdquo; 鐨勪釜鏁般€傛樉鐒讹紝杩欏氨鏄釜LIS闂銆?/span>

璁剧疆缁撴瀯浣?Fi琛ㄧず浠ユ潈鍊间负 i 缁撳熬鐨?nbsp;LIS鐨勯暱搴﹀拰鏁伴噺锛屽垯鍙互浠庢潈鍊煎湪 浠?nbsp;?~ i1?闂磋浆绉昏繃鏉ワ紝鐢ㄦ爲鐘舵暟缁勭淮鎶ゅ墠缂€鏈€澶у€煎拰鏁伴噺鍗冲彲O(logn)鏃堕棿鍐呰В鍐炽€?/span>

 鍥炲埌鏈锛屾垜浠彲浠ュ厛鐢ㄧ被浼肩殑鏂规硶锛屾眰鍑轰互姣忎釜鐐?strong>寮€澶?/strong>鐨凩IS鐨勬渶闀块暱搴﹀拰鏁伴噺銆傝繖闇€瑕佹垜浠€掕繃鏉P锛屽苟鐢ㄦ爲鐘舵暟缁勭淮鎶ゅ悗缂€鍜岃€岄潪鍓嶇紑鍜屻€?/p>

 

鍦ㄦ眰鍑鸿繖浜涗互鍚庯紝鎴戜滑浠庡墠寰€鍚庢壂涓€閬嶏紝鎶婃瘡涓厓绱犳寜浠ュ畠寮€澶寸殑LIS闀垮害锛屾斁鍒皀涓獀ector閲屻€傦紙涓轰粈涔堟槸n涓紝鍥犱负鍙兘搴忓垪鏈韩灏辨槸鏈夊簭锛岄暱搴︿负n锛?/p>

鐒跺悗鎴戜滑鎸夐暱搴︽帹銆傚浜庢瘡涓暱搴︼紝渚濇閬嶅巻杩欎釜vector锛堝凡缁忓瓧鍏稿簭浠庡ぇ鍒板皬浜嗭級锛屽鏋滃綋鍓嶄綅缃甶寮€澶寸殑LIS鏁伴噺num(i)<k锛屽垯k-=num(i)锛屽惁鍒欐垜浠閫夌殑灏辨槸褰撳墠浣嶃€?/p>

娉ㄦ剰閫変簡浣嶇疆i浠ュ悗锛屽皬浜巌鐨勪綅缃兘涓嶈兘鍐嶉€夛紝闇€瑕佹妸杩欎簺浣嶇疆鐨凩IS鏁伴噺娓呴浂銆?/p>

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const ll Inf=1e18+10;
 5 const int MAXN=1e5+10;
 6 
 7 ll k;
 8 int n;
 9 int a[MAXN];
10 
11 struct Node
12     int len;ll num;
13     Node(int len_=0,ll num_=0)len=len_;num=num_;
14 BIT[MAXN],f[MAXN];
15 
16 
17 inline void Work(Node &x,Node y)
18     if(x.len>y.len) return;
19     if(x.len<y.len) x=y;
20     else x.num=min(Inf,x.num+y.num); 
21 
22 inline int lowbit(int x)
23     return x&(-x);
24 
25 inline void Update(int x,Node y)
26     for(int i=x;i;i-=lowbit(i))
27         Work(BIT[i],y);
28 
29 inline Node Query(int x)
30     Node res=Node(0,1);
31     for(int i=x;i<=n;i+=lowbit(i))
32         Work(res,BIT[i]);
33     return res;
34 
35 vector<int> v[MAXN];
36 bool used[MAXN];
37 int main()
38     scanf("%d%lld",&n,&k);
39     for(int i=1;i<=n;++i)
40         scanf("%d",&a[i]);
41     for(int i=n;i>=1;--i)
42         f[i]=Query(a[i]+1);
43         f[i].len++;
44         Update(a[i],f[i]);
45     
46     for(int i=1;i<=n;++i)
47         v[f[i].len].push_back(i);
48     for(int len=Query(1).len,r=1;len>=1;--len)
49         for(int i=0;i<(int)v[len].size();++i)
50             int tmp=v[len][i];
51             if(f[tmp].num<k) k-=f[tmp].num;
52             else
53                 used[a[tmp]]=1;
54                 while(r<=tmp) f[r++].num=0;
55                 break;
56             
57         
58     
59     printf("%d\n",n-Query(1).len);
60     for(int i=1;i<=n;++i)
61         if(!used[i])
62             printf("%d\n",i);
63     return 0;
64 

 

以上是关于USACO 2018 December Contest Platinum T2: Sort It Out的主要内容,如果未能解决你的问题,请参考以下文章

USACO 2007 December Contest, Silver Problem 2. Building Roads Kruskal最小生成树算法

USACO 2015 December Contest Max Flow (bzoj4390)

USACO 2017 December GoldA Pie for a Pie 题解

USACO 2017 December GoldA Pie for a Pie 题解

USACO 2017 December Contest Platinum T2: Push a Box

USACO 2017 December Contest Platinum T3: Greedy Gift Takers