题目链接 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天前
417