| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 992 人关注过本帖
标题:想问一下这道题错在哪儿?
只看楼主 加入收藏
青蝶
Rank: 2
等 级:论坛游民
帖 子:160
专家分:51
注 册:2018-2-4
结帖率:92%
收藏
已结贴  问题点数:20 回复次数:1 
想问一下这道题错在哪儿?
题目链接: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
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:20 
看不懂你的算法逻辑

程序代码:
#include <cstdio>
#include <algorithm>

int main( void )
{
    struct Wood
    {
        unsigned L, W;
    };
    Wood ws[5000];
    size_t ws_len;

    // 输入
    scanf( "%zu", &ws_len );
    for( size_t i=0; i!=ws_len; ++i )
        scanf( "%u%u", &ws[i].L, &ws[i].W );

    // 排序
    std::sort( ws, ws+ws_len, [](const auto& a, const auto& b){return a.L!=b.L ? a.L>b.L : a.W>b.W;} );

    // 至少分成多少个非递减序列
    unsigned groups[5000];
    size_t groups_len = 0;
    for( unsigned i=0; i!=ws_len; ++i )
    {
        unsigned* p = std::lower_bound( groups, groups+groups_len, ws[i].W );
        if( p == groups+groups_len )
            groups[groups_len++] = ws[i].W;
        else
            *p = ws[i].W;
    }
    printf( "%zu\n", groups_len );
}

2018-09-10 13:01
快速回复:想问一下这道题错在哪儿?
数据加载中...
 
   



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

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