题目
每次把空列换到最后一列,把非空行换到最下一行。

#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(模拟)的更多相关文章

  1. CodeForces.158A Next Round (水模拟)

    CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...

  2. Codeforces 747C:Servers(模拟)

    http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...

  3. Codeforces 740A. Alyona and copybooks 模拟

    A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...

  4. 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 ...

  5. CodeForces 670 A. Holidays(模拟)

    Description On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Ma ...

  6. Codeforces 280D k-Maximum Subsequence Sum [模拟费用流,线段树]

    洛谷 Codeforces bzoj1,bzoj2 这可真是一道n倍经验题呢-- 思路 我首先想到了DP,然后矩阵,然后线段树,然后T飞-- 搜了题解之后发现是模拟费用流. 直接维护选k个子段时的最优 ...

  7. 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 ...

  8. CodeForces - 586C Gennady the Dentist 模拟(数学建模的感觉)

    http://codeforces.com/problemset/problem/586/C 题意:1~n个孩子排成一排看病.有这么一个模型:孩子听到前面的哭声自信心就会减弱:第i个孩子看病时会发出v ...

  9. Codeforces 703B. Mishka and trip 模拟

    B. Mishka and trip time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

随机推荐

  1. onSaveInstanceState() 和 onRestoreInstanceState()

    本文介绍Android中关于Activity的两个神秘方法:onSaveInstanceState() 和 onRestoreInstanceState(),并且在介绍这两个方法之后,再分别来实现使用 ...

  2. jq分页异步刷新 ,全局刷新问题

    在做分页的时候,可能点击下一页全部刷新 这样写会导致动态刷新,页面全部刷新了 $("#pageList a").click(function () { var $s = $(thi ...

  3. Javascript 代码格式化(JsFormat)

    JsFormat 在GitHub 上的地址: https://github.com/jdc0589/JsFormat 这是一个sublime text 2 的插件. 安装: 先安装 sublime p ...

  4. XAMPP部署

    1,直接从官网上下载,然后安装即可 2,出现的问题: a,启动Apache服务器的时候,出现打开端口失败,原因80号端口已被占用,解决方案,更改config文件,将端口设置为8090 b,给phpmy ...

  5. try catch finally的执行顺序(有return的情况下)

    结论:1.不管有木有出现异常,finally块中代码都会执行:2.当try和catch中有return时,finally仍然会执行:3.finally是在return后面的表达式运算后执行的(此时并没 ...

  6. DEDECMS之九 文章采集

    到很多网友都为织梦(DEDECMS)的采集教程头疼,的确,官方出的教程太笼统了,什么都没说,换个网站你什么都做不了,这个教程是最详尽的教程,让你一看即会! 一.列表采集 第一步.我们打开织梦后台点击采 ...

  7. 【MVC】自定义Scaffold Template

    MVC提供了基本的CRUD Scaffold Template模板,创建视图的时候,只要勾选创建一个强类型视图 , 并选择模型类,就可以选择支架模板了,这些模板包括List,Detail,Create ...

  8. Cordova - 常用的插件汇总(附插件的安装、查询、更新、删除等命令)

    Hybrid应用比web应用强大之处在于可以使运行在容器中的web内容访问 native APIs.Cordova 提供了许多插件用于调用移动设备上的API. 一,插件相关常用命令   1,查看所有已 ...

  9. ASP.NET性能优化之减少请求

    在上篇<ASP.NET性能优化之让浏览器缓存动态网页> 中的方案中,浏览器发送If-Modified-Since将是否需要使用自己的缓存交给WEB服务器去决定,服务器告知浏览器去读缓存,浏 ...

  10. expect的爱恨情仇

    背景 openvpn生成证书想把它做成一键化,这样添加新用户时候就方便 遇到的问题 我的代码 gg_vpn_keys.exp #!/usr/bin/expect set user [lindex $a ...