| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 994 人关注过本帖
标题:想问一下这道题错在哪儿?
取消只看楼主 加入收藏
青蝶
Rank: 2
等 级:论坛游民
帖 子:160
专家分:51
注 册:2018-2-4
结帖率:92%
收藏
已结贴  问题点数:20 回复次数:0 
想问一下这道题错在哪儿?
题目链接:https://www.

我的代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<vector>
#include<set>
#include<queue>
using namespace std;

int n;

struct node{
    int l;
    int w;
    friend bool operator < (node a,node b){
        if(a.l!=b.l) return a.l<b.l;
        return a.w<b.w;
    }
}t1,t2;

priority_queue<node> q1,q2;

int main(void){
    int i,k=0,w0;
    while(!q1.empty()) q1.pop();
    while(!q2.empty()) q2.pop();
    scanf("%d",&n);
    for(i=1;i<=n;i++){
      scanf("%d %d",&t1.l,&t1.w);
      q1.push(t1);
    }
    while(!q1.empty() || !q2.empty()){
        k++;
        if(k&1){
            t1=q1.top();
            q1.pop();
            w0=t1.w;
            while(!q1.empty()){
                t2=q1.top();
                q1.pop();
                if(t2.w>w0) q2.push(t2);
            }
        }
        else{
            t1=q2.top();
            q2.pop();
            w0=t1.w;
            while(!q2.empty()){
                t2=q2.top();
                q2.pop();
                if(t2.w>w0) q1.push(t2);
            }
        }
    }
    printf("%d\n",k);
    return 0;
}

错了好几个测试点,不知道错在哪里,求大佬帮忙看一下。


搜索更多相关主题的帖子: include int node while top 
2018-09-08 17:59
快速回复:想问一下这道题错在哪儿?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015218 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved