*【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 #打印所…

【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…

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…

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

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

中介者模式java_图解Java设计模式之中介者模式

智能家庭项目1)智能家庭包括各种设备&#xff0c;闹钟、咖啡机、电视机、窗帘等2)主人要看电视时&#xff0c;各个设备可以协同工作&#xff0c;自动完成看电视的准备工作&#xff0c;比如流程为 &#xff1a;闹铃响起 - 》咖啡机开始做咖啡 -》窗帘自动落下 -》电视机开始播放…

【POJ - 2398】Toy Storage (计算几何,二分找位置,叉积,点和直线的位置关系)

题干&#xff1a; Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing with them. They gave Reza a rectangular box to put his toys in. Unfortunately, Reza is rebellious and obeys his parents by simply throwing …

java servlet 转发和重定向_JavaWeb(一)Servlet中乱码解决与转发和重定向的区别

前言前面其实已经把Servlet中所有的内容都介绍完了&#xff0c;这篇讲补充一点乱码和重定向与转发之间的区别&#xff01;一、request请求参数出现乱码问题1.1、get请求1)乱码示例get请求的参数是在url后面提交过来的&#xff0c;也就是在请求行中。结果&#xff1a;Servlet_de…

java jsp导出pdf文件_JSP页面导出PDF格式文件

JSP页面导出PDF格式文件基本在前端页面可以全部完成添加下载链接的点击事件var downPdf document.getElementById("downLoad");downPdf.onclick function() {downPdf.parentNode.removeChild(downPdf);html2canvas(document.body, {onrendered:function(canvas) {v…

java unsafe park_Java中Unsafe类详解

http://www.cnblogs.com/mickole/articles/3757278.htmlJava不能直接访问操作系统底层&#xff0c;而是通过本地方法来访问。Unsafe类提供了硬件级别的原子操作&#xff0c;主要提供了以下功能&#xff1a;1、通过Unsafe类可以分配内存&#xff0c;可以释放内存&#xff1b;类中…

【qduoj - 夏季学期创新题】骑士游历(递推dp)

题干&#xff1a; 描述 输入 输入包含多组数据&#xff0c;第一行T表示数据组数接下来每行六个整数n&#xff0c;m&#xff0c;x1&#xff0c;y1&#xff0c;x2&#xff0c;y2(分别表示n&#xff0c;m&#xff0c;起点坐标&#xff0c;终点坐标) 输出 输出T行&#xff0c;表示…

java ee 6 源码_Java EE 6开发手册·高级篇(第4版)

资源名称&#xff1a;Java EE 6开发手册高级篇(第4版)内容简介&#xff1a;《Java EE 6 开发手册?高级篇(第4 版)》是一本面向实战、以示例为驱动、在Java 平台企业版6(Java EE 6)上开发企业级应用的指南。该指南基于The Java EE 6 Tutorial: Basic Concepts&#xff0c;Fourt…

【qduoj - 夏季学期创新题】矩形剖分(递归,dp)

题干&#xff1a; 描述 对一个给定的矩形&#xff0c;将其划分成尽可能少的正方形&#xff0c;输出正方形的最少个数。例如&#xff0c;如下图所示的情况&#xff0c;则输入为3和4&#xff0c;输出为4。 输入 输入两个整数中间用空格分开。 输出 输出最少分割成的正方形的个…

学分绩点计算编程java_方便我们计算学分绩点的JavaScript

基于目前我们学校教务处的管理系统, 依靠Javascript的帮忙, 我们可以很方便地计算成绩.测试用HTML:style"width: 100%; border-collapse: collapse;">课程代码课程名称课程性质成绩补考成绩重修成绩学分绩点辅修标记24109505数据库系统实验专业基础课优秀0.54.502…

【POJ - 2663】Tri Tiling (简单dp)

题干&#xff1a; In how many ways can you tile a 3xn rectangle with 2x1 dominoes? Here is a sample tiling of a 3x12 rectangle. Input Input consists of several test cases followed by a line containing -1. Each test case is a line containing an integer …

【POJ - 1556】The Doors (计算几何,线段相交)

题干&#xff1a; You are to find the length of the shortest path through a chamber containing obstructing walls. The chamber will always have sides at x 0, x 10, y 0, and y 10. The initial and final points of the path are always (0, 5) and (10, 5). Th…

【POJ - 1696】Space Ant (凸包,最小极角,排序)

题干&#xff1a; The most exciting space discovery occurred at the end of the 20th century. In 1999, scientists traced down an ant-like creature in the planet Y1999 and called it M11. It has only one eye on the left side of its head and just three feet al…

2019蓝桥杯Java决赛题答案_2019第十届蓝桥杯JavaB组省赛真题详解

目录题解待更新第一题&#xff1a;组队题目描述做为篮球队教练&#xff0c;你须要从如下名单中选出 1 号位至 5 号位各一名球员&#xff0c; 组成球队的首发阵容。每位球员担任 1 号位至 5 号位时的评分以下表所示。请你计算首发阵容 1 号位至 5 号位的评分之和最大多是多少&am…

java map统计学生名单_Java含自己的总结:集合,学生,遍历,ArrayList,Set,Map,泛型,班级,发牌—诗书画唱...

声明一个ArrayList&#xff0c;存储一条学生信息&#xff0c;内容为 1 张三 22 男&#xff0c;将信息进行遍历出来package list;import java.util.ArrayList;import java.util.Iterator;public class student{public static void main(String[] args) {ArrayList jiHe…

java生成world文件_HelloWorld.java文件如何创建?

原创HelloWorld.java文件如何创建&#xff1f;编辑:小丸子 来源:PC下载网时间:2017-10-17 19:55:54相信各位刚接触JAVA的新人都希望尽快编写出自己的第一个程序,今天PC下载网小编和你一起学习HelloWorld程序1.首先我们先点击“开始”—然后是“所有程序”—在然后是“附件”—记…

wifisetting.java_Wifi 笔记 | 启动流程

csd&#xff1a;csdn_of_coder/article/details/51541094aosp: Android OAndroid网络各个模式中&#xff0c;Wifi应该是目前最常用的一种网络方式了&#xff1b;下面就简单介绍下Android中Wifi的启动流程。当我在Setting菜单里点击打开Wifi时&#xff0c;调用的入口函数是WifiM…