#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
long long int m,n,k,r[100000],c[100000],x[100000],y[100000],picked[100000],bombs[1000][1000];
int main(){
// freopen("C:\\Users\\Almond\\Desktop\\ctest.txt","w",stdout);
// ios::sync_with_stdio(0);
// cin.tie(0);
cin>>n>>m>>k;
int temp=k;
long long int ans=0;
for (int i=1;i<=k;i++){
cin>>r[i]>>c[i]>>x[i]>>y[i];
}
while (temp>=1){
for (int i=1;i<=k;i++){
if (picked[i]==0 and bombs[r[i]][c[i]]==0){
bombs[r[i]][c[i]]=1;
ans++;
}
}
for (int i=1;i<=k;i++){
if (picked[i]==0){
r[i]+=x[i];
c[i]+=y[i];
if (r[i]<0 or r[i]>=n or c[i]<0 or c[i]>=m){
temp--;
picked[i]=1;
}
}
}
for (int i=1;i<=k;i++){
if (bombs[r[i]][c[i]]==1){
int explode=0;
for (int j=1;j<=k;j++){
if (picked[j]==0 and r[i]==r[j] and c[i]==c[j]){
temp--;
picked[j]=1;
explode=1;
}
}
if (explode==1) bombs[r[i]][c[i]]=0,ans--;
}
}
}
cout<<ans<<"\n";
return 0;
}
#include
#include
#include
#include
#include
#include
#include
#include
#include <bits/stdc++.h>
using namespace std;
long long int m,n,k,r[100000],c[100000],x[100000],y[100000],picked[100000],bombs[1000][1000];
int main(){
// freopen("C:\\Users\\Almond\\Desktop\\ctest.txt","w",stdout);
// ios::sync_with_stdio(0);
// cin.tie(0);
cin>>n>>m>>k;
int temp=k;
long long int ans=0;
for (int i=1;i<=k;i++){
cin>>r[i]>>c[i]>>x[i]>>y[i];
}
while (temp>=1){
for (int i=1;i<=k;i++){
if (picked[i]==0 and bombs[r[i]][c[i]]==0){
bombs[r[i]][c[i]]=1;
ans++;
}
}
for (int i=1;i<=k;i++){
if (picked[i]==0){
r[i]+=x[i];
c[i]+=y[i];
if (r[i]=n or c[i]=m){
temp--;
picked[i]=1;
}
}
}
for (int i=1;i<=k;i++){
if (bombs[r[i]][c[i]]==1){
int explode=0;
for (int j=1;j<=k;j++){
if (picked[j]==0 and r[i]==r[j] and c[i]==c[j]){
temp--;
picked[j]=1;
explode=1;
}
}
if (explode==1) bombs[r[i]][c[i]]=0,ans--;
}
}
}
cout<<ans<<"\n";
return 0;
}
這一行有問題:
if (bombs[r[i]][c[i]]==1){
你沒有檢查魔王是否已經消失
(感覺debug時vector還蠻好用的,我看了很久一直沒找到問題,用了vector來debug才找到...)