B. After Training

来源:互联网 发布:朔州seo快速优化软件 编辑:程序博客网 时间:2024/05/20 20:43
B. After Training
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 hasn balls andm baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from1 tom, correspondingly. The balls are numbered with numbers from1 ton.

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 n,m(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
2132
Input
3 1
Output
111
//超时的代码:O(n*n*logn)#include <iostream>#include <cstdio>#include <vector>#include <map>#include <set>#include <string>#include <cstring>#include <cstdlib>#include <cmath>#include <utility>#include <algorithm>using namespace std;const int maxn = 1e5+10;int n, m;struct bas{    int num;    int balln;};bool cmp(const bas & a, const bas & b){    double x = (m+1)/2.0-a.num;    double y = (m+1)/2.0-b.num;    if (x < 0)    {        x = -x;    }    if (y < 0)    {        y = -y;    }    if (a.balln != b.balln)    {        return a.balln < b.balln;    }    else if (x != y)    {        return x < y;    }    else    {        return a.num < b.num;    }}bas b[maxn];int main(){    while (scanf("%d%d", &n, &m) != EOF)    {        for (int i=1; i<=m; i++)        {            b[i].num = i;            b[i].balln = 0;        }        while (n--)        {            sort(b+1, b+m+1, cmp);            b[1].balln++;            cout << b[1].num << endl;        }    }    return 0;}
//AC代码:O(n*logn)#include <iostream>#include <cstdio>#include <vector>#include <map>#include <set>#include <string>#include <cstring>#include <cstdlib>#include <cmath>#include <utility>#include <algorithm>using namespace std;const int maxn = 1e5+10;int n, m;struct bas{    int num;    int balln;};struct rule{    bool operator()(const bas & a, const bas & b)    {        double x = (m+1)/2.0-a.num;        double y = (m+1)/2.0-b.num;        if (x < 0)        {            x = -x;        }        if (y < 0)        {            y = -y;        }        if (a.balln != b.balln)        {            return a.balln < b.balln;        }        else if (x != y)        {            return x < y;        }        else        {            return a.num < b.num;        }    }};//bas b[maxn];set<bas, rule> b;set<bas, rule> :: iterator it;int main(){    bas ba;    scanf("%d%d", &n, &m);    for (int i=1; i<=m; i++)    {        ba.num = i;        ba.balln = 0;        b.insert (ba);    }    while (n--)    {        ba = *b.begin();        ba.balln++;        cout << ba.num << endl;        b.erase(b.begin());        b.insert (ba);    }    return 0;}

终于又有一次这样的开心O(∩_∩)O~~,,,独自解决问题的成就感,哦呵呵~
0 0
原创粉丝点击