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 ...
随机推荐
- layer自定义弹窗样式
1.下载并引用js, 官网http://layer.layui.com/ 文档http://www.layui.com/doc/modules/layer.html <link href=&qu ...
- drf02 序列化器详解 Serializer
作用 1. 序列化,序列化器会把模型对象转换成字典,经过response以后变成json字符串2. 反序列化,把客户端发送过来的数据,经过request以后变成字典,序列化器可以把字典转成模型3. 反 ...
- BZOJ 1715: [Usaco2006 Dec]Wormholes 虫洞 DFS版SPFA判负环
Description John在他的农场中闲逛时发现了许多虫洞.虫洞可以看作一条十分奇特的有向边,并可以使你返回到过去的一个时刻(相对你进入虫洞之前).John的每个农场有M条小路(无向边)连接着N ...
- esp32(M5STACK)程序烧写(Ubuntu)
由于我们的开发环境在Ubuntu上,所以介绍一下如何在Ubuntu上烧写esp32的程序 首先下载esptools pip install esptool 擦除 sudo es ...
- 【剑指Offer】29、最小的K个数
题目描述: 输入n个整数,找出其中最小的K个数.例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4. 解题思路: 本题最直观的解法就是将输入的n个整数排 ...
- 11.5 【Linq 】连接
11.5.1 使用 join 子句的内连接 如果你打算把一个巨大的序列连接到一个极小的序列上,应尽可能把小序列作为右边序列 class Program { static void Main(strin ...
- html第七节课
document 1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个: var a ...
- 51nod1185 威佐夫游戏 V2【博弈论】
有2堆石子.A B两个人轮流拿,A先拿.每次可以从一堆中取任意个或从2堆中取相同数量的石子,但不可不取.拿到最后1颗石子的人获胜.假设A B都非常聪明,拿石子的过程中不会出现失误.给出2堆石子的数量, ...
- [bzoj4477 Jsoi2015]字符串树 (可持久化trie)
传送门 Solution 复习下tire( ̄▽ ̄)/ 裸的可持久化tire,我用树剖求了下LCA Code #include <cstdio> #include <cstring&g ...
- js中二维数组的创建方法 2017-04-04 14:50 120人阅读 评论(0) 收藏
法一:var myarr=[[0,1,2],[1,2,3]]; 将[0,1,2]看做原来的0,将[1,2,3]看做原来的1,而二者又分别为子数组 如myarr[0][1]=1,myarr[1][1]= ...