1 条题解
-
0
C :
#include <stdio.h> #include <stdlib.h> //#include <string.h> int main(void) { int L,M; int a,b; int *p; int i; int count=0; while((scanf("%d%d",&L,&M),L)) { p=(int *)malloc(sizeof(int)*(L+1)); //memset(p,0,L+1); for(i=0;i<L+1;i++) { p[i] = 0; } while(M) { scanf("%d%d",&a,&b); for(i=a;i<=b;i++) { p[i] = 1; } M--; } count = 0; for(i=0;i<L+1;i++) { if(p[i] == 0) { count++; } } free(p); printf("%d\n",count); } return 0; }
C++ :
#include <stdio.h> int l,m; int run() { int a[11111],i,j,k,h,t=0; for(i=0;i<=l;i++) a[i]=1; for(i=1;i<=m;i++) { scanf("%d%d",&j,&k); for(h=j;h<=k;h++) a[h]=0; } for(i=0;i<=l;i++) t+=a[i]; return t; } int main() { scanf("%d%d",&l,&m); while(l!=0) { printf("%d\n",run()); l=0; scanf("%d%d",&l,&m); } return 0; }
Java :
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ int l=scanner.nextInt(); if(l==0){ continue; } int m=scanner.nextInt(); boolean[] tree=new boolean[10010]; while(m--!=0){ int begin=scanner.nextInt(); int end=scanner.nextInt(); for (int i = begin; i <= end; i++) { tree[i]=true; } } int ans =0; for (int i = 0; i <= l; i++) { if(tree[i]==false){ ++ans; } } System.out.println(ans); } } }
C# :
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 剩下的树 { class Program { static void Main(string[] args) { string s = Console.ReadLine(); string[] words = new string[100]; words=s.Split(' '); int l = int.Parse(words[0]), m = int.Parse(words[1]); while (l != 0 || m != 0) { bool[] exist = new bool[10001]; for (int i = 0; i <= l; i++) { exist[i] = true; } while (m-- != 0) { s = Console.ReadLine(); words = s.Split(' '); int a = int.Parse(words[0]), b = int.Parse(words[1]); for (int i = a; i <= b; i++) { exist[i] = false; } } int cnt=0; for (int i = 0; i <= l; i++) { if (exist[i]) cnt++; } Console.WriteLine("{0}", cnt); s = Console.ReadLine(); words = new string[100]; words = s.Split(' '); l = int.Parse(words[0]);m = int.Parse(words[1]); } } } }
- 1
信息
- ID
- 1101
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者