hdu 1972

来源:互联网 发布:邓肯巅峰数据 编辑:程序博客网 时间:2024/05/16 17:15

这题太水了,一个暴力模拟就A了。


排队时,若是权值递增,那么最坏的情况是n!。可拍,可是n最大100。





/**TASK: crypt1LANG: C++ID: DickensTone**/#include<cstdio>#include<cstring>#include<fstream>#include<iostream>#include<queue>#include<algorithm>using namespace std;const int maxn = 100 + 5;struct node{    int id;    int val;    node(int x, int y):id(x), val(y){}};bool cmp(int x, int y){    return x > y;}int num[maxn];int main(){    //freopen("crypt1.in", "r", stdin);    //freopen("crypt1.out", "w", stdout);    int m, n, T;    queue<node> q;    scanf("%d", &T);    while(T--)    {        memset(num, 0, sizeof(num));        while(!q.empty()) q.pop();        int m, n;        scanf("%d%d", &m, &n);        for(int i = 0; i < m; i++)        {            int t;            scanf("%d", &t);            num[i] = t;            q.push(node(i, t));        }        sort(num, num + m, cmp);        int ans = 0, cnt = 0;        while(!q.empty())        {            node temp = q.front();            q.pop();            if(num[cnt] != temp.val) q.push(temp);            else {                cnt++;                ans++;                if(temp.id == n) break;            }        }        printf("%d\n", ans);    }    return 0;}


原创粉丝点击