【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 ...
随机推荐
- Android Fragment 你应该知道的一切
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/42628537,本文出自:[张鸿洋的博客] 很久以前写过两篇Fragment的介绍 ...
- box-shadow 的一些使用
1.只有左侧有阴影 box-shadow: -10px 0px 3px 1px #aaaaaa;
- css3动画的两种方式transition和@keyframs
- smarty foreach循环
1,smarty foreach1,单纯的数组array(1000,2000,3000),使用foreach(from = $array item=foo){$foo}2,键值对数组<ul> ...
- HTTP 错误 500.22 - Internal Server Error
HTTP 错误 500.22 - Internal Server Error 检测到在集成的托管管道模式下不适用的 ASP.NET 设置. 最可能的原因: 此应用程序在 system.web/http ...
- 5 个最好的3D游戏开发工具(转)
转自:http://www.open-open.com/news/view/33a4f0 5 个最好的3D游戏开发工具 jopen 2012-11-19 22:56:21 • 发布 摘要:UDK(th ...
- DEDECMS之十 修改织梦链和文章的默认来源及作者
今天在用织梦搭网站的时候,发现了两个问题,一个就是最新的dedecms5.7系统中默认会加上“织梦链”这一个链接组,织梦的做法是可以理解的, 但是给别人做网站,这些链接是不能要的,所以在数据库,模板文 ...
- vs2015企业版太大了
安装教程 http://www.cnblogs.com/mephisto/archive/2015/07/22/4666032.html#!comments 新功能 http://news.cnblo ...
- httpserver
改了下 # -*- coding:utf-8 -*- from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler HOST = &quo ...
- Ultra-QuickSort
Description In this problem, you have to analyze a particular sorting algorithm. The algorithm proce ...