B. After Training
来源:互联网 发布:朔州seo快速优化软件 编辑:程序博客网 时间:2024/05/20 20:43
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.
The first line contains two space-separated integers n,m(1 ≤ n, m ≤ 105) — the number of balls and baskets, correspondingly.
Print n numbers, one per line. The i-th line must contain the number of the basket for the i-th ball.
4 3
2132
3 1
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~~,,,独自解决问题的成就感,哦呵呵~
- B. After Training
- CodeForces 195B After Training(STL)
- Codeforces 195B After Training 线段树的维护
- K - After Training CodeForces 195B-找规律
- Codeforces Round #123 (Div. 2) B - After Training
- After Summer Training.
- [HDU5764] After a Sleepless Night [2016 Multi-University Training Contest 4(2016多校联合训练4) B]
- hzau training 20170121 b
- ecjtu-summer training #5 B
- ecjtu-summer training #6 B
- SCUT Training 20170913 Problem B
- SCUT Training 20170920 Problem B
- 2014 UESTC Training for Search Algorithm B
- 2014 UESTC Training for Graph Theory B
- MZ Training 2014 #6 B题
- MZ Training 2014 #4 B题
- C. A and B and Team Training
- B Black Square----(2015 summer training #5)
- 实现div切换
- linux设备驱动第三篇:写一个简单的字符设备驱动
- java多线程知识小抄集(一)
- PHP代码优化的53个细节
- JS和app交互
- B. After Training
- C# winform DataGridt将行中标记字段转换为要展示的字段名称 比如0,1转换为是或否
- 源码安装rsyslog
- html5新版桌面通知
- ListView的精确定位 和 自下而上展示的ListView
- The Most Popular Java API Classes 地址
- Linux 内核定时器
- Python - Requests 模拟 DWR框架的请求
- pom.xm配置解析