A.Pretty Matrix
水题没啥好说的。。。就是我刚开始CE了。。。www
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int Maxn = 2e5+10;
int main()
{
ios::sync_with_stdio(false);
int t,n,m,A,B,x;
cin>>t;
while(t--)
{
int f_no = 0,cnt = 0;
cin>>n>>m>>A>>B;
if(A > B)
f_no = 1;
if(!f_no)
{
for(int i = 0;i < n;i++)
{
for(int j = 0;j < m;j++)
{
cin>>x;
if(x < A || x > B)
cnt++;
}
}
cout<<cnt<<endl;
}
else{
for(int i = 0;i < n;i++)
for(int j = 0;j < m;j++)
cin>>x;
cout<<"No Solution"<<endl;
}
}
return 0;
}
B.Mergeable Stack
队友dl敲得一手漂亮的数据结构哈哈哈哈,注意一下这两个函数splice VS merge
merge:
要求原始list有序
splice:
不要求有序
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <stack>
#include<list>
using namespace std;
const int maxn=3e5+5;
int n,q,op,s,v,t;
list<int> ls[maxn];
int main()
{
int T;scanf("%d",&T);
while(T--)
{
for(int i=0;i<maxn;i++) ls[i].clear();
scanf("%d%d",&n,&q);
while(q--)
{
scanf("%d",&op);
if(op==1)
{
scanf("%d%d",&s,&v);
ls[s].push_back(v);
}
else if(op==2)
{
scanf("%d",&s);
if(ls[s].empty())puts("EMPTY");
else
{
printf("%d\n",ls[s].back());
ls[s].pop_back();
}
}
else
{
scanf("%d%d",&s,&t);
if(ls[t].empty())continue;
else
ls[s].splice(ls[s].end(),ls[t]);
}
}
}
return 0;
}