check mistake #include<bits/stdc++.h> #include<vector> using namespace std; int…
- User
check mistake #include<bits/stdc++.h> #include using namespace std; int XX[8]={2,1,-1,-2,-2,-1,1,2}; int YY[8]={1,2,2,1,-1,-2,-2,-1}; void Dequy(vector<vector>&chess,int x,int y,int k,int n) { if(k == 0) return ; for(int i=0;i<8;i++){ int tx=x+XX[i]; int ty=y+YY[i]; if(tx>=0 && tx<n && ty>=0 && ty<n){ chess[tx][ty]=true; Dequy(chess,tx,ty,k-1,n); } } } int dem(int n,int k, int x,int y){ vector<vector>chess(n,vector(n,false)); chess[x][y]=true; Dequy(chess,x,y,k,n); int dem=0; for(int i=0;i<n;i++); for(int j=0;j<n;j++); if(chess[i][j]==true)dem++; return dem; } int main(){ int t; cin>>t; while(t--){ int n,k,x,y; cin>>n>>k>>x>>y; cout<<dem(n,k,x-1,y-1)<<endl; } }
- Assistant
Here are some mistakes in the code:
-
The line '#include<bits/stdc++.h>' should be '#include<bits/stdc++.h>' with a '>' symbol at the end.
-
The line 'vector<vector>chess(n,vector(n,false));' should be 'vector<vector>chess(n,vector(n,0));' to initialize the chessboard with zeros instead of booleans.
-
In the function 'Dequy()', the line 'if(k == 0) return ;' should be 'if(k <= 0) return ;' to handle cases where k is negative or zero.
-
In the 'dem()' function, the lines 'for(int i=0;i<n;i++);' and 'for(int j=0;j<n;j++);' should not end with a semicolon (;) as it causes the for loop to have an empty body. It should be 'for(int i=0;i<n;i++)' and 'for(int j=0;j<n;j++)'.
-
- User
Compile Error
- Assistant
Apologies for the oversight. Upon reviewing the code again, I found another mistake in the line 'vector<vector>chess(n,vector(n,0));'. The correct way to define a two-dimensional vector is 'vector<vector> chess(n, vector(n, 0));'.
Here's the corrected code:
cpp - User
Compile Error /judger/run/14178bc068304d45a7aaed4e8b128e15/main.cpp:37:13: error: stray '\342' in program 37 | while (t–) { | ^ /judger/run/14178bc068304d45a7aaed4e8b128e15/main.cpp:37:14: error: stray '\200' in program 37 | while (t–) { | ^ /judger/run/14178bc068304d45a7aaed4e8b128e15/main.cpp:37:15: error: stray '\223' in program 37 | while (t–) { | ^
- Assistant
Apologies for the mistakes. It seems that there are some issues with the characters not being recognized correctly. Here's the corrected code:
cpp#include <bits/stdc++.h> #include <vector> using namespace std; int XX[8] = {2, 1, -1, -2, -2, -1, 1, 2}; int YY[8] = {1, 2, 2, 1, -1, -2, -2, -1}; void Dequy(vector<vector<int>>& chess, int x, int y, int k, int n) { if (k <= 0) return; for (int i = 0; i < 8; i++) { int tx = x + XX[i]; int ty = y + YY[i]; if (tx >= 0 && tx < n && ty >= 0 && ty < n) { chess[tx][ty] = 1; Dequy(chess, tx, ty, k - 1, n); } } } int dem(int n, int k, int x, int y) { vector<vector<int>> chess(n, vector<int>(n, 0)); chess[x][y] = 1; Dequy(chess, x, y, k, n); int dem = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (chess[i][j] == 1) dem++; } } return dem; } int main() { int t; cin >> t; while (t--) { int n, k, x, y; cin >> n >> k >> x >> y; cout << dem(n, k, x - 1, y - 1) << endl; } return 0; } - User
Compile Error /judger/run/8b7f978e156147459669bd6504a58824/main.cpp:37:13: error: stray '\342' in program 37 | while (t–) { | ^ /judger/run/8b7f978e156147459669bd6504a58824/main.cpp:37:14: error: stray '\200' in program 37 | while (t–) { | ^ /judger/run/8b7f978e156147459669bd6504a58824/main.cpp:37:15: error: stray '\223' in program 37 | while (t–) { | ^ Giới hạn thời gian60000MS Giới hạn bộ nhớ256MB
- Assistant
Apologies for the confusion. The errors you are receiving seem to be caused by non-standard characters in the code. It's possible that the text encoding or formatting got altered during the communication.
In order to provide a solution that will work correctly, it would be best if you could provide the code in a text format that preserves all the characters correctly. Please copy and paste the code again, ensuring that the formatting and characters remain intact.