包装机
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
queue<char> d[1100];
stack<char> q;
int main()
{
int n,m,s;
cin >> n >> m >> s ;
for(int i=1;i<=n;i++)
{
for(int j=0;j<m;j++)
{
char x;
cin >> x ;
d[i].push(x);
}
}
int t;
while(cin >> t , t!=-1)
{
if(t==0)
{
if(!q.empty())
{
cout << q.top() ;
q.pop();
}
}
else
{
if(!d[t].empty())
{
int ss=q.size();
if(ss==s)
{
cout << q.top() ;
q.pop();
}
q.push(d[t].front());
d[t].pop();
}
}
}
return 0;
}
病毒溯源
#include <iostream>
#include <cstring>
using namespace std;
const int N = 10010;
int n;
int h[N], e[N], ne[N], idx;
bool st[N];
int son[N];
void add(int a, int b)
{
e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}
int dfs(int u)
{
int res = 0;
son[u] = -1;
for (int i = h[u];~i;i = ne[i])
{
int j = e[i];
int d = dfs(j);
if (res < d)res = d, son[u] = j;
else if (res == d) son[u] = min(son[u], j);
}
return res + 1;
}
int main()
{
memset(h, -1, sizeof h);
cin >> n;
for(int i=0;i<n;i++)
{
int cnt;cin >> cnt;
while (cnt--)
{
int x;
cin >> x;
add(i, x);
st[x] = true;
}
}
int root = 0;
while (st[root++]);
root--;
cout << dfs(root) << endl;
cout << root;
while (son[root] != -1)
{
root = son[root];
cout << ' ' << root;
}
system("pause");
}
清点代码库
#include <iostream>
#include <vector>
#include <map>
using namespace std;
vector<int>v;
map <vector <int>, int> mp;
multimap <int, vector<int>, greater<int> >mup;
int main()
{
int n, m;
cin >> n >> m;
v.resize(m);
for(int i = 1; i <= n; i++)
{
for(int j = 0; j < m; j++)
{
cin >> v[j];
}
mp[v]++;
}
for(auto it : mp)
{
mup.insert({it.second, it.first});
}
cout << mup.size() << endl;
for(auto it1:mup)
{
cout << it1.first;
for(auto it2 : it1.second)
{
cout << " " << it2;
}
cout << endl;
}
return 0;
}
哲哲打游戏
#include <iostream>
#include <vector>
using namespace std;
const int N=100004;
vector <int> v[N];
int dan[N],p=1;
int main()
{
int n, m;
cin >> n >> m;
for(int i = 1;i <= n; i++)
{
int k;
cin >> k;
while (k--)
{
int x;
cin >> x;
v[i].push_back(x);
}
}
while (m--)
{
int x, y;
cin >> x >> y;
if(x == 0)
{
p=v[p][y-1];
}
else if(x == 1)
{
dan[y] = p;
cout << p << endl;
}
else
{
p = dan[y];
}
}
cout << p;
return 0;
}