讨论 / 贡献一个c++标准代码。
天伤夜亦眠 2014-05-13 10:14:47
点我顶贴 收藏 删除
#include <algorithm>

#include <iostream>

#include <cstdlib>

#include <cstring>

#include <cstdio>

#include <cmath>

#include <ctime>

using namespace std;

int main(int argc, char *argv[])

{

int t = 0;

int n;

int q;

int a;

int b;

int i;

int j;

int s[ 10005 ] = {};

cin >> n >> q;

for ( i = 0 ; i <= n ; i++ )

s[ i ] = 1;

for ( i = 0 ; i < q ; i++ )

{

cin >> a >> b;

for ( j = a ; j <= b ; j++ )

s[ j ] = 0;

}

for ( i = 0 ; i <= n ; i++ )

t += s[ i ];

cout << t << endl;

//system("PAUSE");

return EXIT_SUCCESS;

}

提交就是对的!!!(自己测也对~~~);

就模拟一下砍树不就行了吗~~~~

#1 Scare-soul@2015-06-14 15:35:56
回复 删除
好麻烦的样子= =
#2 sunnyboy@2020-10-19 18:08:33
回复 删除
#include<iostream>

using namespace std;

int a[10001];

int main()

{

int L,M,i,x,y,j,c=0;

cin>>L>>M;

for(i=0;i<=L;i++)

a[i]=1;

for(int q=1;q<=M;q++)

{

cin>>x>>y;

for(j=x;j<=y;j++)

a[j]=0;

}

for(i=0;i<=L;i++)

if(a[i]==1)

c++;

cout<<c;

}

查看更多回复
提交回复