*【CodeForces - 195B】After Training (多解,模拟)

题干:

After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has n balls and m baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to m, correspondingly. The balls are numbered with numbers from 1 to n.

Valeric decided to sort the balls in the order of increasing of their numbers by the following scheme. He will put each new ball in the basket with the least number of balls. And if he's got several variants, he chooses the basket which stands closer to the middle. That means that he chooses the basket for which  is minimum, where i is the number of the basket. If in this case Valeric still has multiple variants, he chooses the basket with the minimum number.

For every ball print the number of the basket where it will go according to Valeric's scheme.

Note that the balls are sorted into baskets in the order of increasing numbers, that is, the first ball goes first, then goes the second ball and so on.

Input

The first line contains two space-separated integers nm (1 ≤ n, m ≤ 105) — the number of balls and baskets, correspondingly.

Output

Print n numbers, one per line. The i-th line must contain the number of the basket for the i-th ball.

Examples

Input

4 3

Output

2
1
3
2

Input

3 1

Output

1
1
1

题目大意:

     有n个球,m个篮子,  要把这n个球放进这些篮子,首先放篮子中求最少的篮子,若数量相同再放距离中间篮子最近的,若距离相同放篮子编号小的。

解题报告:

   这个题解法很多啊,比较常见的一种就是打表,把i对应位置取模的值打表一下,然后直接输出biao[i]。第二种方法是优先队列。第三种set,或者线段树貌似都可以。

AC代码:

#include<bits/stdc++.h>
using namespace std;int main()
{int n,m;cin>>n>>m;for(int i = 0; i<n; i++) printf("%d\n",(m+i%m)%2 ? ((m+i%m+1)/2) : (m-(i%m))/2);return 0 ;
}

set做法还未看:

   其实就是按照规定的顺序建立set或者优先队列,然后每次取出队首,做出处理再放入容器。

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <string.h>
#include <map>
#include <set>
using namespace std;
#define maxn 100005*3
#define inff 1<<30
struct node
{int val,dis,id;node(int val,int dis,int id):val(val),dis(dis),id(id){}friend bool operator <(node x,node y){if(x.val<y.val)return true;else if(x.val == y.val){if(x.dis<y.dis)return true;else if(x.dis==y.dis){if(x.id<y.id)return true;else return false;}else return false;}else return false;}
};
int abs(int x)
{if(x<0)return -x;else return x;
}
int n,m;
int a[maxn];
int main()
{set<node>s;int i;while(scanf("%d%d",&n,&m)!=EOF){s.clear();int mid1,mid2;if(m%2!=0){mid1=mid2=(m+1)/2;}else{mid1=m/2;mid2=mid1+1;}for(i=1;i<=m;i++){node tx(0,min(abs(mid1-i),abs(mid2-i)),i);s.insert(tx);}for(i=1;i<=n;i++){node tx=*s.begin();s.erase(s.begin());a[i]=tx.id;tx.val++;s.insert(tx);}for(i=1;i<=n;i++){printf("%d\n",a[i]);}}return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441419.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

pandas打印全部列_python——pandas练习题1-5

练习1-开始了解你的数据探索Chipotle快餐数据相应数据集&#xff1a;chipotle.tsvimport pandas as pd chipopd.read_csv("exercise_data/chipotle.tsv",sept) chipo.head(5)chipo.shape[0] #查看有多少行4622chipo.shape[1] #查看有多少列5chipo.columns #打印所…

【POJ - 2406】Power Strings (KMP,最小循环节)

题干&#xff1a; Given two strings a and b we define a*b to be their concatenation. For example, if a "abc" and b "def" then a*b "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative in…

python wmi mac变动_Python WMI参数反转

使用python的wmi模块创建vss快照&#xff0c;我发现除非将它们反向&#xff0c;否则这些参数将不起作用&#xff1a;importwmidefvss_create():shadow_copy_servicewmi.WMI(monikerwinmgmts:\\\\.\\root\\cimv2:Win32_ShadowCopy)resshadow_copy_service.Create(ClientAccessib…

【 HDU - 2594 】Simpsons’ Hidden Talents(KMP应用,求最长前缀后缀公共子串)

题干&#xff1a; Homer: Marge, I just figured out a way to discover some of the talents we weren’t aware we had. Marge: Yeah, what is it? Homer: Take me for example. I want to find out if I have a talent in politics, OK? Marge: OK. Homer: So I take…

python两次调用write连续写入的数据之间_两次调用文件的write 方法,以下选项中描述正确的是...

两次调用文件的write 方法&#xff0c;以下选项中描述正确的是答&#xff1a;连续写入的数据之间无分隔符中国大学MOOC: 斜弯曲、拉(压)弯曲组合变形的危险点都是单向应力状态。答&#xff1a;对急性宫外孕破裂或的最主要症状是答&#xff1a;突然一侧下腹部撕裂样疼痛Some thi…

拉格朗日差值 - 杜教板子

牛客网暑期ACM多校训练营(第一场) F Sum of Maximum 杜教板子&#xff1a; 证明https://blog.csdn.net/Lee_w_j__/article/details/81135539 #include <cstdio> #include <iostream> #include <vector> #include <cstring> #include <algorithm&…

python归并排序 分词_python实现归并排序,归并排序的详细分析

学习归并排序的过程是十分痛苦的。它并不常用&#xff0c;看起来时间复杂度好像是几种排序中最低的&#xff0c;比快排的时间复杂度还要低&#xff0c;但是它的执行速度不是最快的。很多朋友不理解时间复杂度低为什么运行速度不一定快&#xff0c;这个不清楚的伙伴可以看下我之…

CCFCSP 2018年9月 -- 部分题目

CCF201809 -- 第一题 &#xff1a;买菜 问题描述   在一条街上有n个卖菜的商店&#xff0c;按1至n的顺序排成一排&#xff0c;这些商店都卖一种蔬菜。   第一天&#xff0c;每个商店都自己定了一个正整数的价格。店主们希望自己的菜价和其他商店的一致&#xff0c;第二天…

servlet中显示mysql字段_Java Servlet:从数据库获取信息并在屏幕上显示它

创建它代表了表的每一个项目(行)一个JavaBean类。创建一个使用JDBC返回这些项目列表的DAO类。然后在servlet中&#xff0c;只需使用HttpServletRequest#setAttribute()将请求范围中的项目列表&#xff0c;使用RequestDispatcher#forward()将请求转发到JSP文件&#xff0c;并使用…

【CodeForces - 689B】Mike and Shortcuts(Dijkstra最短路,或者bfs跑状态类似spfa)

题干&#xff1a; Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of n intersections numbered from 1 to n. Mike starts walking from his house located a…

sqlserver mysql分页_SQLServer与MySQL中分页查询sql语句示例

/***author blovedr*功能&#xff1a;SQLServer与MySQL中分页查询sql语句示例*日期&#xff1a; 2018年8月17日 10:58*注释&#xff1a; 学习数据库MySQL的点点记录&#xff0c; 谢谢网上各位大神分享经验与资料&#xff0c; 欢迎大神批评与交流。*/分页查询 2018.8.16 …

【51Nod - 1103】N的倍数 (思维,鸽巢原理也叫抽屉定理,求倍数问题取模)

题干&#xff1a; 一个长度为N的数组A&#xff0c;从A中选出若干个数&#xff0c;使得这些数的和是N的倍数。 例如&#xff1a;N 8&#xff0c;数组A包括&#xff1a;2 5 6 3 18 7 11 19&#xff0c;可以选2 6&#xff0c;因为2 6 8&#xff0c;是8的倍数。 Input 第1行…

java位操作_关于java按位操作运算

<1>.在了解位移之前&#xff0c;先了解一下正数和负数的二进制表示形式以及关系&#xff1a;举例15和-15&#xff1a;15 的原码&#xff1a; 00000000 00000000 00000000 00001111补码&#xff1a; 11111111 11111111 11111111 111100001 -15的原码&#xff1a;11111111 …

【51Nod - 1117 】聪明的木匠 (贪心,哈夫曼树,时光倒流)

题干&#xff1a; 一位老木匠需要将一根长的木棒切成N段。每段的长度分别为L1,L2,......,LN&#xff08;1 < L1,L2,…,LN < 1000&#xff0c;且均为整数&#xff09;个长度单位。我们认为切割时仅在整数点处切且没有木材损失。 木匠发现&#xff0c;每一次切割花费的体…

java生成16位随机数_java中如何产生一个16位数字组成的随机字符串?谢谢各位了...

展开全部方法如下&#xff1a;Random rannew random();boolean flagtrue;while(flag){int aran.nextInt(99999999);int bran.nextInt(99999999);long ca*100000000Lb;if(c>1000000000000000L&&c<9999999999999999L){flagfalse;c1c;String numString.valueOf(c1);…

java utf-8 gbk_Java 字符转码之UTF-8转为GBK/GB2312

java跟python类似的做法&#xff0c;在java中字符串的编码是java修改过的一种Unicode编码&#xff0c;所以看到java中的字符串&#xff0c;心理要默念这个东西是java修改过的一种Unicode编码的编码。packagestring;importjava.nio.charset.Charset;public classUTF82GBK {publi…

【CodeForces - 760B 】Frodo and pillows (二分题意,注意细节)

题干&#xff1a; n hobbits are planning to spend the night at Frodos house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of cour…

eclipse wsdl2java_使用Eclipse的wsdl2java工具

一、用Eclipse调用Axis的wsdl2java1.在eclipse里面新建一个项目或已有的项目&#xff1b;2.导入activation.jaraxis.jarcommons-discovery.jarcommons-logging-1.0.3.jarjaxrpc.jarsaaj.jarwsdl4j-1.5.2.jar包3右击你的工程&#xff0d;Run As&#xff0d;Run...&#xff0d;右…

【POJ - 2785】4 Values whose Sum is 0 (二分,折半枚举)

题干&#xff1a; The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute how many quadruplet (a, b, c, d ) ∈ A x B x C x D are such that a b c d 0 . In the following, we assume that all lists have the same…

java好的博客_推荐5个万博爆款Java开源博客,是我目前用过最好用的博客系统

1.OneBlog一个简洁美观、功能强大并且自适应的Java博客&#xff0c;使用springboot开发&#xff0c;前端使用Bootstrap&#xff0c;支持移动端自适应&#xff0c;配有完备的前台和后台管理功能。功能简介多种编辑器、自动申请友情链接、百度推送、评论系统、权限管理、SEO、实时…