2021天梯赛

包装机

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值