zoukankan      html  css  js  c++  java
  • 数据结构 | 队列:1056(考验题目理解能力)

    给这题安上“队列”的标签其实是存疑的,因为这个模拟过程我都没有用到队列,而是用到vector。也没有用到先进先出的性质……

    其实这题思路不难,难的是题目的理解。难理解的一共两个点:

    ①第一行是按索引排列的重量,第二行是按索引排列的序号。结合permutaion(组合)这个单词,大概可以猜到陈越姥姥想表达,或者想设坑什么了。

    ②rank的计算。每一次循环都给vector里面的元素赋上rank属性,但是rank怎么计算呢?

    我在题目中勉强找到一个关于rank的描述:

     All the losers in this turn are ranked the same. Every NG winners are then grouped in the next match until a final winner is determined.

    那么“same”又是什么呢?手动再见。

    根据题解,或者自行对样例数据进行分析,rank=这一轮组数+1,最后的获胜者rank=1 。

    贴出OJ地址希望日后看懂题:Mice and Rice

    一个需要注意的点:每轮记录最大值是记录 weight 最大老鼠的 order

    AC代码:

    #include <stdio.h>
    #include <memory.h>
    #include <math.h>
    #include <string>
    #include <vector>
    #include <set>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <map>
    
    
    #define I scanf
    #define OL puts
    #define O printf
    #define F(a,b,c) for(a=b;a<c;a++)
    #define FF(a,b) for(a=0;a<b;a++)
    #define FG(a,b) for(a=b-1;a>=0;a--)
    #define LEN 10010
    #define MAX 0x06FFFFFF
    #define V vector<int>
    
    using namespace std;
    
    int o[LEN];
    int w[LEN];
    int Rank[LEN];
    
    int main(){
    //    freopen("1056.txt","r",stdin);
        int p,g,n;
        int i,j;
        I("%d%d",&p,&g);
        FF(i,p) I("%d",&w[i]);
        FF(i,p) I("%d",&o[i]);
        vector<int> pre(o,o+p);
        vector<int> cur;
        while(1){
            cur.clear();
            int sz=pre.size();
            int ng=sz/g;
            if(sz%g) ng++;
            FF(i,pre.size()) Rank[pre[i]]=ng+1;
            FF(i,ng){
                int maxv=-1,x;
                for(j=i*g;j<min( (i+1)*g, sz );j++){
                    if(w[pre[j]]>maxv){
                        maxv=w[pre[j]];
                        x=pre[j];
                    }
                }
                cur.push_back(x);
            }
            pre=cur;
            if(cur.size()==1){
                Rank[cur[0]]=1;
                break;
            }
        }
        FF(i,p){
            O("%d",Rank[i]);
            if(i!=p-1) O(" ");
        }
        return 0;
    }
  • 相关阅读:
    laravel migrate 指定执行部分 migration
    Laravel attribute casting 导致的 Indirect modification of overloaded property
    python中列表,元组的乘法
    python中简化的验证码功能
    Day4作业:蛋疼CRM系统
    python中pop(),popitem()的整理
    新手pyhoner的指定内容读取和写入的思路
    Python基础之文件操作
    Python基础之内置函数(一)
    Python基础之set集合与函数
  • 原文地址:https://www.cnblogs.com/TQCAI/p/8540278.html
Copyright © 2011-2022 走看看