C. Weather:题目
为什么直接交代码不行啊,非要加两句话,有没有大佬说说?
#include <bits/stdc++.h>
using namespace std;
// typedef long long ll;
vector<int> a((int)3e5);
vector<int> b((int)3e5), c((int)3e5);
int main()
{freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);int n;cin >> n;if (n==2) {int cou = 0,x;cin>>x;if (x>=0) cou++;cin>>x;if (x<=0) cou++;cout<<cou<<endl;return 0;}b[0] = c[n + 1] = 0;for (int i = 1; i <= n; i++){cin >> a[i];}for (int i = 1; i <= n; i++){b[i] = b[i - 1];if (a[i] >= 0)b[i]++;}for (int i = n; i >= 1; i--){c[i] = c[i + 1];if (a[i] <= 0)c[i]++;}int res = (int)2e5;for (int i = 2; i <= n-1; i++){if (a[i] != 0)res = min(res, b[i - 1] + c[i + 1]);elseres = min(res, b[i - 1] + c[i + 1] + 1);}cout << res << endl;
}
2022年2月27日,1:38,还有一题1300结束