杭电1025Constructing Roads In JGShining's Kingdom

Constructing Roads In JGShining's Kingdom
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines. 

Half of these cities are rich in resource (we call them rich cities) while the others are short of resource (we call them poor cities). Each poor city is short of exactly one kind of resource and also each rich city is rich in exactly one kind of resource. You may assume no two poor cities are short of one same kind of resource and no two rich cities are rich in one same kind of resource. 

With the development of industry, poor cities wanna import resource from rich ones. The roads existed are so small that they're unable to ensure the heavy trucks, so new roads should be built. The poor cities strongly BS each other, so are the rich ones. Poor cities don't wanna build a road with other poor ones, and rich ones also can't abide sharing an end of road with other rich ones. Because of economic benefit, any rich city will be willing to export resource to any poor one. 

Rich citis marked from 1 to n are located in Line I and poor ones marked from 1 to n are located in Line II. 

The location of Rich City 1 is on the left of all other cities, Rich City 2 is on the left of all other cities excluding Rich City 1, Rich City 3 is on the right of Rich City 1 and Rich City 2 but on the left of all other cities ... And so as the poor ones. 

But as you know, two crossed roads may cause a lot of traffic accident so JGShining has established a law to forbid constructing crossed roads. 

For example, the roads in Figure I are forbidden. 



In order to build as many roads as possible, the young and handsome king of the kingdom - JGShining needs your help, please help him. ^_^ 

Input

Each test case will begin with a line containing an integer n(1 ≤ n ≤ 500,000). Then n lines follow. Each line contains two integers p and r which represents that Poor City p needs to import resources from Rich City r. Process to the end of file. 

Output

For each test case, output the result in the form of sample. 
You should tell JGShining what's the maximal number of road(s) can be built. 

Sample Input

2
1 2
2 1
3
1 2
2 3
3 1

Sample Output

#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define MAX 500010
#define INF 0x3f3f3f3f
int a[MAX],g[MAX],dp[MAX];
int main()
{
	int n,p,r,i;
	int l=1;
	while(~scanf("%d",&n))
	{
		for(i=1;i<=n;i++)
		{
			scanf("%d%d",&p,&r);
			a[p]=r;
			g[i]=INF;
		}
		int ans=0;
		for(i=1;i<=n;i++)
		{
			int k=lower_bound(g+1,g+n+1,a[i])-g;
			dp[i]=k;
			g[k]=min(g[k],a[i]);
			ans=max(ans,dp[i]);
		}
		if(ans==1)
		printf("Case %d:\nMy king, at most %d road can be built.\n\n",l++,ans);
		else
	    	printf("Case %d:\nMy king, at most %d roads can be built.\n\n",l++,ans);
	}
	return 0;
}Case 1:
My king, at most 1 road can be built.

Case 2:
My king, at most 2 roads can be built.

引用\[1\]:出现如下报错信息: \[ INFO\] \[1564730909.628248268\]: Constructing new MoveGroup connection for group 'arm_group' in namespace '' \[ INFO\] \[1564730910.984667942\]: MoveItSimpleControllerManager: Waiting for redwall_arm/follow_joint_trajectory to come up \[ERROR\] \[1564730915.984849668\]: MoveItSimpleControllerManager: Action client not connected: redwall_arm/follow_joint_trajectory \[ INFO\] \[1564730916.087709422\]: Returned 0 controllers in list \[ INFO\] \[1564730916.107154984\]: Trajectory execution is managing controllers 。 引用\[2\]:发现竟然没有找到follow_joint_trajectory消息,难道move_group没有发布吗?纠结了一天,终于找到原因了,之前虚拟机械臂有gazebo的ros_control插件自动帮我们获取了follow_joint_trajectory的动作action信息,现在到真实机器人了,需要我们自己写程序了。问题找到了,最重要的是要理解一点,move_group此时是follow_joint_trajectory的client端,动作消息是client端的move_group发布的,听起来有点绕,但是千万不要把报错信息的action client not connect搞混淆了,我们现在client是存在且被感知的(就是move_group),而之所以报错是因为我缺少了action server端,我们需要添加一个server订阅这个action。 引用\[3\]:Animation Blueprints Exposed types on SkeletalControlBase to allow creation of derived classes.Added support for creating sub-classes of FAnimNode_StateMachine outside Engine module.Allowed UAnimNotify_PlayMontageNotify to be inherited by other modules.Bug Fix:Fixed sub-classes of FAnimNode_SkeletalControlBase not having deprecated CacheBones called。 问题:constructing new movegroup connection for group 'manipulator' in namespace 回答: 根据提供的引用内容,报错信息中显示正在构建一个新的MoveGroup连接,连接的组是'manipulator',命名空间为空。\[1\]这个报错信息表明正在尝试建立一个名为'manipulator'的组的MoveGroup连接。然而,报错信息中还显示了一个错误,即Action client 'redwall_arm/follow_joint_trajectory'未连接。\[2\]这可能是因为缺少一个action server端,需要添加一个server来订阅这个action。根据提供的信息,还无法确定是否已经在命名空间中找到了'manipulator'组的相关信息。 #### 引用[.reference_title] - *1* *2* [通过ROS控制真实机械臂(5)---Moveit!真实机械臂(move_group和demo.launch修改)](https://blog.csdn.net/qq_34935373/article/details/95916111)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Unreal Engine 4.20 Release Notes](https://blog.csdn.net/pizi0475/article/details/81636150)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值