杭电OJ Moving Tables 解题报告

题目链接:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=1&sectionid=3&problemid=2


题目大意 & 题解:

        有一间如下图的宿舍,1,3,5,,399号在一边,2,4,6,,400号在相应对门位置。

         

         然后要你从一个寝室里把椅子搬到另一个寝室,而且无论从哪个寝室搬到哪个寝室都要花费10min。

         因为走廊很小,所以一段走廊只能有一个椅子通过。

         比如你要把一个椅子从5号搬到10号,另一个椅子从6号搬到8号,就要花费20min。

         但是如果你要把一个椅子从5号搬到10号,另一个椅子从20号搬到28号,只要花费10min就可以,因为这两段走廊没有重叠。

         坑点:例如 1  3          4  5 这样搬也是20min  ,因为由图可知,3号和4号共用一条走廊。

         然后我开始是模拟搬椅子的过程,用vector里的make_pair从头到尾遍历,去掉可以同时搬的次数,将剩下的*10输出,但是WA了。

         而且我现在还不知道为什么WA,我也会将这个程序传传上去,如果有人看出了哪里错了请告诉我_(:_」∠)_

         然后第二种方法就是用一个数组记录走廊被走过的次数,最后将最高的次数*10就好了,这个方法很简单,看代码就行了。



第一个模拟过程  WA了的代码

/*  wa 此题代码见Moving Tables 2*/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define INF 0x3FFFFFFF;
#define Rep(x,n) for(int x=0;x<n;++x)
#define Rep2(x,l,n) for(int x=l;x<n;++x)
typedef long long ll;
const int MAXN = 100010;
int flag[205];
int main()
{
    int t;
	cin>>t;
	
	while(t--)
	{
		int n;
		cin>>n;
		vector< pair<int,int> >v;
		Rep(i,n)flag[i]=1;
	//	Rep(i,n)cout<<flag[i];
	//	cout<<endl;
		Rep(i,n)
		{
		   int x,y;
		   cin>>x>>y;
		   if(x>y){
		   	int msn=x;
		   	x=y;
		   	y=msn;
		   }
		   v.push_back(make_pair(x,y));
		}
		int sum=0;
		Rep(i,n-1){
		//	cout<<v[i].first<<' '<<v[i].second<<endl;
			if(flag[i]==0)continue;
			Rep2(j,i+1,n)
			{   if(flag[j]==0)continue;
				if(v[j].second<v[i].first){
				if(v[i].first%2==0&&v[j].second+1==v[i].first);
				else flag[j]=0;
			    continue;
				//	cout<<flag[j]<<endl;					
				}
				if(v[j].first>v[i].second){
				if(v[i].second%2==1&&v[i].second+1==v[j].first);
				else flag[j]=0;
				continue;
				//	cout<<flag[j]<<endl;
					
				}	
			}
	    }
	   // Rep(i,n)cout<<flag[i];
	   //	cout<<endl;
		Rep(i,n){
			if(flag[i]==1)sum+=10;
		}
		cout<<sum<<endl;	
		}	
	return 0;
}

第二个 记录走廊被走过的次数 AC

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define INF 0x3FFFFFFF;
#define Rep(x,n) for(int x=0;x<n;++x)
#define Rep2(x,l,n) for(int x=l;x<n;++x)
typedef long long ll;
const int MAXN = 100010;
int flag[405]; 
int main()
{
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		for(int i=0;i<405;++i)flag[i]=0;
		Rep(i,n)
		{
			int x,y;
			cin>>x>>y;
			if(x>y){
				int m=x;
				x=y;
				y=m;
			}
			if(x%2==0)flag[x-1]++;
			if(y%2==1)flag[y+1]++;
			Rep2(j,x,y+1)flag[j]++;
		
		}
		int c=0;
		Rep(i,405){
		
			if(flag[i]>c)c=flag[i];
		}
	
		cout<<c*10<<endl;
	}
	return 0;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值