NC24845. [USACO 2009 Oct G]The Robot Plow
描述
Consider a field that is 6 squares wide and 4 squares high. As FJ issues a pair of plowing instructions (shown), the field gets plowed as shown by '*' and '#' (normally plowed field all looks the same, but '#' shows which were most recently plowed): ...... **.... #####. ...... (1,1)(2,4) **.... (1,3)(5,4) #####. ...... **.... **.... ...... **.... **.... A total of 14 squares are plowed.POINTS: 25
输入描述
* Line 1: Three space-separated integers: X, Y, and I
* Lines 2..I+1: Line i+1 contains plowing instruction i which is described by four integers: Xll, Yll, Xur, and Yur
输出描述
* Line 1: A single integer that is the total number of squares plowed
示例1
输入:
6 4 2 1 1 2 4 1 3 5 4
输出:
14
说明:
As in the task's example.C++14(g++5.4) 解法, 执行用时: 4ms, 内存消耗: 728K, 提交时间: 2019-08-30 15:55:41
#include<bits/stdc++.h> using namespace std; int e[300][300]; int main() { int x,y,n; scanf("%d%d%d",&x,&y,&n); while(n--){ int t1,t2; int t3,t4; scanf("%d%d%d%d",&t1,&t2,&t3,&t4); for(int i=t1;i<=t3;i++){ for(int j=t2;j<=t4;j++) e[i][j]++; } } int ans=0; for(int i=1;i<=x;i++){ for(int j=1;j<=y;j++) if(e[i][j]) ans++; } printf("%d",ans); }
C++11(clang++ 3.9) 解法, 执行用时: 5ms, 内存消耗: 496K, 提交时间: 2020-02-26 18:16:10
#include<bits/stdc++.h> using namespace std; bool b[241][241]; int main() { int n,m,l,x1,x2,y1,y2,ans=0; cin>>n>>m>>l; while(l--) { cin>>x1>>y1>>x2>>y2; for(int i=x1;i<=x2;i++) for(int j=y1;j<=y2;j++) { if(!b[i][j]) ans++; b[i][j]=1; } } cout<<ans; return 0; }
Pascal(fpc 3.0.2) 解法, 执行用时: 5ms, 内存消耗: 376K, 提交时间: 2019-08-31 08:01:52
var a:array[0..241,0..241] of longint; n,m,k,i,j,s,x1,x2,y1,y2,z:longint; begin read(n,m,k); for s:=1 to k do begin read(x1,y1,x2,y2); for i:=x1 to x2 do for j:=y1 to y2 do if a[i,j]=0 then begin inc(z); a[i,j]:=1; end; end; writeln(z); end.