日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UVA 11995 I Can Guess the Data Structure! STL

發布時間:2025/3/21 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UVA 11995 I Can Guess the Data Structure! STL 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

  題目鏈接: UVA很難登上去吧......

  題目大意: 給你幾組輸入與輸出讓你判斷是棧,隊列, 堆, 還是不確定, 還是哪種也不是

  解題思路: 這題看起來很簡單, 搞幾個標準STL, 和結果一對比就知道了, 坑點就是棧, 隊列或堆在判斷.top的時候會溢出造成RE, 在這兒坑了兩次, 一開始還以為是不是全局不行

  代碼:?

#include <queue> #include <stack> #include <iostream> #include <cstdio> #include <algorithm> #include <vector> using namespace std;int ans[100]; stack<int> S; queue<int> Q; priority_queue<int> PQ;int main() {int n;while( scanf( "%d", &n ) != EOF ) {while( !S.empty() ) {S.pop();}while( !Q.empty() ) {Q.pop();}while( !PQ.empty() ) {PQ.pop();}ans[0] = ans[1] = ans[2] = 1;while( n-- ) {int op, num;scanf( "%d%d", &op, &num );if( op == 1 ) {S.push(num);Q.push(num);PQ.push(num);}else {if( ans[0] && !Q.empty() ) {int temp = Q.front();Q.pop();if( num != temp ) ans[0] = 0;}else ans[0] = 0;if( ans[1] && !S.empty() ) {int temp = S.top();S.pop();if( num != temp ) ans[1] = 0;}else ans[1] = 0;if( ans[2] && !PQ.empty() ) {int temp = PQ.top();PQ.pop();if( num != temp ) ans[2] = 0;}else ans[2] = 0;}}int sum = ans[0] + ans[1] + ans[2];if( sum == 1 ) {if( ans[0] == 1 ) {printf( "queue\n" );}else if( ans[1] == 1 ) {printf( "stack\n" );}else {printf( "priority queue\n" );}}else if( sum == 0 ) {printf( "impossible\n" );}else {printf( "not sure\n" );}}return 0; } View Code

  思考: 這題就是考細心的啊, 還記得去年第一次組隊打多校的時候就是遇到了這個坑點, 總RE, 最后花了三個多小時才找到錯誤, 自己現在卻還是不長記性, 所以以后遇到棧等需要取偷拍top或者pop操作的時候, 先判空!

轉載于:https://www.cnblogs.com/FriskyPuppy/p/7240235.html

總結

以上是生活随笔為你收集整理的UVA 11995 I Can Guess the Data Structure! STL的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。