为什么会RE???

P2141 [NOIP2014 普及组] 珠心算测验

@[caox0427](/user/886310) b[i]==2 ???
by Gohidg @ 2023-07-12 11:54:51


改成b[i]=2
by Gohidg @ 2023-07-12 11:55:59


还有一点
by ILoveSoviet @ 2023-07-12 11:56:57


你的第二个循环(j那个)的判断式写的是i<n,估计就应此RE了
by ILoveSoviet @ 2023-07-12 11:58:02


``` #include<bits/stdc++.h> using namespace std; int n,cnt; int main(){ int a[10005] = {0},b[10005] = {0}; cin>>n; for(int i = 0;i<n;i++){ cin>>a[i]; b[i] ==2; } for(int i = 0;i<n;i++){ for(int j = i+1;j<n;j++){ for(int z = 0;z<n;z++){ if(a[i]+a[j] == a[z]&&b[z] == 2){ cnt++; b[z] = 1; } } } } cout<<cnt; return 0; } ```
by xu222ux @ 2023-07-12 12:00:54


不止,不是b[i]=1;是b[z]
by xu222ux @ 2023-07-12 12:02:34


帮你调好了,拿走不谢: ```cpp #include<bits/stdc++.h> using namespace std; int n,cnt; int main(){ int a[10005] = {0},b[10005] = {0}; cin>>n; // cout<<n; for(int i = 0;i<n;i++){ cin>>a[i]; b[i] = 2; } for(int i = 0;i<n;i++){ for(int j = i+1;j<n;j++){ for(int z = 0;z<n;z++){ // cout<<i<<" "<<j<<" "<<z<<endl; // system("PAUSE"); if(a[i]+a[j] == a[z]&&b[z] == 2){ cnt++; // cout<<i<<" "<<j<<endl; b[z] = 1; } } } } cout<<cnt; return 0; } ```
by ILoveSoviet @ 2023-07-12 12:03:05


@[ILoveSoviet](/user/724221) 谢谢了
by Ghost_Death @ 2023-07-16 17:56:40


##### G ```cpp #include <bits/stdc++.h> using namespace std; #define ll long long bool l[100001]; ll dfs(vector<int> arr, int n) { ll ans = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { for (int k = 0; k < n && k != j; ++k) if ((arr[i] == (arr[j] + arr[k])) && l[arr[i]] == 0) { l[arr[i]] = 1; ans++; //cout << ans << "1!!" << endl; } } //cout << i << " " << j << " " << k << endl; } return ans; } int main() { int n; vector<int> arr; cin >> n; for (int i = 0; i < n; ++i) { int temp; cin >> temp; arr.push_back(temp); } bool flag = 0; ll ans = dfs(arr, n); cout << ans << endl; return 0; } ```
by 13704085069a @ 2023-07-17 14:52:50


|