C++RE求助……
  • 板块P1250 种树
  • 楼主LYB23390
  • 当前回复8
  • 已保存回复8
  • 发布时间2021/6/2 13:28
  • 上次更新2023/11/4 22:23:33
查看原帖
C++RE求助……
317146
LYB23390楼主2021/6/2 13:28
#include<bits/stdc++.h>
using namespace std;


int main(){
	int n,h; 
	cin>>n>>h;
	int b[h],e[h],t[h],tree[n]={0},ans=0;
	for(int i=0;i<h;i++)cin>>b[i]>>e[i]>>t[i];
	for(int i=0;i<h;i++)
		for(int j=0;i<h;j++)
			if(t[i]<t[j]){
				swap(b[i],b[j]);
				swap(e[i],e[j]);
				swap(t[i],t[j]);
			}
	for(int i=0;i<h;i++)
		for(int j=b[i]-1;j<e[i];j++)
			if(tree[j]==0){
				ans++;
				tree[i]=1;
			}
	cout<<ans;
	return 0;
}
#include<bits/stdc++.h>
using namespace std;


int main(){
	int n,h; 
	cin>>n>>h;
	int b[h],e[h],t[h],tree[n]={0},ans=0;
	for(int i=0;i<h;i++)cin>>b[i]>>e[i]>>t[i];
	for(int i=0;i<h;i++)
		for(int j=0;i<h;j++)
			if(t[i]<t[j]){
				swap(b[i],b[j]);
				swap(e[i],e[j]);
				swap(t[i],t[j]);
			}
	for(int i=0;i<h;i++)
		for(int j=b[i]-1;j<e[i];j++)
			if(tree[j]==0){
				ans++;
				tree[i]=1;
			}
	cout<<ans;
	return 0;
}
2021/6/2 13:28
加载中...