327 条题解
-
-12718817432 LV 5 @ 2018-09-15 21:45:42
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int tree[10010];//tree[n]为第n棵树
int main()
{
int m,x,kai,jie,sum=0;
cin>>m>>x;
for(int i=1;i<=x;i++)//每个区域使用一次
{
cin>>kai>>jie;//开始和结束的坐标
for(int t=kai;t<=jie;t++)
{
tree[t]=1;//在区域内的树给上标记,重复区域无影响
}
}
for(int i=0;i<=m;++i)
{
if(tree[i]!=1) sum++;//输出没被标记的树
}
cout<<sum;
} -
-12017-11-09 14:41:51@
简单优化一下
#include<stdio.h>
int main(){
int i,j,l,m,a1,a2,c,totallong;
static int la[10001],ra[10001],s[10001];scanf("%d%d",&l,&m);
getchar();for(i=0;i<m;i++){
scanf("%d%d",&a1,&a2);
if (a1>a2){
c=a1;
a1=a2;
a2=c;
}
if (a2>la[a1]){
la[a1]=a2;
}
if ((a1<ra[a2]) || (ra[a2]==0)){
ra[a2]=a1;
}
}for(i=0;i<=l;i++){
if (la[i]!=0){
for(j=i;j<=la[i];j++){
s[j]=1;
}
i=la[i];
}
}
for(i=l;i>=0;i--){
if(ra[i]!=0){
for(j=i;j>=ra[i];j--){
s[j]=1;
}
i=ra[i];
}
}totallong=l+1;
for(i=0;i<=l;i++){
if(s[i]) totallong--;
}
printf("%d",totallong);
} -
-12017-10-31 20:36:28@
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[10001];
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int i,j,m,n;
cin>>m>>n;
int under_1[n+1],under_2[n+1];
for (i=0;i<n;i++)
{
cin>>under_1[i]>>under_2[i];
for (j=under_1[i];j<=under_2[i];j++)
a[j]=1;
}
int c=0;
for (i=0;i<=m;i++)
{
if (a[i]==0)
c++;
}
cout<<c<<endl;
system("pause");
return 0;
} -
-12017-10-20 22:43:18@
var l,m,x,y,i,j,ans:longint; a:array[0..10000] of integer;
begin
readln(l,m);
fillchar(a,sizeof(a),1);
for i:=1 to m do
begin
readln(x,y);
for j:=x to y do a[j]:=0;
end;
for i:=0 to l do
if a[i]<>0 then inc(ans);
writeln(ans);
end. -
-12017-10-05 10:01:18@
var a:array[0..10001]of longint; l,n,i,x,y,j,c:longint; begin readln(l,n); for i:=0 to l do a[i]:=1; for i:=1 to n do begin read(x,y); for j:=x to y do a[j]:=0; end; for i:=0 to l do c:=c+a[i]; write(c); end.
-
-12016-11-01 16:32:42@
#include<iostream>
using namespace std;
int main()
{
int L, M, counter=0;
cin >> L >> M;
int arr1[150], arr2[150];
for(int i=0;i<M;i++)
{
cin >> arr1[i] >> arr2[i];
}
for(int j=1;j<=L;j++)
{
for (int i = 0; i < M; i++)
{
if (arr1[i] <= j&&arr2[i]>=j)
{
++counter; break;
}
}
}
int remain = L + 1 - counter;
cout << remain;
return 0;}
大佬们帮忙看一下哪里错了,为什么有一个数据点没过 -
-32015-08-26 16:19:34@
我就是牛逼啊,你们一群垃圾,还学编程?
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int l,m,a[10002],i,w,c,j,sum=0;
scanf("%d%d",&l,&m);
for(i=0;i<=l;i++){
a[i]=1;
}
for(i=1;i<=m;i++){
scanf("%d%d",&w,&c);
for(j=w;j<=c;j++){
if(a[j]==1){
a[j]=0;
}
else{
a[j]=0;
}
}
}
for(i=0;i<=l;i++){
sum+=a[i];
}
printf("%d",sum);
return 0;
}