PAT 1016 Mice and Rice (25)
2016-07-24 11:44
323 查看
思路
1.这个问题有点烦,感觉可以总结一下2总结就是当下一轮还大于1的话,继续往下分
3.首先每p个找出最大的值m以及m_id
4.然后把这个最大的id装到原来的order中,用num计数
5..更新remain,记得其他的的排名要在原来的基础上加next,即剩下的个数。
我出错的一些点
1.不想吐槽了,这道题每个英文单词每句话都看懂了,就是没理解题目是什么意思。就是这句,The third line gives the initial playing order which is a permutation of 0,…NP-1.2.最后那个只有一个了,就退出循环了,所以最后所有都加一。
代码
#include <iostream> #include <vector> #include <math.h> #include<algorithm> using namespace std; int main() { ios::sync_with_stdio(false); int n, p; cin >> n >> p; vector<int> mouse(n),order(n),sx(n,0); for (int i = 0; i < n; i++) { cin >> mouse[i]; } for (int i = 0; i < n; i++) { cin >> order[i]; } int remain = n; //这个问题有点烦,感觉可以总结一下 //总结就是当下一轮还大于1的话,继续往下分 //1.首先每p个找出最大的值m以及m_id //2.然后把这个最大的id装到原来的order中 //3.更新remain,记得其他的的排名要在原来的基础上加next,即剩下的个数 while (remain>1) { int num = 0; //cout << "remain:" << remain << endl; for (int i = 0; i < remain; i = i + p) { /*cout << "order:" << endl; for (int i = 0; i < remain; i++) { if (i != n - 1) cout << order[i] << " "; else cout << order[i] << endl; }*/ int m = -1,m_id=-1; for (int j = 0; j < p&&i+j<remain; j++) { //cout << "aaa" << endl; int ch = order[i + j]; //m = max(mouse[ch], m); //这里出错了卧槽 //m_id = ch; if (m < mouse[ch]) { m = mouse[ch]; m_id = ch; } } //cout << "m:" << m << " m_id:" << m_id << endl; for (int j = 0; j < p&&i + j<remain; j++) { //cout << "bbb" << endl; int ch = order[i + j]; if (ch != m_id) { //cout << "bb" << endl; int next = (remain + p - 1) / p; sx[ch]=sx[ch]+next; } } order[num++] = m_id; } /*if (remain == 1) { int ch = order[0]; for (int i = 0; i < n&&i!=ch; i++) { sx[i]++; } break; }*/ remain = (remain + p - 1) / p; } for (int i = 0; i < n; i++) { //最后那个只有一个了,就退出循环了,所以最后所有都加一 if (i != n - 1) cout << sx[i] + 1 << " "; else cout << sx[i]+1 << endl; } return 0; }
相关文章推荐
- 超级表格创始人中学时代揭秘
- ubuntu中source insight打不开,报错pagefault的解决方法
- DOM
- 《浪潮之巅》观后感
- poj 1201 Intervals [差分约束]
- Python之Pycharm常用快捷键
- 7.22号布置的作业
- IO - 同步,异步,阻塞,非阻塞
- UDP协议点对点(P2P)通讯(或者说NAT穿越)实例
- 盒子模型简介
- ubuntu 上查看内存信息
- FHIR概述
- CodeForces 437C The Child and Toy
- 上海 交通卡退卡规则,余额给退吗
- 辗转相除求gcd
- Ubuntu从入门到精通 ubuntu如何设置和打开3D效果桌面
- 21. Merge Two Sorted Lists(Sort)
- POJ 1703 Find themCatch them
- 用Fiddler模拟低速网络环境 差网络模拟工具 http 500是什么意思?
- 《计算机图形学》2.1.3 随机扫描显示器