327 条题解
-
0xtx123 LV 8 @ 2014-12-16 18:29:11
#include<iostream>
using namespace std;
struct data{
bool tree;
bool used;
};
data a[10000];
int main()
{
int m,b[101],c[101],tot=0,LL;
cin>>LL;
for(int i=0;i<=LL;++i)
{
a[i].used=0;
a[i].tree=0;
}
cin>>m;
for(int i=1;i<=m;++i)
{
cin>>b[i];
cin>>c[i];
}
for(int i=1;i<=m;++i)
{
for(int j=b[i];j<=c[i];++j)
if(!a[j].used)
{
a[j].tree=1;
a[j].used=1;
}
}
for(int i=0;i<=LL;++i)
if(!a[i].tree)
tot=tot+1;
cout<<tot;
return 0;
} -
02014-12-12 20:18:08@
program ex;
var data:array[0..10000] of boolean;
i,a,b,n,sum,k:longint;
begin
fillchar(data,sizeof(data),false);
read(sum); read(n);
inc(sum);
for i:=1 to n do
begin
read(a); read(b);
for k:=a to b do
begin
if data[k]=false then
begin
data[k]:=true;
sum:=sum-1;
end;
end;
end;
write(sum);
end.裸搜,枚举即可,实在想装B的可以用线段树什么的= =
-
02014-11-03 13:13:21@
program tree;
var i,k,m,l:integer;
a:array[0..10000] of boolean;
procedure tree;
var a1,a2,j:integer;
begin
readln(a1,a2);
for j:=a1 to a2 do a[j]:=false;
end;begin
readln(l,m);
for i:=0 to l do a[i]:=true;
for i:=1 to m do tree;
k:=0;
for i:=0 to l do
begin
if a[i] then k:=k+1;
end;
writeln(k);
end. -
02014-10-26 16:20:26@
type info=record
x,id:longint;
end;var
bool,b:array[0..1000000] of boolean;
x,y:array[0..1000000] of longint;
l,m,m1,m2,sum,i,j,k,tot,ti:longint;
a:array[0..100000] of info;procedure qsort(l,r:longint);
var
i,j,k:longint;
temp:info;
begin
i:=l;
j:=r;
k:=(i+j) div 2;
temp:=a[k];
a[k]:=a[l];
while i<j do
begin
while (i<j)and(a[j].x>temp.x) do
dec(j);
if i<j then
begin
a[i]:=a[j];
inc(i);
end;
while (i<j)and(a[i].x<temp.x) do
inc(i);
if i<j then
begin
a[j]:=a[i];
dec(j);
end;
end;a[i]:=temp;
if l<i-1 then
qsort(l,i-1);
if r>i+1 then
qsort(i+1,r);
end;begin
readln(l,m);
for i:=1 to m do
begin
readln(x[i],y[i]);
inc(tot);
a[tot].x:=x[i];
a[tot].id:=tot;
inc(tot);
a[tot].x:=y[i];
a[tot].id:=tot;
end;
qsort(1,tot);for i:=1 to tot do
begin
if not bool[i] then
begin
for j:=i+1 to tot do
if a[i].id+1=a[j].id then
break;
for k:=i to j-1 do
b[k]:=true;
bool[i]:=true;
bool[j]:=true;
end;
end;for i:=1 to tot-1 do
if b[i] then
begin
sum:=sum+a[i+1].x-a[i].x+1;
if b[i-1] then
dec(sum);
end;writeln(l-sum+1);
end.
淳朴离散化
-
02014-10-26 11:31:35@
program tree;
var a:array[0..10000] of 0..1;
L,M,i,j,k,p,n1,n2:integer;
begin
assign(input,'tree.in');
assign(output,'tree.out');
reset(input);
rewrite(output);
read(L,M);
for i:=0 to 10000 do a[i]:=1;
for i:=1 to M do begin {边读入区间边处理}
read(n1,n2);
for j:=n1 to n2 do a[j]:=0; {在此区间的坐标点使树的数量置0}
end;
k:=0;
for i:=0 to L do k:=k+a[i]; {统计,注意从0开始,到L结束,而不是到10000!!}
writeln(k);
close(input);close(output);end. -
02014-10-03 16:46:49@
#include <cstdio>
bool tree[10050];
size_t start, end;
unsigned int ans(0);int main()
{
unsigned int L, M;scanf("%u%u", &L, &M);
for (unsigned int flag = 0;flag != M;++flag)
{
scanf("%u%u", &start, &end);
for (;start <= end;++start)
tree[start] = true;
}for (size_t index = 0;index <= L;++index)
if (!tree[index])
++ans;printf("%u", ans);
return 0;
} -
02014-09-11 22:20:46@
#include <cstdio>
#include<iostream>
using namespace std;
int x[10001];
int n,m;
int i,a,b,ans=0;
int main()
{
cin>>n>>m;
for(i=0;i<=n;i++)
x[i]=1;
for(i=0;i<m;i++){
cin>>a>>b;
while(a<=b){
x[a]=0;
a++;
}
}
for(i=0;i<=n;i++)
if(x[i]==1)
ans++;
cout<<ans;
return 0;
} -
02014-09-09 13:59:38@
#include "stdio.h"
int a[10001];
int L,M;
int main()
{
scanf("%d %d",&L,&M);
int i,left,right,sum=0;
for(i=0;i<=L;i++)
{
a[i]=1;
}
for(i=0;i<M;i++)
{
scanf("%d %d",&left,&right);
while(left<=right)
{
a[left]=0;
left=left+1;
}
}
for(i=0;i<=L;i++)
{
if(a[i]==1)
sum=sum+1;
}
printf("%d",sum);
return 0;
} -
02014-08-16 19:52:02@
var f:array [0..10010] of boolean;
l,m,i,j,a,b,ans:longint;
begin
readln(l,m);
for i:=1 to m do
begin
readln(a,b);
for j:=a to b do
f[j]:=true;
end;
for i:=0 to l do if not f[i] then inc(ans);
writeln(ans);
end.
你们写这么多干嘛。。看数据范围就知道这是个水题 -
02014-08-15 20:49:15@
###BLOCK
type
treepoint=record
l:longint;r:longint;left:longint;right:longint;fa:longint;cover:longint;
end;
var
i,j,k,m,n:longint;
x,y,z,len:longint;
tree:array[1..1000000] of treepoint;
procedure build(root,ll,rr:longint);
begin
tree[root].l:=ll;
tree[root].r:=rr;
tree[root].cover:=0;
if ll<>rr then
begin
inc(len);
tree[len].fa:=root;
tree[root].left:=len;
build(len,ll,(ll+rr) div 2);
inc(len);
tree[len].fa:=root;
tree[root].right:=len;
build(len,(ll+rr)div 2+1,rr);
end;
end;
procedure labe(root,ll,rr,x:longint);
begin
if (tree[root].l=ll) and (tree[root].r=rr) then inc(tree[root].cover,x)
else
begin
if ll>(tree[root].l+tree[root].r) div 2 then begin
labe(tree[root].right,ll,rr,x);exit;end;
if rr<=(tree[root].l+tree[root].r) div 2 then begin
labe(tree[root].left,ll,rr,x);exit;end;
labe(tree[root].left,ll,(tree[root].l+tree[root].r) div 2,x);
labe(tree[root].right,(tree[root].l+tree[root].r) div 2+1,rr,x);
end;
end;
function count_h(root:longint):longint;
begin
if tree[root].cover>0 then exit(tree[root].r-tree[root].l+1)
else
begin
if tree[root].l=tree[root].r then exit(0);
exit(count_h(tree[root].left)+count_h(tree[root].right));
end;
end;
function count(root,ll,rr:longint):longint;
begin
if (tree[root].l=ll) and (tree[root].r=rr) then
exit(count_h(root))
else
begin
if ll>(tree[root].l+tree[root].r) div 2 then exit(count(tree[root].right,ll,rr));
if rr<=(tree[root].l+tree[root].r) div 2 then exit(count(tree[root].left,ll,rr));exit(count(tree[root].left,ll,(tree[root].l+tree[root].r)div 2)+count(tree[root].right,(tree[root].l+tree[root].r) div 2+1,rr));
end;
end;
begin
readln(n,m);
fillchar(tree,sizeof(tree),0);
len:=1;
build(1,0,n);for i:=1 to m do
begin
readln(x,y);
labe(1,x,y,1);
end;
k:=count(1,0,n);
writeln(n+1-k);
end. -
02014-08-01 14:44:04@
秒过 O(∩_∩)O哈哈~
program fdh;
const
z=10000;
var
a:array[0..z] of longint;
m,l,x,y:longint;
i,j:longint;
begin
read(l,m);
for i:=0 to l do
a[i]:=1;
for i:=1 to m do
begin
read(x,y);
for j:=x to y do
a[j]:=0;
end;
m:=0;
for i:=0 to l do
m:=m+a[i];
writeln(m);
end. -
02014-05-07 19:41:33@
看成线段树。。。吓死瞄了
-
02014-01-01 11:59:54@
Vijos 题解:http://hi.baidu.com/umule/item/2c997f8ed9600fdae596e017
有疑问请留言 共同进步 -
02013-11-30 11:40:21@
编译成功
测试数据 #0: Accepted, time = 0 ms, mem = 444 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 440 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 444 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 444 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 444 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 448 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 448 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 448 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 448 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 444 KiB, score = 10
Accepted, time = 0 ms, mem = 448 KiB, score = 100#include<cstdio>
#include<cstdlib>
#include<algorithm>
#define max(a,b) a>b?a:b
using namespace std;
typedef struct node{
int a;
int b;
}node;
node road[101];
int top=0;
int cmp(node a,node b){
return a.a<b.a;
}
int main(){
int l,m,ans=0;
scanf("%d %d",&l,&m);
scanf("%d %d",&road[1].a,&road[1].b);
for(int i=2;i<=m;i++) scanf("%d %d",&road[i].a,&road[i].b);
sort(road+1,road+m+1,cmp);
for(int i=1;i<m;i++){
if(road[i+1].a<=road[i].b){
road[i+1].a=road[i].a;
road[i+1].b=max(road[i+1].b,road[i].b);
road[i].a=-1;
road[i].b=-1;
}
}
for(int i=1;i<=m;i++){
if(road[i].a+road[i].b<0) continue;
else ans+=road[i].b-road[i].a+1;
}
printf("%d",l+1-ans);
return 0;
} -
02013-11-07 21:25:36@
编译成功
测试数据 #0: WrongAnswer, time = 0 ms, mem = 600 KiB, score = 0
测试数据 #1: Accepted, time = 0 ms, mem = 600 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 600 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 604 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 604 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 600 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 608 KiB, score = 10
测试数据 #7: Accepted, time = 15 ms, mem = 600 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 600 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 604 KiB, score = 10
WrongAnswer, time = 15 ms, mem = 608 KiB, score = 90#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
const int N=10005;
int a[N];
int main(){
int m,l,i,head,tail,ans=0;
cin>>l>>m;
for(i=1;i<=l;i++)a[i]=1;
for(i=1;i<=m;i++)
{cin>>head>>tail;
for(;head<=tail;head++)
{a[head]=0;}
}
for(i=1;i<=l;i++)
{if(a[i]==1)ans++;}
cout<<ans+1;
return 0;
}
第一个测试数据??请教!! -
02013-11-06 13:12:27@
PROGRAM VP1103; //https://vijos.org/p/1103
VAR
l{马路长度,m{区域数目},i,j{计数器},x{存储区段起始},y{存储区段终止},s{存储总数}:longint;
t:array[0..10000] of boolean; //树木状态
BEGIN
read(l{:马路的长度},m{:区域的数目}); //读数目
fillchar(t,l+1{包括树木[0]},true); //数组初始化
FOR i:=1 TO m DO BEGIN //读入区域,并改变区域树木状态
read(x{起始},y{终止}); //读起始终止
for j:=x to y do t[j]:=false; //依次标记区域内移除的树木
END;{FOR}
for i:=0 to l do
if t[i]=true {判断是否存在} then inc(s); //计算总数
writeln(s); //输出
end. -
02013-10-31 16:22:27@
这个题目挺简单,楼下的算法思想和我的一致啊。
评测结果
编译成功foo.pas(15,17) Warning: Variable "sum" does not seem to be initialized
测试数据 #0: Accepted, time = 0 ms, mem = 832 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 832 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 828 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 832 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 832 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 832 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 828 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 828 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 828 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 832 KiB, score = 10
Accepted, time = 0 ms, mem = 832 KiB, score = 100program tree;
var l,m,i,j,x,y,sum:longint;
trees:array[0..10000] of boolean;
begin
read(l,m);
fillchar(trees,l+1,true);
for i:=1 to m do
begin
read(x,y);
for j:=x to y do
trees[j]:=false;
end;
for i:=0 to l do
if trees[i]=true then
inc(sum);
writeln(sum);
end. -
02013-10-15 19:36:09@
一个水题让咱WA5次,CE2次,玩脱了囧。不该不去测试的= =
编译成功
foo.pas(13,25) Warning: Variable "ans" does not seem to be initialized
测试数据 #0: Accepted, time = 0 ms, mem = 828 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 832 KiB, score = 10
测试数据 #2: Accepted, time = 15 ms, mem = 828 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 828 KiB, score = 10
测试数据 #4: Accepted, time = 15 ms, mem = 828 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 828 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 828 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 832 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 832 KiB, score = 10
测试数据 #9: Accepted, time = 15 ms, mem = 832 KiB, score = 10
Accepted, time = 45 ms, mem = 832 KiB, score = 100
var
l,m,i,j,a,b,ans:integer;
t:array[0..10000]of boolean;
begin
read(l,m);
fillchar(t,sizeof(t),true);
for i:=1 to m do begin
read(a,b);
for j:=a to b do
t[j]:=false;
end;
for i:=0 to l do
if t[i] then inc(ans);
writeln(ans);
end. -
02013-10-07 13:39:40@
纯模拟 注意起点从0开始!!!
var i,j,k,l,n,m,x,y,ans:longint;
a:array[0..10000] of longint;
begin
readln(l,n);
for i:=1 to n do begin
read(x,y);
if x>y then begin
k:=x;
x:=y;
y:=k;
end;
for j:=x to y do a[j]:=1;
end;
for i:=0 to l do if a[i]=0 then inc(ans);
writeln(ans);
end. -
02013-10-04 21:22:01@
编译成功
测试数据 #0: WrongAnswer, time = 0 ms, mem = 504 KiB, score = 0
测试数据 #1: WrongAnswer, time = 0 ms, mem = 508 KiB, score = 0
测试数据 #2: WrongAnswer, time = 15 ms, mem = 508 KiB, score = 0
测试数据 #3: Accepted, time = 0 ms, mem = 500 KiB, score = 10
测试数据 #4: Accepted, time = 19 ms, mem = 508 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 508 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 504 KiB, score = 10
测试数据 #7: WrongAnswer, time = 0 ms, mem = 512 KiB, score = 0
测试数据 #8: WrongAnswer, time = 0 ms, mem = 508 KiB, score = 0
测试数据 #9: Accepted, time = 0 ms, mem = 508 KiB, score = 10
WrongAnswer, time = 34 ms, mem = 512 KiB, score = 50
代码
#include<iostream>
using namespace std;
int main(){
int malu[10000],l,m,ans=0,i,a,b;
cin>>l>>m;
for(i=0;i<m;i++)
{cin>>a>>b;
if(a>b){a+=b;b=a-b;a=a-b;}
for(;a<=b;a++)malu[a+1]=1;}
for(i=0;i<l;i++)
if(malu[i]==1) ans++;
cout<<l-ans+1;
return 0;
}why?