#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int n;
int a[1007][1007],t[1007],p[1007];
queue<int>q[2];//每次把消去的选手扔进队列,避免无法消去的选手被频繁访问,暴力模拟会N^3复杂度,只对新的选手进行遍历大概只有N^2复杂度
int main(){
cin>>n;
for(int i=1;i<=n;++i)
for(int j=1;j<n;++j)
cin>>a[i][j];
for(int i=1;i<=n;++i)
q[0].push(i);
int now=1;
for(int day=1,tot=n*(n-1)/2;day<=n*(n-1)/2;++day){
now^=1;
while(!q[now].empty()){
int x=q[now].front();
q[now].pop();
int y=a[x][++t[x]];
if(p[y]==x){
tot--;
q[1-now].push(x);
q[1-now].push(y);
p[x]=p[y]=0;
}
else
p[x]=y;
}
if(!tot){
cout<<day<<endl;
return 0;
}
}
cout<<-1<<endl;
return 0;
}

Atcoder Beginner Contest 139E(模拟,思维)的更多相关文章

  1. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  2. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

  3. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

  4. AtCoder Beginner Contest 161

    比赛链接:https://atcoder.jp/contests/abc161/tasks AtCoder Beginner Contest 161 第一次打AtCoder的比赛,因为是日本的网站终于 ...

  5. AtCoder Beginner Contest 223

    AtCoder Beginner Contest 223 A是纯纯的水题,就不说了 B - String Shifting 思路分析 我真的sb,一开始想了好久是不是和全排列有关,然后读了好几遍题目也 ...

  6. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

  7. AtCoder Beginner Contest 148 题解

    目录 AtCoder Beginner Contest 148 题解 前言 A - Round One 题意 做法 程序 B - Strings with the Same Length 题意 做法 ...

  8. AtCoder Beginner Contest 238 A - F 题解

    AtCoder Beginner Contest 238 \(A - F\) 题解 A - Exponential or Quadratic 题意 判断 \(2^n > n^2\)是否成立? S ...

  9. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

随机推荐

  1. django 创建管理员用户

    7.2 create 创建管理员用户: python manage.py run server python manage.py createsuperuser password :123456789 ...

  2. Java日期时间API系列13-----Jdk8中java.time包中的新的日期时间API类,时间类转换,Date转LocalDateTime,LocalDateTime转Date等

    从前面的系列博客中可以看出Jdk8中java.time包中的新的日期时间API类设计的很好,但Date由于使用仍非常广泛,这就涉及到Date转LocalDateTime,LocalDateTime转D ...

  3. 修改环境变量后,导致一些常用命令失效,如ll,ls,vi不能用

    因为一不小心将linux的环境变量修改错误,导致ll之类的常用命令都不能用,很是苦恼,通过百度查询,原来在敲命令时,敲完整的命令路径,还是可以的: 原文地址:http://www.cnblogs.co ...

  4. 分布式一致性协议 --- Paxos

    问题 Paxos 到底解决什么样的问题,动机是什么 Paxos 流程是怎么样的? Paxos 算法的缺陷是什么 概述 Paxos 是分布式一致性算法,根据少数服从多数的原则多个节点确定某个数值.通过学 ...

  5. SpringCloud全家桶学习之Feign负载均衡----Feign(四)

    一.Feign概述 (1)Feign是什么? 官网地址:https://projects.spring.io/spring-cloud/spring-cloud.html#spring-cloud-f ...

  6. vscode 提示 Running save participants 无法保存文件

    今天vscode提示一直在running save participants...中,无法保存文件 control + shift + p打开面板后,输入Reload with extensions ...

  7. photoshop下载(ps)

    https://pan.baidu.com/s/1bNrUod2n1VqsA7Fr9RHtsg

  8. systomctl与service的区别主要是版本区别

    redhat和centos在7及以后的版本,用systemctl命令 redhat和centos在6及6以前的版本,用service命令. 两者的区别,如下. 举例 这里的.service可以不写,如 ...

  9. Spring Boot 使用 Dom4j XStream 操作 Xml

    Xml 现在仍然占据着比较重要的地位,比如微信接口中使用了 Xml 进行消息的定义.本章重点讨论 Xml 的新建.编辑.查找.转化,可以这么理解,本章是使用了 dom4j.xstream 也是在开发者 ...

  10. Linux下如何查看tomcat是否启动、查看tomcat启动日志(转)

    在Linux系统下,重启Tomcat使用命令的操作! 1.首先,进入Tomcat下的bin目录 cd /usr/local/tomcat/bin 使用Tomcat关闭命令 ./shutdown.sh ...