[2019鏉數澶氭牎绗叚鍦篯[hdu6635]Nonsense Time
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[2019鏉數澶氭牎绗叚鍦篯[hdu6635]Nonsense Time相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/targe' title='targe'>targe for can lse mes using include algorithm pre
棰樼洰閾炬帴锛?a href="http://acm.hdu.edu.cn/showproblem.php?pid=6635" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=6635
棰樻剰鏄涓€寮€濮嬫墍鏈夋暟閮藉喕缁擄紝绗琲绉掍細瑙e喕绗琸i涓暟锛屾眰姣忕鐘舵€佷笅鐨勬渶闀夸笂涓婂崌瀛愬簭鍒楅暱搴︺€?/p>
杩欑棰樹竴鎯虫坊鍔犳搷浣滃氨涓嶅ソ瀹炵幇锛屾墍浠ュ共鑴嗗弽鐫€鏉ワ紝鎯冲垹闄ゆ搷浣溿€?/p>
浠庣n绉掑紑濮嬪線鍓嶉亶鍘嗭紝姣忔閮戒細鍐荤粨涓€涓暟锛岃繖鏃跺垽鏂竴涓嬭繖涓暟鏄惁涓€瀹氳鍦ㄦ渶闀夸笂鍗囧瓙搴忓垪閲屻€?/p>
浣跨敤浜屽垎鐨勬柟娉曟眰鏈€闀夸笂鍗囧瓙搴忓垪锛屽苟涓旀瘡娆℃眰瀹屽瓙搴忓垪鍚庡彲浠ュ鐞嗗嚭閭d簺浣嶇疆鏄繀椤诲湪鏈€闀夸笂鍗囧瓙搴忓垪閲岀殑銆?/p>
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<string> 5 #include<algorithm> 6 #include<queue> 7 using namespace std; 8 const int maxn = 5e4 + 10; 9 int a[maxn], vis[maxn], ans[maxn], d[maxn], in[maxn], dp[maxn]; 10 int len; 11 void slove(int n) 12 len = 0; 13 for (int i = 1; i <= n; i++) 14 if (a[i] != 0) 15 int pos = lower_bound(d + 1, d + 1 + len, a[i]) - d; 16 if (pos > len) 17 d[++len] = a[i]; 18 else 19 d[pos] = a[i]; 20 dp[i] = pos; 21 22 23 int q = len, limit = n; 24 for (int i = n; i >= 1; i--) 25 if (dp[i] == q && a[i] <= limit && a[i] != 0) 26 limit = a[i]; 27 in[i] = 1; 28 q--; 29 30 else 31 in[i] = 0; 32 33 34 int main() 35 int t; 36 scanf("%d", &t); 37 while (t--) 38 int n; 39 scanf("%d", &n); 40 for (int i = 1; i <= n; i++) 41 scanf("%d", &a[i]); 42 for (int i = 1; i <= n; i++) 43 scanf("%d", &vis[i]); 44 slove(n); 45 for (int i = n; i >= 1; i--) 46 ans[i] = len; 47 a[vis[i]] = 0; 48 if (in[vis[i]])slove(n); 49 50 for (int i = 1; i <= n; i++) 51 printf("%d%c", ans[i], i == n ? 鈥?/span>\n鈥?/span> : 鈥?/span> 鈥?/span>); 52 53
以上是关于[2019鏉數澶氭牎绗叚鍦篯[hdu6635]Nonsense Time的主要内容,如果未能解决你的问题,请参考以下文章