0%

[題解]爺爺種樹

a105. 爺爺種樹

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <bits/stdc++.h>
#define N 505
#define mod 1000000007
#define FOR(i,n) for(int i=0;i<n;i++)
#define ios ios::sync_with_stdio(0)
using namespace std;


signed main(){
ios;
int n,m,t;cin>>n>>m>>t;
bool arr[N][N];
memset(arr,0,sizeof(arr));

while(t--){
int r1,r2,c1,c2;cin>>r1>>c1>>r2>>c2;
int dr = r2-r1,dc = c2-c1;
if(dr>0)dr = 1;else dr = -1;
if(dc>0)dc = 1;else dc = -1;

if(r1==r2){
for(int i=c1;i!=c2;i+=dc)arr[r1][i] = 1;
arr[r1][c2] = 1;
}
else if(c1==c2){
for(int i=r1;i!=r2;i+=dr)arr[i][c1] = 1;
arr[r2][c1] = 1;
}
else{
for(int i=r1,j=c1;i!=r2;i+=dr,j+=dc){
arr[i][j] = 1;
arr[r2][c2] = 1;
}
}
}
int ans = 0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(arr[i][j])ans+=1;
}
}
cout<<ans<<endl;
}