【CodeForces 266C】Below the Diagonal(模拟)
题目
每次把空列换到最后一列,把非空行换到最下一行。
#include<cstdio>
#include<algorithm>
#define N 1005
using namespace std;
struct ans{int i,a,b;} a[100005];
int n,m,x,y,ma[N][N],r[N],c[N];
int main()
{
scanf("%d",&n);
for(int i=1; i<n; i++)
{
scanf("%d%d",&x,&y);
ma[x][y]=1;
r[x]++;
c[y]++;
}
for(; n; n--)
{
for(int i=1; i<n; i++)
if(c[i]==0)
{
a[m++]=(ans){2,n,i};
for(int j=1; j<=n; j++)
swap(ma[j][n],ma[j][i]);
swap(c[i],c[n]);
break;
}
for(int i=1; i<n; i++)
if(r[i])
{
a[m++]=(ans){1,n,i};
swap(ma[n],ma[i]);
swap(r[i],r[n]);
break;
}
for(int i=1; i<=n; i++)
if(ma[n][i])c[i]--;
}
printf("%d\n",m);
for(int i=0; i<m; i++)
printf("%d %d %d\n",a[i].i,a[i].a,a[i].b);
}
【CodeForces 266C】Below the Diagonal(模拟)的更多相关文章
- CodeForces.158A Next Round (水模拟)
CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...
- Codeforces 747C:Servers(模拟)
http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...
- Codeforces 740A. Alyona and copybooks 模拟
A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...
- Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))
A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- CodeForces 670 A. Holidays(模拟)
Description On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Ma ...
- Codeforces 280D k-Maximum Subsequence Sum [模拟费用流,线段树]
洛谷 Codeforces bzoj1,bzoj2 这可真是一道n倍经验题呢-- 思路 我首先想到了DP,然后矩阵,然后线段树,然后T飞-- 搜了题解之后发现是模拟费用流. 直接维护选k个子段时的最优 ...
- Codeforces 1090B - LaTeX Expert - [字符串模拟][2018-2019 Russia Open High School Programming Contest Problem B]
题目链接:https://codeforces.com/contest/1090/problem/B Examplesstandard input The most famous characters ...
- CodeForces - 586C Gennady the Dentist 模拟(数学建模的感觉)
http://codeforces.com/problemset/problem/586/C 题意:1~n个孩子排成一排看病.有这么一个模型:孩子听到前面的哭声自信心就会减弱:第i个孩子看病时会发出v ...
- Codeforces 703B. Mishka and trip 模拟
B. Mishka and trip time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
随机推荐
- javascript里面this机制的几个例子
javascript里面的this值会随着使用场景的不同二发生变化,但是总有一个原则,那就是this总指向当前调用函数的那个对象.以下我会举几个例子来说明这个问题.1.this本身总是指向当前的类的实 ...
- iOS SDWebImage使用详解
这个类库提供一个UIImageView类别以支持加载来自网络的远程图片.具有缓存管理.异步下载.同一个URL下载次数控制和优化等特征. 使用示范的代码:UITableView使用UIImageView ...
- C# 6.0
C# 6.0 的新语法特性 回眸 C# 的前世今生 - 见证 C# 6.0 的新语法特性 序 目前最新的版本是 C# 7.0,VS 的最新版本为 Visual Studio 2017 RC,两者都 ...
- SQL Server 用SSMS查看依赖关系有时候不准确,改用代码查
SQL Server 用SSMS查看依赖关系有时候不准确,明明某个sp中有用到表tohen,查看表tohen的依赖关系的时候,却看不到这个sp 用代码查看方式如下: --依赖于表tohen的对象 SE ...
- PageRank算法简介及Map-Reduce实现
PageRank对网页排名的算法,曾是Google发家致富的法宝.以前虽然有实验过,但理解还是不透彻,这几天又看了一下,这里总结一下PageRank算法的基本原理. 一.什么是pagerank Pag ...
- Python2.2-原理之类型和运算
此节来自于<Python学习手册第四版>第二部分 一.Python对象类型(第4章) 1. Python可以分解成模块.语句.表达式以及对象:1.程序由模块构成:2.模块包含语句:3.语句 ...
- Theano3.3-练习之逻辑回归
是官网上theano的逻辑回归的练习(http://deeplearning.net/tutorial/logreg.html#logreg)的讲解. Classifying MNIST digits ...
- centos7 安装nginx和php5.6.25遇到 无法访问php页面 报错file not found 问题解决
php-fpm安装完成,nginx安装完成 netstap -ntl| 发下端口正常开启 iptables -L 返现9000端口已经开放 ps -aux|grep nginx 发下nginx进程正常 ...
- 在SSIS 2012中使用CDC(数据变更捕获)
最新项目稍有空隙,开始研究SQL Server 2012和2014的一些BI特性,参照(Matt)的一个示例,我们开始体验SSIS中的CDC(Change Data Capture,变更数据捕获). ...
- WebHeaderCollection 类
https://msdn.microsoft.com/zh-cn/library/system.net.webheadercollection(v=VS.95).aspx /// <summar ...