E - Dividing Orange
Problem description
One day Ms Swan bought an orange in a shop. The orange consisted of n·k segments, numbered with integers from 1 to n·k.
There were k children waiting for Ms Swan at home. The children have recently learned about the orange and they decided to divide it between them. For that each child took a piece of paper and wrote the number of the segment that he would like to get: the i-th (1 ≤ i ≤ k) child wrote the number ai (1 ≤ ai ≤ n·k). All numbers ai accidentally turned out to be different.
Now the children wonder, how to divide the orange so as to meet these conditions:
- each child gets exactly n orange segments;
- the i-th child gets the segment with number ai for sure;
- no segment goes to two children simultaneously.
Help the children, divide the orange and fulfill the requirements, described above.
Input
The first line contains two integers n, k (1 ≤ n, k ≤ 30). The second line contains kspace-separated integers a1, a2, ..., ak (1 ≤ ai ≤ n·k), where ai is the number of the orange segment that the i-th child would like to get.
It is guaranteed that all numbers ai are distinct.
Output
Print exactly n·k distinct integers. The first n integers represent the indexes of the segments the first child will get, the second n integers represent the indexes of the segments the second child will get, and so on. Separate the printed numbers with whitespaces.
You can print a child's segment indexes in any order. It is guaranteed that the answer always exists. If there are multiple correct answers, print any of them.
Examples
Input
2 2
4 1
Output
2 4
1 3
Input
3 1
2
Output
3 2 1
解题思路:这道题看辣么久才看懂,真的是怀疑自己的智商QAQ。输出有k行,每行必须包含一个儿童想要的那块橙子块编号(该行的任意位置输出都可以),再输出n-1个橙子块的编号,编号不能有重复输出,[1,n*k]中每个编号只输出1次即可。
AC代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k,cnt=,a[],b[];
cin>>n>>k;
for(int i=;i<=n*k;++i)a[i]=i;
for(int i=;i<=k;++i){cin>>b[i];a[b[i]]=;}
for(int i=;i<=k;++i){
cout<<b[i];//每一行先输出b[i]
int t=;//t为计数器,一行输出n个数
while(t<n){
if(a[cnt]){cout<<' '<<a[cnt++];t++;}
else cnt++;
}
cout<<endl;
}
return ;
}
E - Dividing Orange的更多相关文章
- Codeforces Round #150 (Div. 2)
A. Dividing Orange 模拟. B. Undoubtedly Lucky Numbers 暴力枚举\(x.y\). C. The Brand New Function 固定左端点,右端点 ...
- 利用Python【Orange】结合DNA序列进行人种预测
http://blog.csdn.net/jj12345jj198999/article/details/8951120 coursera上 web intelligence and big data ...
- orange pi pc 体验(一)
最近在淘宝上看到一款和树莓派差不多的卡片机,定价才99元,而且是国产的,忍不住入手了一个,就是orange pi 感兴趣的可以百度搜索下,深圳一个公司出的,不过资料比树莓派少了很多,论坛中人也没多少, ...
- POJ 1014 Dividing
Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 66032 Accepted: 17182 Descriptio ...
- CF 371B Fox Dividing Cheese[数论]
B. Fox Dividing Cheese time limit per test 1 second memory limit per test 256 megabytes input standa ...
- AC日记——Dividing poj 1014
Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 69575 Accepted: 18138 Descri ...
- POJ 1014 Dividing(多重背包)
Dividing Description Marsha and Bill own a collection of marbles. They want to split the collectio ...
- Dividing a Chocolate(zoj 2705)
Dividing a Chocolate zoj 2705 递推,找规律的题目: 具体思路见:http://blog.csdn.net/u010770930/article/details/97693 ...
- 动态规划--模板--hdu 1059 Dividing
Dividing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
随机推荐
- AI:PR的数学表示-传统方法PR
前言: 接上一篇:AI:模式识别的数学表示 在图像处理PR领域,相对于ANN方法,其他的方法一般称为传统方法.在结构上,几乎所有的PR方法都是可解释的.且任一传统方法,在一定约束下,可以转换为SV近邻 ...
- SLAM: 图像角点检测的Fast算法(时间阈值实验)
作为角点检测的一种快速方法,FastCornerDetect算法比Harris方法.SIft方法都要快一些,应用于实时性要求较高的场合,可以直接应用于SLAM的随机匹配过程.算法来源于2006年的Ed ...
- (转)基于MVC4+EasyUI的Web开发框架经验总结(10)--在Web界面上实现数据的导入和导出
http://www.cnblogs.com/wuhuacong/p/3873498.html 数据的导入导出,在很多系统里面都比较常见,这个导入导出的操作,在Winform里面比较容易实现,我曾经在 ...
- POJ_3020_最小路径覆盖
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8721 Accepted: 4330 ...
- 在MySQL的表中增加一列
MySql中增加一列 如果想在一个已经建好的表中添加一列,可以用: alter table TABLE_NAME add column NEW_COLUMN_NAME varchar(45) not ...
- 【ABCD组】Scrum meeting 4
前言 第4次会议在6月16日由组长在教9 405召开. 主要对下一步的工作进行说明安排,时长90min. 主要内容 分配下阶段任务,争取在这阶段完成软件的设计阶段 任务分配 姓名 当前阶段任务 贡献时 ...
- vscode简单使用介绍及个人常用扩展插件
vscode全称Visual Studio Code 是微软开发一款IDE,官方地址 vscode 作为一款前端编辑器功能很强大,灵活,可以根据个人喜好选择扩展插件,而且还支持多种开发语言, 关于v ...
- Request中通过文件流获取文件
第一次写博客,希望能帮到以后接触到这里的同学,废话不多说,面对疾风吧. /** * 获取文件相信信息 * @param request HttpServletRequest实例 * @param im ...
- 【Codeforces 933A】A Twisty Movement
[链接] 我是链接,点我呀:) [题意] [题解] 因为只有1和2. 所以最后肯定是若干个1接着若干个2的情况. 即11...11222...222这样的. 1.首先考虑没有翻转的情况. 那么就直接枚 ...
- 重命名文件及html
import os import nltk from bs4 import BeautifulSoup as bs def get_txt_name_from_bak_name(bak_name): ...