首页 > 其他分享 >8.16

8.16

时间:2023-08-16 19:44:05浏览次数:33  
标签:cnt idx int sum long 8.16 root

#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 105;
queue<char> v[maxn]; ///存储每个轨道上的物品
stack<char> s;  ///筐
queue<char> q;  ///结果输出
int main()
{
    int N,M,S;
    int a[1005];
    char ch;
    cin>>N>>M>>S;
    getchar();
    for(int i=1;i<=N;i++){
        for(int j=0;j<M;j++){
            cin>>ch;
            v[i].push(ch);
            a[i]++;
        }
        getchar();
    }
    int x;
    while(true){
        cin>>x;
        if(x==-1)break;
        if(x==0){
            if(s.size()==0)continue;    //如果筐里面的为空就不做任何处理,跳过
            else{
                q.push(s.top());        //否则,弹出栈顶元素,放入流水线上
                s.pop();
            }
        }
        if(x>=1 && x<=N){
            if(v[x].size()==0)continue;        //如果对应轨道上没有物品了不做任何处理,跳过
            else{
                if(s.size()==S){    //如果筐已经满了,就弹出筐顶物品到流水线上,再将物品放入框中
                    q.push(s.top());
                    s.pop();
                }
                s.push(v[x].front());
                v[x].pop();
            }
        }
    }
    /*
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cout<<v[i][j];
        }
    }
    */
    while(!q.empty()){
        cout<<q.front();
        q.pop();
    }
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e4 + 10,M=1000010;
int h[N],e[M],ne[M],idx;
int n;
int cnt;
bool vis[N];
vector<int> temp,ans;
void add(int a,int b){
    e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}
void dfs(int u,int sum){
    if(sum>cnt){
        cnt=sum;
        ans=temp;
    }
    else if(sum==cnt&&temp<ans){
        ans=temp;
    }
    for(int i=h[u];~i;i=ne[i]){
        int j=e[i];
        temp.push_back(j);
        dfs(j,sum+1);
        temp.pop_back();
    }
}
int main()
{
    memset(h,-1,sizeof h);
    cin>>n;
    for(int i=0;i<n;i++){
        int k;
        cin>>k;
        while(k--){
            int a;
            cin>>a;
            add(i,a);
            vis[a]=true;
        }
    }
    int root=0;
    while(vis[root])root++;
    dfs(root,1);
    cout<<cnt<<endl;
    cout<<root;
    for(int i=0;i<ans.size();i++){
        cout<<' '<<ans[i];
    }
    return 0;
}

 

标签:cnt,idx,int,sum,long,8.16,root
From: https://www.cnblogs.com/xuxingkai/p/17636042.html

相关文章

  • 2023.8.16 周三:Java论文提交管理系统
    1packageSystem;2importjava.util.Scanner;3publicclassPaperManagement{4publicstaticvoidmain(String[]args){5Scannerscanner=newScanner(System.in);6ScoreInformation[]students=newScoreInformation[5];......
  • 2023.8.16 关于先前函数内外声明变量差异问题的答案
    答案:编译器无法在编译时求得一个非常量的值,它只能在运行时通过读取变量地址来间接得到变量的值,而全局变量在编译时就必须确定其值,故C有静态存储区数据必须用常量初始化的规定。在编译时只能用常量去初始化一个静态存储区的数据,而不能用“读取某个变量的内容”来初始化。来源:外部......
  • 【比赛】8.16
    Ⅰ.LYKlovesstring通过限定元素的先后可以将\(10^10\)优化成\(10!\),再加一些剪枝就可以过了。#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;constintmod=1e9+7;intread(){ intx=0,f=1;charch=getchar(); while(ch<'0'||......
  • 8.16集训笔记
    上午/一维数组排序排序:sort,冒泡,选择,插入,计数复杂度:\(O(nlogn),O(n^2),O(n^2),O(n^2),O(n)\)点击查看代码#include<bits/stdc++.h>#include<algorithm>usingnamespacestd;constintN=1e5+10;inta[N],n;intmain(){//cin>>n;//for(inti=1;i<=n;......
  • 2023.8.16
    今天不是生日,也没有节日,普通得不能再普通的一天。无聊随意翻网站,偶然翻到了两年前生日发的博客,不知道为何内心有点波澜,想写点东西,但也不知道写什么。回忆我回忆起了2021年3月14日,我正坐在图书馆三楼(可能是)我一个很少光顾的位置上,午后阳光很懒,慢慢撒到桌子上,映红半张草稿纸,我在费......
  • ApacheCN 活动汇总 2019.8.16
    公告欢迎大家在我们平台上投放广告。如果你希望在我们的专栏、文档或邮件中投放广告,请准备好各种尺寸的图片和专属链接,我们组织了一个开源互助平台,方便开源组织和大V互相认识,互相帮助,整合资源。请回复这个帖子并注明组织/个人信息来申请加入。请回复这个帖子来推荐希望翻译的内容......
  • vue项目报错:Node.js v18.16.1 error Command failed with exit code 1.
    原因:把node升级到了最新的长期支持版18.16.1,结果运行vue项目启动失败,报错如下:试了各种办法都解决不了,后面只能把node降级到16.20.1运行项目又可以启动了......
  • Win7使用最新的node.js(版本18.16.0)
    截至本文的发布时间2023.06.11,前端开发基础工具node.js的最新版本是18.16.0LTS可能有人要问,为什么要研究node.js在Win7系统下的兼容情况呢?你直接用Win10不就行了?如果你可以直接使用Win10,显然你不是这篇文章的推荐阅读对象,因为某些开发环境比较特殊,只能使用Win7而不允许使用Win......
  • 8.16 instanceof 关键词
    demo1classPerson{publicvoidrun(){System.out.println("run.....");}}classSupermanextendsPerson{publicvoidfly(){System.out.println("超音速飞....");}publicvoidfire(){System.ou......
  • centos7 安装python3.8.16
    升级openssl下载opensslopenssl官方下载地址:https://www.openssl.org/source/wgethttps://github.com/openssl/openssl/archive/OpenSSL_1_1_1d.tar.gz解压tar-zxvfOpenSSL_1_1_1d.tar.gz编译安装进入openssl-OpenSSL_1_1_1dcdopenssl-OpenSSL_1_1_1d指定安装......