推桌子

推桌子

时间限制:1000 ms  |  内存限制:65535 KB

难度:3

描述
The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape
is in the following figure.

The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables are big, only
one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out the following plan: Moving a table from a room to another room can be done within 10 minutes. When moving a table from room i to room j, the
part of the corridor between the front of room i and the front of room j is used. So, during each 10 minutes, several moving between two rooms not sharing the same part of the corridor will be done simultaneously. To make it clear the manager illustrated the
possible cases and impossible cases of simultaneous moving.

For each room, at most one table will be either moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job is to write a program to solve the manager‘s problem.

输入
The input consists of T test cases. The number of test cases ) (T is given in the first line of the input file. Each test case begins with a line containing an integer N , 1 <= N <= 200,
that represents the number of tables to move.

Each of the following N lines contains two positive integers s and t, representing that a table is to move from room number s to room number t each room number appears at most once in the N lines). From the 3 + N -rd

line, the remaining test cases are listed in the same manner as above.

输出
The output should contain the minimum time in minutes to complete the moving, one per line.
样例输入
3
4
10 20
30 40
50 60
70 80
2
1 3
2 200
3
10 100
20 80
30 50
样例输出
10
20
30

思路:
   这题不是怎么难的题,就是细节比较多。
   (1)输入时左边数据可能大于右边
   (2)走廊的那幅图是有用的,规定偶数和奇数的特点。如:3-5与6-8是不能同时移动桌子的
我的代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct S
{
	int L;
	int R;
	int flag;
}a[210];
bool cmp(const S& p,const S&q)
{
	return p.R>q.R;
}
int main()
{
	int n,m,i,j,k,t;
	scanf("%d",&n);
	while (n--)
	{
		scanf("%d",&m);
		for (i=0;i<m;++i)
		{
			scanf("%d %d",&a[i].L,&a[i].R);
			if (a[i].L>a[i].R)
			{
				swap(a[i].L,a[i].R);
			}
			a[i].flag=1;
		}
		sort(a,a+m,cmp);
		for (i=0,t=0;i<m;++i)
		{
			k=a[i].L;
			if (a[i].flag)
			{
				t++;
				for (j=i+1;j<m;++j)
				{
					if (a[j].flag)
					{
						if (!(k&1)&&k-1>a[j].R)
						{
							a[j].flag=0;
							k=a[j].L;
						}
						else if((k&1)&&k>a[j].R)
						{
							a[j].flag=0;
							k=a[j].L;
						}
					}
				}
			}
		}
		cout << t*10 << endl;
	}
	return 0;
}

标程:


#include<cstring>
#include<cstdio>
#include<map>
#include<string>
#include<algorithm>
#include<vector>
#include<iostream>
using namespace std;
const int M=210;
#define CLR(arr,val) memset(arr,val,sizeof(arr))
int cnt[M];

int main()
{
	//freopen("in.txt","r",stdin);
	int t,n,a,b;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
	//	cerr<<n<<endl;
		CLR(cnt,0);
		for(int i=0;i!=n;i++)
		{
			scanf("%d%d",&a,&b);
			if(a>b) swap(a,b);
			for(int j=(a-1)/2;j<=(b-1)/2;j++)
				++cnt[j];
		}
		//copy(cnt,cnt+202,ostream_iterator<int>(cerr," "));
		printf("%d\n",*max_element(cnt,cnt+202)*10);

	}
}        
时间: 2024-10-08 17:03:25

推桌子的相关文章

nyoj 220——推桌子——————【贪心】

推桌子 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure. The floor has 200 rooms each on the north side and south side along the corridor. Rec

poj1083,nyoj220推桌子 贪心

#include <stdio.h><span style="font-family: Arial, Helvetica, sans-serif;">//注意两点,桌子可能从编号高的房间推到编号低的房间.如果2 3 ,4 5也是要分两次进行.因为3和4在同一走廊.</span> #include <string.h> #include <algorithm> using namespace std; struct node {

程序员到项目经理:从内而外的提升

转自:http://www.cnblogs.com/watsonyin/archive/2012/09/10/2679528.html 目录 从程序员到项目经理(一):为什么要当项目经理 从程序员到项目经理(二):升职之辨 从程序员到项目经理(三):认识项目经理 从程序员到项目经理(四):外行可以领导内行吗 从程序员到项目经理(五):程序员加油站,不是人人都懂的学习要点 从程序员到项目经理(六):程序员加油站 — 懂电脑更要懂人脑 从程序员到项目经理(七):程序员加油站 — 完美主义也是一种错

学习 探索

<整理的艺术2>实用技巧分享 别一次把资料全部整理完 这条对我无效,因为我有个非常好的习惯,在每天下班前10分钟,把当天的工作资料全部归纳.整理. 学会放松 书中有一条技巧是利用身边的度假村和温泉,那是日本的作法. 自己觉得累的时间,大都是脑力活动,这里比如的办法是多运动,比如慢跑.游泳之类,然后找个正规按摩店(在北方良子足道多一点)做脚道按摩或全身按摩,然后睡一觉,睡醒后经常满血复活. 每个人的选择不同,有人去爬山,有人去泡温泉.逛街,关键是要找到几种适合自己的放松方法,适当的放松,记住玩游

从程序员到项目经理(19):让员工为目标而干活

船在大海上航行,需要灯塔的指引.目标就是项目中灯塔.在项目中,目标不但可以指引方向,还可以凝聚人心. 1.把员工团结在目标下面 不善于给工作制定目标的管理者不是优秀的管理者,没有目标的团队也不能称之为团队.一个合适的目标,可以将员工紧紧的凝聚在一起,产生强大的力量.因此,项目经理必须要学会利用这一点,让员工为目标干活,将员工团结在目标下面. (1)目标是领导力的来源,也是团队的基本特征 无论是对个人,还是对组织,目标的重要性都不言而喻.为了“实现共产主义”这一伟大目标,无数革命先烈抛头颅.洒热血

HDOJ-1050-Moving Tables(nyoj220)

推桌子 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure. The floor has 200 rooms each on the north side and south side along the corridor. Rec

hdu 1207 汉诺塔II (DP+递推)

汉诺塔II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4529    Accepted Submission(s): 2231 Problem Description 经典的汉诺塔问题经常作为一个递归的经典例题存在.可能有人并不知道汉诺塔问题的典故.汉诺塔来源于印度传说的一个故事,上帝创造世界时作了三根金刚石柱子,在一根柱子上从下往

hdu 1267 递推

下沙的沙子有几粒? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4326    Accepted Submission(s): 2268 Problem Description 2005年11月份,我们学校参加了ACM/ICPC 亚洲赛区成都站的比赛,在这里,我们获得了历史性的突破,尽管只是一枚铜牌,但获奖那一刻的激动,也许将永远铭刻

git使用(1)----推送代码到远程

git使用(1) 首先要明白git上有三个区域 1.工作区 2.暂存区 3.历史记录区 步骤: 1.git  init 2.配置环境(如果配置一次了以后就不用再继续配置) git  config  --global  user.name  "username" git  config  --global  user.email  "email" 3.在本地版本库设置远程版本库的别名: git  remote  add  版本库别名  <库地址> 比如:g