AcWing
  • 首页
  • 活动
  • 题库
  • 竞赛
  • 应用
  • 更多
    • 题解
    • 分享
    • 商店
    • 问答
    • 吐槽
  • App
  • 登录/注册

这编译器是不是不行啊



0


题目链接 https://www.acwing.com/problem/content/105/

我实在是受不了了,代码写的逻辑一点问题都没有,换了两种方法了,就是输入数据读的有问题

错误的代码:

#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef long long int ll;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef vector<bool> vb;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef vector<vi> vvi;



#define lowbit(S) ((S)& -(S))
#define pb push_back
#define sz(x) ((int)(x.size()))
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define bitcount __builtin_popcount


int cnt;
map<int, int> mapp;
const int N = 2e5 + 10;
int discrete(int x){
    if (!mapp.count(x)) mapp[x] = cnt++;
    return mapp[x];
}

 //int a[200341] = {0};
int main(){
    //ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, m;
    cin >> n;
    vi a(N, 0);
    mapp.clear();
    cnt = 0;
    for (int i = 0, t; i < n; ++i){
        cin >> t;t = discrete(t);
        a[t] += 1;
    }
    cin >> m;
    int happy = 0, ok = 0, ans = 1;
    set<int> sett;
    vvi b(N, vi(2, 0));
    for (int i = 0; i < m; ++i) cin >> b[i][0];
    for (int i = 0; i < m; ++i) cin >> b[i][1];
    for (int i = 0; i < m; ++i){
        //if (i > 1000) cout << b[i][0] << " \n"; 重点是这一句,数据有2000个,但是读到省略号以后的数据全是0
        int t = discrete(b[i][0]);
        if (a[t] > happy){
            happy = a[t];
            ans = i + 1;
            ok = a[discrete(b[i][1])];
        }
        else if (happy == a[t] && ok < a[discrete(b[i][1])]){
            ok = a[discrete(b[i][1])];
            ans = i + 1;
        }
    }

    cout << ans << endl;
    return 0;
}



//下面这种写法是第2000个数据第一千多就读到了,根本没法跑代码

#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef long long int ll;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef vector<bool> vb;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef vector<vi> vvi;



#define lowbit(S) ((S)& -(S))
#define pb push_back
#define sz(x) ((int)(x.size()))
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define bitcount __builtin_popcount


int cnt;
map<int, int> mapp;
int discrete(int x){
    if (!mapp.count(x)) mapp[x] = cnt++;
    return mapp[x];
}

 //int a[200341] = {0};
int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, m;
    cin >> n;
    vi a(2e5, 0);
    mapp.clear();
    cnt = 0;
    for (int i = 0, t; i < n; ++i){
        cin >> t;t = discrete(t);
        a[t] += 1;
    }
    cin >> m;
    int happy = 0, ok = 0, ans = 1;
    set<int> sett;
    for (int i = 1; i <= m; ++i){
        int t;  cin >> t; t = discrete(t);
        if (a[t] > happy){
            happy = a[t];
            sett.clear();
            sett.insert(i);
            ans = i;
        }
        else if (a[t] == happy){
            sett.insert(i);
        }
    }
    for (int i = 1; i <= m; ++i) {
        int t; cin >> t; t = discrete(t);
        if (sett.count(i) && ok < a[t]){
            ok = a[t];
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}



要么数据读出来全是0,要么数据读出来顺序不对,第2000个数据第1300多就读到了

什么情况啊,vector,数组都试过了,输入一直采用的cin>>输入,始终解决不了的问题

CF已AC,我是真服了..debug两个小时原来是网站有问题,以后再也不相信网站了



提问于13天前
__yxc_
417


2 个问答



1

个人感觉,未必是读入的不正确,而是你各种数据结构套的太多了吧……
实在不行,咱copy个快读试试

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
    int x=0,y=1;char ch=getchar();
    for(;ch>57||ch<48;y=(ch==45?-1:1),ch=getchar());
    for(;ch>47&&ch<58;x=(x<<1)+(x<<3)+(ch^48),ch=getchar());
    return x*y;
}

inline void write(int x)
{
    if(x<0) putchar(45),x=-x;
    if(x>9) write(x/10);
    putchar(48+x%10);
}

#define writesp(x) write(x),putchar(' ')
#define writeln(x) write(x),putchar('\n')

/*----------------------------------------------------------------------------------------------------------------------------------------------*/

#define N 200010

struct mv
{
    int id , x , y ;
    inline bool operator < ( const mv & t ) const 
    {
        if( t . x == x ) return t . y < y ;
        else return t . x < x ; 
    }
}M[ N ] ;

int n , m , a[ N ] ;

signed main()
{

    n = read() ;
    memset( a , 0x3f , sizeof a ) ;
    for( int i = 1 ; i <= n ; i ++ ) a[ i ] = read( ) ;
    sort( a + 1 , a + n + 1 ) ;

    m = read() ;
    for( int i = 1 ; i <= m ; i ++ )
    {
        int t = read( ) ; M[ i ] . id = i ; 
        M[ i ] . x += upper_bound( a + 1 , a  + n + 2 , t ) - lower_bound( a + 1 , a + n + 2 , t ) ; 
    }
    for( int i = 1 ; i <= m ; i ++ )
    {
        int t = read( ) ;
        M[ i ] . y += upper_bound( a + 1 , a  + n + 2 , t ) - lower_bound( a + 1 , a + n + 2 , t ) ; 
    }
    sort( M + 1 , M + m + 1 ) ;
    write( M[ 1 ] . id ) ;
    return 0 ;
}

回答于13天前
virapaksa
589

@virapaksa:  感谢回复!!(SMILE) –  __yxc_   13天前

@virapaksa:  这话我觉得不对,如果不合理的话cf肯定过不去的,如果在其他平台或者我自己电脑上都跑不了,那就是代码的问题。如果只是在这个网站上跑不了,那就是网站的问题 –  __yxc_   13天前

反正各种奇奇怪怪的评测环境都会对程序产生影响,只要你写的够合理什么都卡不住你的 –  virapaksa   13天前

@__yxc_:  哟西,快把yxc钓出来提个建议 –  virapaksa   13天前

数据结构没问题的,就写了个离散化,CF已经AC了 –  __yxc_   13天前



0

这题目是进阶指南的 题目数据在作者github上都有。 我AC了 感觉没啥问题。 
另外cf能过和这里没啥关系

回答于9天前
itdef
411723

我的代码在两个OJ 都过了 ,所以我不认为编译器有问题 ,可能是数据问题 或格式问题。 另外这个数据是进阶指南作者随书光盘和github上都有的,不是acwing额外处理修改过的,应该和网站无关。不需要反思啊。然后cf能过可能他没出可能出错的数据而已,不能说明网站有问题。 比如我的代码在我单机上都能ac,我不能说oj判断我 wa就是有问题 –  itdef   5天前

哥们,这话说出来你不觉得有问题吗? 别的网站能交过去,就在这里交不过去,不应该反思一下这里的问题吗。你觉得跟这个没啥关系的话请你说出具体的为什么没有关系,这样会更有信服力。不然张口就来很容易让人认为你的逻辑就是:something只适合中国宝宝体质。 –  __yxc_   5天前


我来回答
你确定删除吗?

© 2018-2023 AcWing 版权所有  |  京ICP备17053197号-1
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息