您当前的位置: 首页 > 

先求一个导

暂无认证

  • 4浏览

    0关注

    291博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

pta L2-32,没事别break.

先求一个导 发布时间:2021-03-09 19:26:07 ,浏览量:4

https://pintia.cn/problem-sets/994805046380707840/problems/1111914599412858889 天梯赛,栈的基本应用,有手就行,然而第一个点没过(逃

题目简述: 给你T个测试案例.每次有n个数,从1-n,扔到一个容量为m的栈里,每个元素入栈后可以立即出栈,也可以待里边.判断元素出栈的序列能否形成1-n,即1 2 3 4 5…n这样的.

十分代码,一手break导致后续数据没有输入完,最值钱的点白给,呆的一.

/*
就算是现在在的大学很无聊 就算现在的专业你不喜欢 就算是有些必修课你不想上
你也要把它当作是你去往另一个平台的通行证。
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define OldTomato ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef pair PII;
typedef long long ll;
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int N = 1e5+10;
const int mod = 1e9+7;
const double eps = 1e-6;
inline int lowbit(int x){ return x&(-x);}
int n,m,k,T;
void fun()
{
  OldTomato;
  cin>>n>>m>>T;
  while(T--)
  {
    stack st; //每个测试案例清空栈. 
    int tmp = 1; //当前应该装卸的货物. 
    bool flag = false;
    for(int i=0;i>x;
       if(x==tmp)
	   {
	      tmp++;
	      while(st.size()&&st.top()==tmp) //只有当恰好放的这个与之匹配,才有可能从栈顶开始清.
		  {
		      st.pop();
			  tmp++;  
		  }   
	   } 
	   else  //不匹配,压栈. 
	   {
	        st.push(x);
	        if(st.size() > m) //只有压栈才会导致栈的size增加 
	        {
	           break;
			}
	   }
	}	
	while(st.size()&&st.top()==tmp)  //放完货物以后,可以全部出栈. 
	{
	   tmp++; st.pop();
	}
    if(st.empty()) flag = true;
	if(flag) cout m) //只有压栈才会导致栈的size增加 
	        {
	          flag = false;  //不能break,会导致后续的输入没输入完,淦.
			}
	   }
	}	
    if(st.empty()&&flag) cout            
关注
打赏
1662037414
查看更多评论
0.0429s