NC229258. It Rains Again
描述
输入描述
The first line contains one positive integer .
Each of the next n lines contains four positive integers , representing a rainscreen which starts from the and ends at .
输出描述
The only one integer - the number of units of the x-axis which will not get rained on.
示例1
输入:
5 1 2 2 1 1 1 2 2 3 3 4 3 5 1 6 3 6 3 7 2
输出:
4
C 解法, 执行用时: 552ms, 内存消耗: 708K, 提交时间: 2022-03-22 16:17:51
#include <stdio.h> int main(){ int i,n,u,t,x,m[100000]; scanf("%d",&n); for(i=0;i<=100000;i++) m[i]=0; for(;n>0;n--){ scanf("%d%d%d%d",&i,&u,&t,&x); for(u=i-1;u<t-1;u++) m[u]=1; } x=0; for(i=0;i<100000;i++) x+=m[i]; printf("%d",x); return 0; }
C++ 解法, 执行用时: 1614ms, 内存消耗: 792K, 提交时间: 2021-10-26 10:43:19
#include<stdio.h> int a[100005]; int main() { int t,x1,y1,x2,y2; scanf("%d",&t); int cnt=0; while(t--) { scanf("%d%d%d%d",&x1,&y1,&x2,&y2); for(int i=x1;i<x2;++i) { if(a[i]==0) { a[i]=1; ++cnt; } } } printf("%d",cnt); }
Python3 解法, 执行用时: 575ms, 内存消耗: 5364K, 提交时间: 2022-10-17 19:54:20
a=int(input()) l=[0]*100005 for i in range(a): a,b,c,d=map(int,input().split()) l[a+1]+=1 l[c+1]-=1 ans=0 k=0 for i in range(len(l)): k+=l[i] if k>0: ans+=1 print(ans)