CodeForces - 1517B Morning Jogging
B. Morning Jogging
time limit per test1 second
memory limit per test256 megabytes
The 2050 volunteers are organizing the “Run! Chase the Rising Sun” activity. Starting on Apr 25 at 7:30 am, runners will complete the 6km trail around the Yunqi town.
There are n+1 checkpoints on the trail. They are numbered by 0, 1, …, n. A runner must start at checkpoint 0 and finish at checkpoint n. No checkpoint is skippable — he must run from checkpoint 0 to checkpoint 1, then from checkpoint 1 to checkpoint 2 and so on. Look at the picture in notes section for clarification.
Between any two adjacent checkpoints, there are m different paths to choose. For any 1≤i≤n, to run from checkpoint i−1 to checkpoint i, a runner can choose exactly one from the m possible paths. The length of the j-th path between checkpoint i−1 and i is bi,j for any 1≤j≤m and 1≤i≤n.
To test the trail, we have m runners. Each runner must run from the checkpoint 0 to the checkpoint n once, visiting all the checkpoints. Every path between every pair of adjacent checkpoints needs to be ran by exactly one runner. If a runner chooses the path of length li between checkpoint i−1 and i (1≤i≤n), his tiredness is
mini=1nli,min_{i=1}^nli,mini=1nli,
i. e. the minimum length of the paths he takes.
Please arrange the paths of the m runners to minimize the sum of tiredness of them.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤10000). Description of the test cases follows.
The first line of each test case contains two integers n and m (1≤n,m≤100).
The i-th of the next n lines contains m integers bi,1, bi,2, …, bi,m (1≤bi,j≤109).
It is guaranteed that the sum of n⋅m over all test cases does not exceed 104.
Output
For each test case, output n lines. The j-th number in the i-th line should contain the length of the path that runner j chooses to run from checkpoint i−1 to checkpoint i. There should be exactly m integers in the i-th line and these integers should form a permuatation of bi,1, …, bi,m for all 1≤i≤n.
If there are multiple answers, print any.
Example
input
2
2 3
2 3 4
1 3 5
3 2
2 3
4 1
3 5
output
2 3 4
5 3 1
2 3
4 1
3 5
Note
In the first case, the sum of tiredness is min(2,5)+min(3,3)+min(4,1)=6.
In the second case, the sum of tiredness is min(2,4,3)+min(3,1,5)=3.
问题链接:CodeForces - 1517B Morning Jogging
问题简述:(略)
问题分析:(略)
AC的C++语言程序如下:
/* CodeForces - 1517B Morning Jogging */#include <bits/stdc++.h>using namespace std;const int INF = 0x3F3F3F3F;
const int N = 100 + 1;
int b[N][N], ans[N][N], l[N], r[N];int main()
{int t, n, m;scanf("%d", &t);while (t--) {scanf("%d%d", &n, &m);for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++)scanf("%d", &b[i][j]);sort(b[i], b[i] + m);l[i] = 0, r[i] = m - 1;}for (int i = 0; i < m; i++) {int minb = INF, idx = 0;for (int j = 0; j < n; j++)if (b[j][l[j]] < minb)idx = j, minb = b[j][l[j]];for (int j = 0; j < n; j++)if (j == idx)ans[i][j] = b[j][l[j]++];elseans[i][j] = b[j][r[j]--];}for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++)printf("%d ", ans[j][i]);printf("\n");}}return 0;
}
CodeForces - 1517B Morning Jogging相关推荐
- Contest 2050 and Codeforces Round #718 B. Morning Jogging
题目连接:https://codeforces.com/contest/1517/problem/B The 2050 volunteers are organizing the "Run! ...
- Morning Jogging(贪心)
Morning Jogging - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) Problem - 1517B - Codeforce #include <bits/stdc+ ...
- CodeForces 375D Tree and Queries
传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...
- 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)
题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...
- 【codeforces 812C】Sagheer and Nubian Market
[题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...
- CodeForces 获得数据
针对程序的输出可以看见 CodeForces :当输入.输出超过一定字符,会隐藏内容 所以:分若干个程序进行输入数据的获取 1. 1 for (i=1;i<=q;i++) 2 { 3 scanf ...
- codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)...
题目链接:http://www.codeforces.com/problemset/problem/281/A 题意:将一个英文字母的首字母变成大写,然后输出. C++代码: #include < ...
- CodeForces 595A
题目链接: http://codeforces.com/problemset/problem/595/A 题意: 一栋楼,有n层,每层有m户,每户有2个窗户,问这栋楼还有多少户没有睡觉(只要一个窗户灯 ...
- codeforces A. Jeff and Digits 解题报告
题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...
最新文章
- Volley 源码解析之图片请求
- sql和mysql一起,SQL连接和MySQL
- 5.分布式数据库HBase第1部分
- Linux下实现USB口的热插拔
- Linux基础练习题(三)
- 计算机科学导论课后单词,计算机科学导论课后总结
- 2021-2025年中国点状插头装置行业市场供需与战略研究报告
- Makefile 入门教程
- ViewPager和Tabhost结合,可滑动的tabhost
- 域名生意逆市火爆 BNS能否接棒ENS?
- Spring 漏洞及其修复方案
- 棕榈油跌停见顶,铁矿石认沽上涨,YP05惊天大反弹2022.3.14
- 短视频风口持续 今日头条再投10亿补贴火山小视频
- 设计模式01-七大设计原则
- 告别脚本小子系列丨JAVA安全(6)——反序列化利用链(上)
- 免费好用的PC端屏幕录制软件
- 使用GitHub Actions通过CI提高代码质量
- Ubuntu下使用opera的坑
- 卡巴斯基KAV/KIS 6.0.1.411正式版下载 附MP1版中文汉化+注册码
- 体验TiDB V6.0.0 之Clinic
热门文章
- 阿群笔记:CentOS7 在线安装 docker 的推荐方法
- Springboot 跨域配置
- JQuery:常用方法一览
- Spark 解析 : DAGScheduler中的DAG划分与提交
- oracle 10g rac 停止,Oracle10g RAC 关闭及启动
- spark运行wordcount
- php 日志增强,php 日志扩展
- ajax跨域请求wcf服务,jQuery ajax跨域发布到WCF休息服务
- 编写程序,用户输入一个位以上的整数,输出其百位以上的数字。例如用户输入1234.则程序输出12.
- C++11新特性——auto和decltype