POJ 1083 贪心 及其证明

本文介绍了一种通过遍历所有给定点对之间的路径并找出经历次数最多节点的方法。该节点被视为最繁忙节点,因为它不能与其他节点同时经历。通过C++实现的算法详细展示了如何计算这些节点,并提供了一个具体的示例程序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <cstring>
#define INF 100000000
using namespace std;
struct node{
	int x,y;
	bool operator < (const node &a) const {
		return abs(y - x) < abs(a.x - a.y);
	}	
};
node a[205];

int d[1000];

int main(){
	int t;
	//freopen("in.txt","r",stdin);
	
	cin >> t;
	while(t--){
		int n;
		
		cin >>  n;	
		for(int i = 0;i < n;i++){
			int x,y;
			scanf("%d%d",&x,&y);
			
			a[i].x = (min(x,y)+1)/2;
			a[i].y = (max(x,y)+1)/2;
		}
		memset(d,0,sizeof(d));
		
		for(int i = 0;i < n;i++){
			for(int j = a[i].x;j <= a[i].y;j++){
				d[j]++;
			}
		}
		
		int ans = 0;
		for(int i = 0;i <= 200;i++){
			if(d[i] > ans){
				ans ++;
			}
		}
		
		cout << ans*10 << endl;
	}
	return 0;
}
证明:这个点是经过次数最多的点,因为这个点所在的每一次移动都不能同时进行所以他一定是最小的次数!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值