题目链接:Codeforces 384B Multitasking
题目大意:给出n,m,k,表示说有n个长度为m的序列,要求进行排序,最多执行m*(m-1)/2次交换,给出每次交换的位置,k为1的话交换位置大的在前面,k=0,小的在前面。
解题思路:贪心,直接冒泡排序,次数刚好是m*(m-1)/2次。
#include <stdio.h>
#include <string.h>
int main () {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) scanf("%*d");
printf("%d\n", m * (m - 1) / 2);
if (k) {
for (int i = m; i > 1; i--) {
for (int j = m; j > m - i + 1; j--) printf("%d %d\n", j, j-1);
}
} else {
for (int i = m - 1; i; i--) {
for (int j = 1; j <= i; j++) printf("%d %d\n", j, j+1);
}
}
return 0;
}
分享到:
相关推荐
Codeforces - 1107B. Digital root & 1107C. Brutality(规律 & 贪心)Codeforces - 1107B.
Codeforces 1105B - Zuhair and Strings 测试点37个(全)
Codeforces 题库 101-200 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
Codeforces 题库 001-100 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
codeforces编程网站预测分数插件
使用于Google Chrome的Codeforces Enhancer 1.1.2插件安装包。 版本:codeforces enhancer 1.1.2 使用浏览器:Google Chrome
Codeforces 185A - Plant 全测试点49个
codeforces 19 E Fairy 一道比较难的题目的解题报告 推荐阅读
Codeforces global round 10 codes
暴枚最长桌脚的长度$l$,然后长度比$l$长的桌脚全部都要砍掉长度比$l$短的桌脚选择代价前$k$小的砍掉用线段树维护;示例程序 :typedef long l
Codeforces round 678 division 2 codes
Some of the Codeforces problems codes
Codeforces - 1131C. Birthday(贪心)题目链接题目给你n和n个数,要你重新排列n个数,使得这些数的相邻差值中最大的那个值最小。stat
lucifer1004大佬的博客cf上分攻略故里大佬的githubcf思维题刷题数:44- (1421)codeforces 676 div2 A,B done
Codeforces round 678 D2_Codeforces_源码
一个Codeforces、牛客竞赛、AtCoder平台的编程竞赛查询插件,ACMer必备.zip
打codeforces的神器
codeforces-js Codeforces JS
接受串子-接受字符串相等-接受Codeforces回合#684(Div.2) 2/6 1440A-购买琴弦-接受1440B -中位数的总和-已接受1440C1-二进制表(简易版)-已接受1440C2-二进制表(硬版)-已接受 Codeforces回合#683(分区2) 1/...
Codeforces Round #723 (Div. 2).md