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;
    }
  • 相关阅读:
    springboot springcloud zuul 过滤器
    springboot springcloud eureka 熔断器
    javaweb servlet filter
    maven nexus 搭建私服(二)
    springboot springcloud zuul 网关入门
    springboot springcloud 配置中心
    springboot springcloud eureka 入门
    java rabbitmq
    java jvm调优
    maven nexus 搭建私服(一)
  • 原文地址:https://www.cnblogs.com/TQCAI/p/8540278.html
Copyright © 2011-2022 走看看