前十題都AC,十題之後就開始錯了,請問我有什麼細節沒注意到嗎?
#include <iostream>
using namespace std;
int main()
{
int n, m, k;
cin>>n>>m>>k;
int bomb[m][n];
for( int i=0 ; i<m ; i++ )
{
for( int j=0 ; j<n ; j++ )
{
bomb[i][j] = 0;
}
}
int king[k][5];
for( int i=0 ; i<k ; i++ )
{
king[i][4] = 0;
for( int j=0 ; j<4 ; j++ )
{
cin>>king[i][j];
}
}
int dead = 0;
while( dead < k )
{
for( int i=0 ; i<k ; i++ )//left bomb
{
if( king[i][4] == 0 )
{
bomb[ king[i][0] ][ king[i][1] ] = 1;
}
}
for( int i=0 ; i<k ; i++ )//survive move
{
if( king[i][4] == 0 )
{
king[i][0] += king[i][2];
king[i][1] += king[i][3];
}
}
for( int i=0 ; i<k ; i++ )//dead
{
if( king[i][4] == 0 )
{
if(king[i][0] >= n || king[i][1] >= m || king[i][0] < 0 || king[i][1] < 0 )
{
king[i][4] = 1;
dead++;
}
}
if( king[i][4] == 0 )
{
if( bomb[ king[i][0] ][ king[i][1] ] >= 1 )
{
bomb[ king[i][0] ][ king[i][1] ] = 2;
king[i][4] = 1;
dead++;
}
}
}
/*for( int i=0 ; i<k ; i++ )
{
for( int j=0 ; j<k ; j++ )
{
if( i != j )
{
if( king[i][4] == 0 && king[j][4] == 0 )
{
if( king[i][0] == king[j][0] && king[i][1] == king[j][1] )
{
king[i][4] = 1;
king[j][4] = 1;
dead++;
dead++;
}
}
}
}
}*/
for( int i=0 ; i<m ; i++ )
{
for( int j=0 ; j<n ; j++ )
{
if( bomb[i][j] == 2)
{
bomb[i][j] = 0;
}
}
}
}
int answer = 0;
for( int i=0 ; i<m ; i++ )
{
for( int j=0 ; j<n ; j++ )
{
if( bomb[i][j] == 1 )
{
answer++;
}
}
}
cout<<answer;
return 0;
}
前十題都AC,十題之後就開始錯了,請問我有什麼細節沒注意到嗎?
#include
using namespace std;
int main()
{
int n, m, k;
cin>>n>>m>>k;int bomb[m][n];
for( int i=0 ; i {
for( int j=0 ; j {
bomb[i][j] = 0;
}
}int king[k][5];
for( int i=0 ; i {
king[i][4] = 0;for( int j=0 ; j<4 ; j++ )
{
cin>>king[i][j];
}
}int dead = 0;
while( dead < k )
{
for( int i=0 ; i {
if( king[i][4] == 0 )
{
bomb[ king[i][0] ][ king[i][1] ] = 1;
}
}for( int i=0 ; i {
if( king[i][4] == 0 )
{
king[i][0] += king[i][2];
king[i][1] += king[i][3];
}
}for( int i=0 ; i {
if( king[i][4] == 0 )
{
if(king[i][0] >= n || king[i][1] >= m || king[i][0] < 0 || king[i][1] < 0 )
{
king[i][4] = 1;
dead++;}
}
if( king[i][4] == 0 )
{
if( bomb[ king[i][0] ][ king[i][1] ] >= 1 )
{
bomb[ king[i][0] ][ king[i][1] ] = 2;
king[i][4] = 1;
dead++;
}
}
}/*for( int i=0 ; i {
for( int j=0 ; j {
if( i != j )
{
if( king[i][4] == 0 && king[j][4] == 0 )
{
if( king[i][0] == king[j][0] && king[i][1] == king[j][1] )
{
king[i][4] = 1;
king[j][4] = 1;
dead++;
dead++;
}
}
}
}
}*/for( int i=0 ; i {
for( int j=0 ; j {
if( bomb[i][j] == 2)
{
bomb[i][j] = 0;
}
}
}}
int answer = 0;
for( int i=0 ; i {
for( int j=0 ; j {
if( bomb[i][j] == 1 )
{
answer++;
}
}
}cout<
return 0;
}
n和m顛倒了